This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[csl-sol210] Patch to stop collect2 unlinking directories


This patch for csl-sol210-3_4-branch changes collect2 so that when
unlinking files (in particular linker output after a linker error) it
only unlinks regular files or symbolic links.  (I made the logic
follow unlink_if_ordinary from libiberty, which isn't present on that
branch.)  The user bug report case was where the named output was a
directory, compiling as root and Solaris allowing root to unlink
nonempty directories.  Although this could be considered user error or
a OS defect rather than a GCC bug, I don't think it's actually ever
*useful* for GCC to try to unlink a directory in this case.

Bootstrapped with no regressions on i386-pc-solaris2.10.1.  Applied to
csl-sol210-3_4-branch.  Do people think a version using
unlink_if_ordinary would make sense for mainline?

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2005-06-01  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc/collect2.c (maybe_unlink): Only unlink regular files or
	symlinks.

--- collect2.c.orig	2005-01-10 15:25:23.000000000 +0000
+++ collect2.c	2005-06-01 02:15:41.000000000 +0000
@@ -1580,7 +1580,12 @@ static void
 maybe_unlink (const char *file)
 {
   if (!debug)
-    unlink (file);
+    {
+      struct stat st;
+      if (lstat (file, &st) == 0
+	  && (S_ISREG (st.st_mode) || S_ISLNK (st.st_mode)))
+	unlink (file);
+    }
   else
     notice ("[Leaving %s]\n", file);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]