m4-patches
[Top][All Lists]
Advanced

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

branch-1_4 files and subprocesses


From: Eric Blake
Subject: branch-1_4 files and subprocesses
Date: Fri, 18 Aug 2006 23:10:47 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

This cleans up syscmd and esyscmd so that an unrelated child process does not 
see any file descriptors that m4 is using for internal purposes only.

2006-08-18  Eric Blake  <address@hidden>

        Don't let unrelated child processes see too many files.
        * m4/gnulib-cache.m4: Augment with gnulib-tool --import cloexec.
        * src/builtin.c (m4_esyscmd, m4_regexp, m4_patsubst): Fix
        spelling in error message.
        * src/debug.c [!__STDC__]: Assume C89, and nuke old varargs.h.
        (debug_set_output): Close debug file on exec.
        * src/m4.h (includes): Add cloexec.h.
        * src/output.c (make_room_for): Close diversions on exec.
        * src/path.c (path_search): Close include files on exec.
        * NEWS: Document this.

Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.54
diff -u -b -r1.1.1.1.2.54 NEWS
--- NEWS        18 Aug 2006 16:28:22 -0000      1.1.1.1.2.54
+++ NEWS        18 Aug 2006 23:07:04 -0000
@@ -11,8 +11,10 @@
 * The format macro now understands %F, %g, and %G.
 * When loading frozen files, m4 now exits with status 63 if version
   mismatch is detected.
-* Fix bugs that occurred when invoked with stdout or stderr closed.
-  Detect write failures to stdout or to the target of the debugfile macro.
+* Fix bugs that occurred when invoked with stdout or stderr closed,
+  and detect write failures to stdout or to the target of the
+  debugfile macro.  In particular, the syscmd and esyscmd macros can
+  no longer interfere with the debug stream or diversions.
 * The m4exit macro now converts values outside the range 0-255 to 1.
 * It is now an error if a command-line input file ends in the middle of a
   comment, matching the behavior of mid-string and mid-argument
Index: m4/gnulib-cache.m4
===================================================================
RCS file: /sources/m4/m4/m4/Attic/gnulib-cache.m4,v
retrieving revision 1.1.2.11
diff -u -b -r1.1.2.11 gnulib-cache.m4
--- m4/gnulib-cache.m4  8 Aug 2006 16:23:58 -0000       1.1.2.11
+++ m4/gnulib-cache.m4  18 Aug 2006 23:07:04 -0000
@@ -15,10 +15,10 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 --
doc-base=doc --aux-dir=. --no-libtool --macro-prefix=M4 alloca binary-io close-
stream error fdl fopen-safer free gendocs getopt mkstemp obstack regex stdlib-
safer strtol tmpfile-safer unlocked-io verror xalloc xvasprintf
+#   gnulib-tool --import --dir=. --lib=libm4 --source-base=lib --m4-base=m4 --
doc-base=doc --aux-dir=. --no-libtool --macro-prefix=M4 alloca binary-io 
cloexec close-stream error fdl fopen-safer free gendocs getopt mkstemp obstack 
regex stdlib-safer strtol tmpfile-safer unlocked-io verror xalloc xvasprintf
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
-gl_MODULES([alloca binary-io close-stream error fdl fopen-safer free gendocs 
getopt mkstemp obstack regex stdlib-safer strtol tmpfile-safer unlocked-io 
verror xalloc xvasprintf])
+gl_MODULES([alloca binary-io cloexec close-stream error fdl fopen-safer free 
gendocs getopt mkstemp obstack regex stdlib-safer strtol tmpfile-safer unlocked-
io verror xalloc xvasprintf])
 gl_AVOID([])
 gl_SOURCE_BASE([lib])
 gl_M4_BASE([m4])
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.35
diff -u -b -r1.1.1.1.2.35 builtin.c
--- src/builtin.c       18 Aug 2006 16:28:22 -0000      1.1.1.1.2.35
+++ src/builtin.c       18 Aug 2006 23:07:04 -0000
@@ -871,7 +871,7 @@
   if (pin == NULL)
     {
       M4ERROR ((warning_status, errno,
-               "cannot open pipe to command \"%s\"", ARG (1)));
+               "cannot open pipe to command `%s'", ARG (1)));
       sysval = -1;
     }
   else
@@ -1773,7 +1773,7 @@
 
   if (startpos == -2)
     M4ERROR ((warning_status, 0,
-              "error matching regular expression \"%s\"", regexp));
+              "error matching regular expression `%s'", regexp));
   else if (argc == 3)
     shipout_int (obs, startpos);
   else if (startpos >= 0)
@@ -1839,7 +1839,7 @@
 
          if (matchpos == -2)
            M4ERROR ((warning_status, 0,
-                     "error matching regular expression \"%s\"", regexp));
+                     "error matching regular expression `%s'", regexp));
          else if (offset < length)
            obstack_grow (obs, victim + offset, length - offset);
          break;
Index: src/debug.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/debug.c,v
retrieving revision 1.1.1.1.2.7
diff -u -b -r1.1.1.1.2.7 debug.c
--- src/debug.c 8 Aug 2006 23:17:44 -0000       1.1.1.1.2.7
+++ src/debug.c 18 Aug 2006 23:07:04 -0000
@@ -21,13 +21,8 @@
 
 #include "m4.h"
 
-#include <sys/stat.h>
-
-#ifdef __STDC__
 #include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+#include <sys/stat.h>
 
 /* File for debugging output.  */
 FILE *debug = NULL;
@@ -203,6 +198,9 @@
       if (fp == NULL)
        return FALSE;
 
+      if (set_cloexec_flag (fileno (fp), true) != 0)
+       M4ERROR ((warning_status, errno,
+                 "Warning: cannot protect debug file across forks"));
       debug_set_file (fp);
     }
   return TRUE;
@@ -237,17 +235,9 @@
 | left quote) and %r (optional right quote).                          |
 `---------------------------------------------------------------------*/
 
-#ifdef __STDC__
 static void
 trace_format (const char *fmt, ...)
-#else
-static void
-trace_format (...)
-#endif
 {
-#ifndef __STDC__
-  const char *fmt;
-#endif
   va_list args;
   char ch;
 
@@ -257,12 +247,7 @@
   int slen;
   int maxlen;
 
-#ifdef __STDC__
   va_start (args, fmt);
-#else
-  va_start (args);
-  fmt = va_arg (args, const char *);
-#endif
 
   while (TRUE)
     {
Index: src/m4.h
===================================================================
RCS file: /sources/m4/m4/src/m4.h,v
retrieving revision 1.1.1.1.2.27
diff -u -b -r1.1.1.1.2.27 m4.h
--- src/m4.h    8 Aug 2006 23:17:44 -0000       1.1.1.1.2.27
+++ src/m4.h    18 Aug 2006 23:07:04 -0000
@@ -49,6 +49,7 @@
 #include <sys/types.h>
 
 #include "binary-io.h"
+#include "cloexec.h"
 #include "close-stream.h"
 #include "error.h"
 #include "exit.h"
Index: src/output.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/output.c,v
retrieving revision 1.1.1.1.2.9
diff -u -b -r1.1.1.1.2.9 output.c
--- src/output.c        8 Aug 2006 23:17:44 -0000       1.1.1.1.2.9
+++ src/output.c        18 Aug 2006 23:07:04 -0000
@@ -158,6 +158,9 @@
       if (selected_diversion->file == NULL)
        M4ERROR ((EXIT_FAILURE, errno,
                  "ERROR: cannot create temporary file for diversion"));
+      if (set_cloexec_flag (fileno (selected_diversion->file), true) != 0)
+       M4ERROR ((warning_status, errno,
+                 "Warning: cannot protect diversion across forks"));
 
       if (selected_diversion->used > 0)
        {
Index: src/path.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/path.c,v
retrieving revision 1.1.1.1.2.8
diff -u -b -r1.1.1.1.2.8 path.c
--- src/path.c  31 Jul 2006 03:48:06 -0000      1.1.1.1.2.8
+++ src/path.c  18 Aug 2006 23:07:04 -0000
@@ -127,6 +127,9 @@
   fp = fopen (file, "r");
   if (fp != NULL)
     {
+      if (set_cloexec_flag (fileno (fp), true) != 0)
+       M4ERROR ((warning_status, errno,
+                 "Warning: cannot protect input file across forks"));
       if (result)
        *result = xstrdup (file);
       return fp;
@@ -154,6 +157,9 @@
        {
          if (debug_level & DEBUG_TRACE_PATH)
            DEBUG_MESSAGE2 ("path search for `%s' found `%s'", file, name);
+         if (set_cloexec_flag (fileno (fp), true) != 0)
+           M4ERROR ((warning_status, errno,
+                     "Warning: cannot protect input file across forks"));
          if (result)
            *result = name;
          else






reply via email to

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