diff mbox

PR/57652 collect2 temp files

Message ID CAGWvnyk3CpQ9G+huqdw0R37=47c4ABD4Tz2+kexPhfmuhvx9Tg@mail.gmail.com
State New
Headers show

Commit Message

David Edelsohn June 19, 2013, 2:49 p.m. UTC
A 2011 change to collect2 to use the standard diagnostics
infrastructure broke collect2's cleanup of temp files when an error
occurs.  This prototype of a patch implements the minimal conversion
of collect2 to use atexit().

If this is the right direction, all calls to collect_exit() can be
converted to exit().

Thanks, David

        PR driver/57652
        * collect2.c (collect_atexit): New.
        (collect_exit): Directly call exit.
        (main): Register collect_atexit with atexit.

Comments

Joseph Myers June 19, 2013, 4:38 p.m. UTC | #1
On Wed, 19 Jun 2013, David Edelsohn wrote:

> A 2011 change to collect2 to use the standard diagnostics
> infrastructure broke collect2's cleanup of temp files when an error
> occurs.  This prototype of a patch implements the minimal conversion
> of collect2 to use atexit().
> 
> If this is the right direction, all calls to collect_exit() can be
> converted to exit().
> 
> Thanks, David
> 
>         PR driver/57652
>         * collect2.c (collect_atexit): New.
>         (collect_exit): Directly call exit.
>         (main): Register collect_atexit with atexit.

This is OK.  Using atexit seems to me to be the right approach for such 
cleanup.
diff mbox

Patch

Index: collect2.c
===================================================================
--- collect2.c  (revision 200180)
+++ collect2.c  (working copy)
@@ -367,7 +367,7 @@ 
 /* Delete tempfiles and exit function.  */

 void
-collect_exit (int status)
+collect_atexit (void)
 {
   if (c_file != 0 && c_file[0])
     maybe_unlink (c_file);
@@ -395,12 +395,16 @@ 
       maybe_unlink (lderrout);
     }

-  if (status != 0 && output_file != 0 && output_file[0])
+  if (output_file != 0 && output_file[0])
     maybe_unlink (output_file);

   if (response_file)
     maybe_unlink (response_file);
+}

+void
+collect_exit (int status)
+{
   exit (status);
 }

@@ -970,6 +974,9 @@ 
   signal (SIGCHLD, SIG_DFL);
 #endif

+  if (atexit (collect_atexit) != 0)
+    fatal_error ("atexit failed");
+
   /* Unlock the stdio streams.  */
   unlock_std_streams ();