This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] gcc cannot deal with full /tmp
- From: Denys Vlasenko <dvlasenk at redhat dot com>
- To: dj at redhat dot com, ian at airs dot com
- Cc: gcc-patches at gcc dot gnu dot org, binutils at sources dot redhat dot com
- Date: Mon, 28 Jul 2008 19:10:59 +0200
- Subject: [PATCH] gcc cannot deal with full /tmp
Hi,
This is a trivial fix for
https://bugzilla.redhat.com/show_bug.cgi?id=203231
This bug is actually in libiberty, thus I post the patch to both gcc and
binutils list.
Bug description:
mkstemps() loops TMP_MAX times even if open error is fatal. This creates
an impression that gcc hung (TMP_MAX is ~200000). Moreover, when it does
finish looping and returns to make_temp_file(), make_temp_file()
just abort()s without good error message.
The patch deals with both problems.
Sample output:
Cannot create temporary file in /root/srcdevel/gcc/testdir/: Permission denied
./z.sh: line 13: 6115 Aborted TMP=$PWD/testdir i486-linux-uclibc-gcc -o t t.c
Please ACK or comment. Thanks.
--
vda
diff -d -urpN gcc.0/libiberty/make-temp-file.c gcc.1/libiberty/make-temp-file.c
--- gcc.0/libiberty/make-temp-file.c 2008-07-21 14:50:00.000000000 +0200
+++ gcc.1/libiberty/make-temp-file.c 2008-07-21 16:28:06.000000000 +0200
@@ -23,6 +23,7 @@ Boston, MA 02110-1301, USA. */
#include <stdio.h> /* May get P_tmpdir. */
#include <sys/types.h>
+#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -166,12 +167,13 @@ make_temp_file (const char *suffix)
strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix);
fd = mkstemps (temp_filename, suffix_len);
- /* If mkstemps failed, then something bad is happening. Maybe we should
- issue a message about a possible security attack in progress? */
+ /* mkstemps failed. It may be EPERM, ENOSPC etc. */
if (fd == -1)
- abort ();
- /* Similarly if we can not close the file. */
+ {
+ fprintf(stderr, "Cannot create temporary file in %s: %s\n", base, strerror(errno));
+ abort ();
+ }
if (close (fd))
- abort ();
+ abort (); /* sheer paranoia */
return temp_filename;
}
diff -d -urpN gcc.0/libiberty/mkstemps.c gcc.1/libiberty/mkstemps.c
--- gcc.0/libiberty/mkstemps.c 2008-07-21 14:50:00.000000000 +0200
+++ gcc.1/libiberty/mkstemps.c 2008-07-28 18:48:34.000000000 +0200
@@ -127,6 +127,9 @@ mkstemps (char *pattern, int suffix_len)
if (fd >= 0)
/* The file does not exist. */
return fd;
+ if (errno != EEXIST)
+ /* Fatal error (EPERM, ENOSPC etc). Doesn't make sense to loop. */
+ break;
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different