summaryrefslogtreecommitdiff
path: root/lib/pipe.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-03-20 17:20:29 +0100
committerBruno Haible <bruno@clisp.org>2010-03-20 17:20:29 +0100
commit062cad2d07081f9a60adbb90fc1184a435a1a93f (patch)
tree267f1c0aa49dab4304d07987b0302b35f3d3b1e0 /lib/pipe.c
parentb1eaa47f003b6a9a227a56967e2c650515a6432b (diff)
downloadgnulib-062cad2d07081f9a60adbb90fc1184a435a1a93f.tar.gz
pipe: Set errno upon failure.
Diffstat (limited to 'lib/pipe.c')
-rw-r--r--lib/pipe.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/pipe.c b/lib/pipe.c
index 6986525081..1c81d14523 100644
--- a/lib/pipe.c
+++ b/lib/pipe.c
@@ -128,6 +128,7 @@ create_pipe (const char *progname,
int nulloutfd;
int stdinfd;
int stdoutfd;
+ int saved_errno;
/* FIXME: Need to free memory allocated by prepare_spawn. */
prog_argv = prepare_spawn (prog_argv);
@@ -203,6 +204,8 @@ create_pipe (const char *progname,
(const char **) environ);
}
}
+ if (child == -1)
+ saved_errno = errno;
if (stdinfd >= 0)
close (stdinfd);
if (stdoutfd >= 0)
@@ -225,12 +228,13 @@ create_pipe (const char *progname,
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;
}
@@ -350,6 +354,7 @@ create_pipe (const char *progname,
close (ofd[0]);
close (ofd[1]);
}
+ errno = err;
return -1;
}
posix_spawn_file_actions_destroy (&actions);