From d629f6d28665184cf8970b691e48ea2dfccfa25f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 26 Jan 2009 00:12:36 +0100 Subject: [PATCH] Use the posix_spawn or its replacement on all Unix platforms. --- ChangeLog | 19 +++++++++++++++ lib/execute.c | 55 +------------------------------------------- lib/pipe.c | 71 +-------------------------------------------------------- m4/execute.m4 | 13 +---------- m4/pipe.m4 | 14 +----------- modules/execute | 10 +++++++- modules/pipe | 12 +++++++++- 7 files changed, 43 insertions(+), 151 deletions(-) diff --git a/ChangeLog b/ChangeLog index 398b1a940..f74e89882 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2009-01-25 Bruno Haible + * 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 + * lib/glthread/threadlib.c: Include . 2009-01-25 Bruno Haible diff --git a/lib/execute.c b/lib/execute.c index 71da46fb7..c9f25b52d 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -44,13 +44,7 @@ #else /* Unix API. */ -# if HAVE_POSIX_SPAWN -# include -# else -# if HAVE_VFORK_H -# include -# endif -# endif +# include #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); diff --git a/lib/pipe.c b/lib/pipe.c index d842c77f9..d44f62e5f 100644 --- a/lib/pipe.c +++ b/lib/pipe.c @@ -44,13 +44,7 @@ #else /* Unix API. */ -# if HAVE_POSIX_SPAWN -# include -# else -# if HAVE_VFORK_H -# include -# endif -# endif +# include #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); diff --git a/m4/execute.m4 b/m4/execute.m4 index bec89461d..b89d43a1e 100644 --- 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 @@ 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 - ]) ]) diff --git a/m4/pipe.m4 b/m4/pipe.m4 index 83f286809..fe7876ff0 100644 --- 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 @@ 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 - ]) ]) diff --git a/modules/execute b/modules/execute index ecea7980e..6dddd3883 100644 --- a/modules/execute +++ b/modules/execute @@ -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 diff --git a/modules/pipe b/modules/pipe index 42e3b837a..08c2f94a9 100644 --- a/modules/pipe +++ b/modules/pipe @@ -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 -- 2.11.0