bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make run in parallel mode with output redirected to a regular file c


From: Frank Heckenbach
Subject: Re: Make run in parallel mode with output redirected to a regular file can randomly drop output lines
Date: Fri, 31 May 2013 05:37:45 +0200

Martin Dorey wrote:

> > That said, I'm now going back to my own programs which redirect
> > stdout in forked child processes and add O_APPEND to O_TRUNC ...
> 
> Me too!

I just realized that this also applies to the temp files created for
output-sync, since tmpfile() doesn't set O_APPEND. The problem
doesn't exist WRT parallel make jobs, since they get different temp
files, but with jobs that fork themselves, like:

foo:
        echo foo & echo bar; wait

It might be hard to reproduce the problem with such a simple test
case, but since we just basically determined that it should be the
job of the caller to insure stdout is "forkable", this burden falls
on make in this case. Also it's another case that output-sync would
noticeable change the visible behaviour. So I suggest this change:

--- misc.c.orig 2013-05-31 05:06:33.000000000 +0200
+++ misc.c      2013-05-31 05:21:34.000000000 +0200
@@ -18,6 +18,12 @@
 #include "dep.h"
 #include "debug.h"
 
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#else
+# include <sys/file.h>
+#endif
+
 /* GNU make no longer supports pre-ANSI89 environments.  */
 
 #include <stdarg.h>
@@ -961,7 +967,7 @@
 int
 open_tmpfd ()
 {
-  int fd = -1;
+  int fd = -1, flags;
   FILE *tfile = tmpfile ();
 
   if (! tfile)
@@ -974,6 +980,12 @@
 
   fclose (tfile);
 
+  flags = fcntl (fd, F_GETFL, 0);
+  if (flags < 0)
+    pfatal_with_name ("fcntl (F_GETFL)");
+  if (fcntl (fd, F_SETFL, flags | O_APPEND) < 0)
+    pfatal_with_name ("fcntl (F_SETFL)");
+
   return fd;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]