Safety cleanups: ensure OUTFD is -1 when closed.
authorPaul Smith <psmith@gnu.org>
Sun, 21 Jul 2013 20:55:40 +0000 (16:55 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 21 Jul 2013 20:56:00 +0000 (16:56 -0400)
ChangeLog
job.c

index 78690ea0d884847a4f891c273f95941d1498ae38..8454b08cf1919839b9225030897d003095bc2734 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-21  Paul Smith  <psmith@gnu.org>
+
+       * job.c (assign_child_tempfiles): Assign OUTFD to -1 for safety.
+       (start_job_command): Don't test output_sync and sync_cmd: redundant.
+       Changes suggested by Frank Heckenbach <f.heckenbach@fh-soft.de>.
+
 2013-07-14  Paul Smith  <psmith@gnu.org>
 
        * filedef.h (update_status): Convert UPDATE_STATUS from a char to
diff --git a/job.c b/job.c
index 68f1f26fcd00a7910e319650a52c8801940df6d4..01989055989abec14b411a3c2d69d46fb1315476 100644 (file)
--- a/job.c
+++ b/job.c
@@ -687,7 +687,10 @@ assign_child_tempfiles (struct child *c)
 
  error:
   if (c->outfd >= 0)
-    close (c->outfd);
+    {
+      close (c->outfd);
+      c->outfd = -1;
+    }
   output_sync = 0;
 }
 
@@ -700,8 +703,8 @@ pump_from_tmp (int from, FILE *to)
 #ifdef WINDOWS32
   int prev_mode;
 
-  /* from_fd is opened by open_tmpfd, which does it in binary mode, so
-     we need the mode of to_fd to match that.  */
+  /* "from" is opened by open_tmpfd, which does it in binary mode, so
+     we need the mode of "to" to match that.  */
   prev_mode = _setmode (fileno (to), _O_BINARY);
 #endif
 
@@ -721,7 +724,7 @@ pump_from_tmp (int from, FILE *to)
     }
 
 #ifdef WINDOWS32
-  /* Switch to_fd back to its original mode, so that log messages by
+  /* Switch "to" back to its original mode, so that log messages by
      Make have the same EOL format as without --output-sync.  */
   _setmode (fileno (to), prev_mode);
 #endif
@@ -1753,7 +1756,7 @@ start_job_command (struct child *child)
 #ifdef OUTPUT_SYNC
           /* Divert child output if output_sync in use.  Don't capture
              recursive make output unless we are synchronizing "make" mode.  */
-          if (output_sync && sync_cmd)
+          if (sync_cmd)
             {
               int outfd = fileno (stdout);
               int errfd = fileno (stderr);
@@ -1866,7 +1869,7 @@ start_job_command (struct child *child)
 #ifdef OUTPUT_SYNC
           /* Divert child output if output_sync in use.  Don't capture
              recursive make output unless we are synchronizing "make" mode.  */
-          if (output_sync && sync_cmd)
+          if (sync_cmd)
             hPID = process_easy (argv, child->environment,
                                  child->outfd, child->errfd);
           else