+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>.
#else
/* Unix API. */
-# if HAVE_POSIX_SPAWN
-# include <spawn.h>
-# else
-# if HAVE_VFORK_H
-# include <vfork.h>
-# endif
-# endif
+# include <spawn.h>
#endif
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;
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);
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);
#else
/* Unix API. */
-# if HAVE_POSIX_SPAWN
-# include <spawn.h>
-# else
-# if HAVE_VFORK_H
-# include <vfork.h>
-# endif
-# endif
+# include <spawn.h>
#endif
/* 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;
bool attrs_allocated;
int err;
pid_t child;
-# else
- int child;
-# endif
if (pipe_stdout)
if (pipe (ifd) < 0
*
*/
-# if HAVE_POSIX_SPAWN
if (slave_process)
{
sigprocmask (SIG_SETMASK, NULL, &blocked_signals);
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);
-# 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,
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
- ])
])
-# 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,
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
- ])
])
lib/execute.c
lib/w32spawn.h
m4/execute.m4
-m4/posix_spawn.m4
Depends-on:
error
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
lib/pipe.c
lib/w32spawn.h
m4/pipe.m4
-m4/posix_spawn.m4
Depends-on:
environ
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