changeset 11090:414a549bcd8b

Use the posix_spawn or its replacement on all Unix platforms.
author Bruno Haible <bruno@clisp.org>
date Mon, 26 Jan 2009 00:12:36 +0100
parents 43ca345955b3
children 77b88b566cf1
files ChangeLog lib/execute.c lib/pipe.c m4/execute.m4 m4/pipe.m4 modules/execute modules/pipe
diffstat 7 files changed, 43 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+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>.
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -44,13 +44,7 @@
 #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 @@
      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 @@
   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 @@
   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);
--- a/lib/pipe.c
+++ b/lib/pipe.c
@@ -44,13 +44,7 @@
 #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 @@
   /* 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 @@
   bool attrs_allocated;
   int err;
   pid_t child;
-# else
-  int child;
-# endif
 
   if (pipe_stdout)
     if (pipe (ifd) < 0
@@ -282,7 +272,6 @@
  *
  */
 
-# if HAVE_POSIX_SPAWN
   if (slave_process)
     {
       sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
@@ -370,64 +359,6 @@
   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);
--- a/m4/execute.m4
+++ b/m4/execute.m4
@@ -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 @@
   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
-    ])
 ])
--- a/m4/pipe.m4
+++ b/m4/pipe.m4
@@ -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 @@
 
 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
-    ])
 ])
--- a/modules/execute
+++ b/modules/execute
@@ -6,7 +6,6 @@
 lib/execute.c
 lib/w32spawn.h
 m4/execute.m4
-m4/posix_spawn.m4
 
 Depends-on:
 error
@@ -14,6 +13,15 @@
 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
--- a/modules/pipe
+++ b/modules/pipe
@@ -6,7 +6,6 @@
 lib/pipe.c
 lib/w32spawn.h
 m4/pipe.m4
-m4/posix_spawn.m4
 
 Depends-on:
 environ
@@ -15,6 +14,17 @@
 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