X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fpipe.c;h=f8e7dee104e9897be8bdfd2976cb3d321376d52b;hb=fa3486514bd8f15f8eb4c49821d0356b52e5a335;hp=05bd4ece6825508c3b96cf5361f5cd4a15637e6a;hpb=04cacfa50524e0e6f11fa82b5a263fac6a8c21ea;p=gnulib.git diff --git a/lib/pipe.c b/lib/pipe.c index 05bd4ece6..f8e7dee10 100644 --- a/lib/pipe.c +++ b/lib/pipe.c @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -44,26 +44,10 @@ #else /* Unix API. */ -# if HAVE_POSIX_SPAWN -# include -# else -# if HAVE_VFORK_H -# include -# endif -# endif +# include #endif -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - /* The results of open() in this file are not used with fchdir, therefore save some unnecessary work in fchdir.c. */ #undef open @@ -211,14 +195,16 @@ create_pipe (const char *progname, copy of the environment block - ignoring the effects of putenv() and [un]setenv(). */ { - child = spawnvpe (P_NOWAIT, prog_path, prog_argv, environ); + child = spawnvpe (P_NOWAIT, prog_path, (const char **) prog_argv, + (const char **) environ); if (child < 0 && errno == ENOEXEC) { /* prog is not an native executable. Try to execute it as a shell script. Note that prepare_spawn() has already prepended a hidden element "sh.exe" to prog_argv. */ --prog_argv; - child = spawnvpe (P_NOWAIT, prog_argv[0], prog_argv, environ); + child = spawnvpe (P_NOWAIT, prog_argv[0], (const char **) prog_argv, + (const char **) environ); } } if (stdinfd >= 0) @@ -263,7 +249,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; @@ -271,9 +256,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 @@ -292,7 +274,6 @@ create_pipe (const char *progname, * */ -# if HAVE_POSIX_SPAWN if (slave_process) { sigprocmask (SIG_SETMASK, NULL, &blocked_signals); @@ -380,64 +361,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);