Use the posix_spawn or its replacement on all Unix platforms.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Jan 2009 23:12:36 +0000 (00:12 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Jan 2009 23:12:36 +0000 (00:12 +0100)
ChangeLog
lib/execute.c
lib/pipe.c
m4/execute.m4
m4/pipe.m4
modules/execute
modules/pipe

index 398b1a9..f74e898 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2009-01-25  Bruno Haible  <bruno@clisp.org>
 
+       * lib/pipe.c: On Unix, assume HAVE_POSIX_SPAWN and use posix_spawnp.
+       * m4/pipe.m4 (gl_PIPE): Remove tests for vfork() based code.
+       * modules/pipe (Files): Remove m4/posix_spawn.m4.
+       (Depends-on): Add spawn, posix_spawnp, posix_spawn_file_actions_init,
+       posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2,
+       posix_spawn_file_actions_addopen, posix_spawn_file_actions_destroy,
+       posix_spawnattr_init, posix_spawnattr_setsigmask,
+       posix_spawnattr_setflags, posix_spawnattr_destroy.
+
+       * lib/execute.c: On Unix, assume HAVE_POSIX_SPAWN and use posix_spawnp.
+       * m4/execute.m4 (gl_EXECUTE): Remove tests for vfork() based code.
+       * modules/execute (Files): Remove m4/posix_spawn.m4.
+       (Depends-on): Add spawn, posix_spawnp, posix_spawn_file_actions_init,
+       posix_spawn_file_actions_addopen, posix_spawn_file_actions_destroy,
+       posix_spawnattr_init, posix_spawnattr_setsigmask,
+       posix_spawnattr_setflags, posix_spawnattr_destroy.
+
+2009-01-25  Bruno Haible  <bruno@clisp.org>
+
        * lib/glthread/threadlib.c: Include <stdlib.h>.
 
 2009-01-25  Bruno Haible  <bruno@clisp.org>
index 71da46f..c9f25b5 100644 (file)
 #else
 
 /* Unix API.  */
-# if HAVE_POSIX_SPAWN
-#  include <spawn.h>
-# else
-#  if HAVE_VFORK_H
-#   include <vfork.h>
-#  endif
-# endif
+# include <spawn.h>
 
 #endif
 
@@ -204,7 +198,6 @@ execute (const char *progname,
      subprocess to exit with return code 127.  It is implementation
      dependent which error is reported which way.  We treat both cases as
      equivalent.  */
-#if HAVE_POSIX_SPAWN
   sigset_t blocked_signals;
   posix_spawn_file_actions_t actions;
   bool actions_allocated;
@@ -212,11 +205,7 @@ execute (const char *progname,
   bool attrs_allocated;
   int err;
   pid_t child;
-#else
-  int child;
-#endif
 
-#if HAVE_POSIX_SPAWN
   if (slave_process)
     {
       sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
@@ -274,48 +263,6 @@ execute (const char *progname,
   posix_spawn_file_actions_destroy (&actions);
   if (attrs_allocated)
     posix_spawnattr_destroy (&attrs);
-#else
-  if (slave_process)
-    block_fatal_signals ();
-  /* Use vfork() instead of fork() for efficiency.  */
-  if ((child = vfork ()) == 0)
-    {
-      /* Child process code.  */
-      int nullinfd;
-      int nulloutfd;
-
-      if ((!null_stdin
-          || ((nullinfd = open ("/dev/null", O_RDONLY, 0)) >= 0
-              && (nullinfd == STDIN_FILENO
-                  || (dup2 (nullinfd, STDIN_FILENO) >= 0
-                      && close (nullinfd) >= 0))))
-         && (!(null_stdout || null_stderr)
-             || ((nulloutfd = open ("/dev/null", O_RDWR, 0)) >= 0
-                 && (!null_stdout
-                     || nulloutfd == STDOUT_FILENO
-                     || dup2 (nulloutfd, STDOUT_FILENO) >= 0)
-                 && (!null_stderr
-                     || nulloutfd == STDERR_FILENO
-                     || dup2 (nulloutfd, STDERR_FILENO) >= 0)
-                 && ((null_stdout && nulloutfd == STDOUT_FILENO)
-                     || (null_stderr && nulloutfd == STDERR_FILENO)
-                     || close (nulloutfd) >= 0)))
-         && (!slave_process || (unblock_fatal_signals (), true)))
-       execvp (prog_path, prog_argv);
-      _exit (127);
-    }
-  if (child == -1)
-    {
-      if (slave_process)
-       unblock_fatal_signals ();
-      if (termsigp != NULL)
-       *termsigp = 0;
-      if (exit_on_error || !null_stderr)
-       error (exit_on_error ? EXIT_FAILURE : 0, errno,
-              _("%s subprocess failed"), progname);
-      return 127;
-    }
-#endif
   if (slave_process)
     {
       register_slave_subprocess (child);
index d842c77..d44f62e 100644 (file)
 #else
 
 /* Unix API.  */
-# if HAVE_POSIX_SPAWN
-#  include <spawn.h>
-# else
-#  if HAVE_VFORK_H
-#   include <vfork.h>
-#  endif
-# endif
+# include <spawn.h>
 
 #endif
 
@@ -253,7 +247,6 @@ create_pipe (const char *progname,
   /* Unix API.  */
   int ifd[2];
   int ofd[2];
-# if HAVE_POSIX_SPAWN
   sigset_t blocked_signals;
   posix_spawn_file_actions_t actions;
   bool actions_allocated;
@@ -261,9 +254,6 @@ create_pipe (const char *progname,
   bool attrs_allocated;
   int err;
   pid_t child;
-# else
-  int child;
-# endif
 
   if (pipe_stdout)
     if (pipe (ifd) < 0
@@ -282,7 +272,6 @@ create_pipe (const char *progname,
  *
  */
 
-# if HAVE_POSIX_SPAWN
   if (slave_process)
     {
       sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
@@ -370,64 +359,6 @@ create_pipe (const char *progname,
   posix_spawn_file_actions_destroy (&actions);
   if (attrs_allocated)
     posix_spawnattr_destroy (&attrs);
-# else
-  if (slave_process)
-    block_fatal_signals ();
-  /* Use vfork() instead of fork() for efficiency.  */
-  if ((child = vfork ()) == 0)
-    {
-      /* Child process code.  */
-      int nulloutfd;
-      int stdinfd;
-      int stdoutfd;
-
-      if ((!pipe_stdin || dup2 (ofd[0], STDIN_FILENO) >= 0)
-         && (!pipe_stdout || dup2 (ifd[1], STDOUT_FILENO) >= 0)
-         && (!pipe_stdin || close (ofd[0]) >= 0)
-         && (!pipe_stdout || close (ifd[1]) >= 0)
-         && (!pipe_stdin || close (ofd[1]) >= 0)
-         && (!pipe_stdout || close (ifd[0]) >= 0)
-         && (!null_stderr
-             || ((nulloutfd = open ("/dev/null", O_RDWR, 0)) >= 0
-                 && (nulloutfd == STDERR_FILENO
-                     || (dup2 (nulloutfd, STDERR_FILENO) >= 0
-                         && close (nulloutfd) >= 0))))
-         && (pipe_stdin
-             || prog_stdin == NULL
-             || ((stdinfd = open (prog_stdin, O_RDONLY, 0)) >= 0
-                 && (stdinfd == STDIN_FILENO
-                     || (dup2 (stdinfd, STDIN_FILENO) >= 0
-                         && close (stdinfd) >= 0))))
-         && (pipe_stdout
-             || prog_stdout == NULL
-             || ((stdoutfd = open (prog_stdout, O_WRONLY, 0)) >= 0
-                 && (stdoutfd == STDOUT_FILENO
-                     || (dup2 (stdoutfd, STDOUT_FILENO) >= 0
-                         && close (stdoutfd) >= 0))))
-         && (!slave_process || (unblock_fatal_signals (), true)))
-       execvp (prog_path, prog_argv);
-      _exit (127);
-    }
-  if (child == -1)
-    {
-      if (slave_process)
-       unblock_fatal_signals ();
-      if (exit_on_error || !null_stderr)
-       error (exit_on_error ? EXIT_FAILURE : 0, errno,
-              _("%s subprocess failed"), progname);
-      if (pipe_stdout)
-       {
-         close (ifd[0]);
-         close (ifd[1]);
-       }
-      if (pipe_stdin)
-       {
-         close (ofd[0]);
-         close (ofd[1]);
-       }
-      return -1;
-    }
-# endif
   if (slave_process)
     {
       register_slave_subprocess (child);
index bec8946..b89d43a 100644 (file)
@@ -1,4 +1,4 @@
-# execute.m4 serial 3
+# execute.m4 serial 4
 dnl Copyright (C) 2003, 2008, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,15 +9,4 @@ AC_DEFUN([gl_EXECUTE],
   dnl Prerequisites of lib/execute.c.
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_TYPE_MODE_T])
-  AC_CHECK_HEADERS_ONCE([unistd.h])
-  AC_REQUIRE([AC_FUNC_FORK])
-  AC_CHECK_FUNC([posix_spawn],
-    [gl_POSIX_SPAWN_WORKS
-     case "$gl_cv_func_posix_spawn_works" in
-       *yes)
-         AC_DEFINE([HAVE_POSIX_SPAWN], [1],
-           [Define if you have the posix_spawn() function and it works.])
-         ;;
-     esac
-    ])
 ])
index 83f2868..fe7876f 100644 (file)
@@ -1,4 +1,4 @@
-# pipe.m4 serial 3
+# pipe.m4 serial 4
 dnl Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -6,19 +6,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_PIPE],
 [
-  dnl Prerequisites of lib/pipe.h.
-  AC_CHECK_HEADERS_ONCE([unistd.h])
   dnl Prerequisites of lib/pipe.c.
   AC_REQUIRE([AC_C_INLINE])
   AC_REQUIRE([AC_TYPE_MODE_T])
-  AC_REQUIRE([AC_FUNC_FORK])
-  AC_CHECK_FUNC([posix_spawn],
-    [gl_POSIX_SPAWN_WORKS
-     case "$gl_cv_func_posix_spawn_works" in
-       *yes)
-         AC_DEFINE([HAVE_POSIX_SPAWN], [1],
-           [Define if you have the posix_spawn() function and it works.])
-         ;;
-     esac
-    ])
 ])
index ecea798..6dddd38 100644 (file)
@@ -6,7 +6,6 @@ lib/execute.h
 lib/execute.c
 lib/w32spawn.h
 m4/execute.m4
-m4/posix_spawn.m4
 
 Depends-on:
 error
@@ -14,6 +13,15 @@ exit
 fatal-signal
 wait-process
 gettext-h
+spawn
+posix_spawnp
+posix_spawn_file_actions_init
+posix_spawn_file_actions_addopen
+posix_spawn_file_actions_destroy
+posix_spawnattr_init
+posix_spawnattr_setsigmask
+posix_spawnattr_setflags
+posix_spawnattr_destroy
 stdbool
 strpbrk
 unistd
index 42e3b83..08c2f94 100644 (file)
@@ -6,7 +6,6 @@ lib/pipe.h
 lib/pipe.c
 lib/w32spawn.h
 m4/pipe.m4
-m4/posix_spawn.m4
 
 Depends-on:
 environ
@@ -15,6 +14,17 @@ exit
 fatal-signal
 gettext-h
 open
+spawn
+posix_spawnp
+posix_spawn_file_actions_init
+posix_spawn_file_actions_addclose
+posix_spawn_file_actions_adddup2
+posix_spawn_file_actions_addopen
+posix_spawn_file_actions_destroy
+posix_spawnattr_init
+posix_spawnattr_setsigmask
+posix_spawnattr_setflags
+posix_spawnattr_destroy
 stdbool
 strpbrk
 unistd