+2010-03-20 Bruno Haible <bruno@clisp.org>
+
+ pipe: Set errno upon failure.
+ * lib/pipe.h: Specify that when -1 is returned, errno is set.
+ * lib/pipe.c (create_pipe): Set errno when returning -1. Use the right
+ errno value in error message.
+
2010-03-20 Bruno Haible <bruno@clisp.org>
Jim Meyering <meyering@redhat.com>
int nulloutfd;
int stdinfd;
int stdoutfd;
+ int saved_errno;
/* FIXME: Need to free memory allocated by prepare_spawn. */
prog_argv = prepare_spawn (prog_argv);
(const char **) environ);
}
}
+ if (child == -1)
+ saved_errno = errno;
if (stdinfd >= 0)
close (stdinfd);
if (stdoutfd >= 0)
if (child == -1)
{
if (exit_on_error || !null_stderr)
- error (exit_on_error ? EXIT_FAILURE : 0, errno,
+ error (exit_on_error ? EXIT_FAILURE : 0, saved_errno,
_("%s subprocess failed"), progname);
if (pipe_stdout)
close (ifd[0]);
if (pipe_stdin)
close (ofd[1]);
+ errno = saved_errno;
return -1;
}
close (ofd[0]);
close (ofd[1]);
}
+ errno = err;
return -1;
}
posix_spawn_file_actions_destroy (&actions);
one or two file descriptors for communication with the subprocess.
If the subprocess creation fails: if exit_on_error is true, the main
process exits with an error message; otherwise, an error message is given
- if null_stderr is false, then -1 is returned and fd[] remain uninitialized.
+ if null_stderr is false, then -1 is returned, with errno set, and fd[]
+ remain uninitialized.
After finishing communication, the caller should call wait_subprocess()
to get rid of the subprocess in the process table.