aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-08-14 15:30:41 +0000
committerAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-08-14 15:30:41 +0000
commitc6f8d14a5230ab4846833800d37eba9384cbb331 (patch)
treeff343dafe35e898d9a38d30fa3986f39921aceb8
parent70ea1692b7560d38478a27e126397b235d042fc0 (diff)
downloadpaludis-c6f8d14a5230ab4846833800d37eba9384cbb331.tar.gz
paludis-c6f8d14a5230ab4846833800d37eba9384cbb331.tar.xz
Cleanup stdout and stderr descriptors after a run_command
-rw-r--r--paludis/util/system.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 9b1b7eb..4706fe8 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -314,7 +314,7 @@ paludis::run_command(const Command & cmd)
if (-1 != stdout_write_fd)
{
if (-1 == dup2(stdout_write_fd, 1))
- throw RunCommandError("dup2 failed");
+ throw RunCommandError("dup2 failed: " + stringify(strerror(errno)));
if (-1 != stdout_close_fd)
close(stdout_close_fd);
@@ -323,7 +323,7 @@ paludis::run_command(const Command & cmd)
if (-1 != stderr_write_fd)
{
if (-1 == dup2(stderr_write_fd, 2))
- throw RunCommandError("dup2 failed");
+ throw RunCommandError("dup2 failed: " + stringify(strerror(errno)));
if (-1 != stderr_close_fd)
close(stderr_close_fd);
@@ -366,6 +366,12 @@ paludis::run_command(const Command & cmd)
else
{
int status(-1);
+
+ stdout_write_fd = -1;
+ stdout_close_fd = -1;
+ stderr_write_fd = -1;
+ stderr_close_fd = -1;
+
if (-1 == wait(&status))
throw RunCommandError("wait failed: " + stringify(strerror(errno)));
return WIFSIGNALED(status) ? WTERMSIG(status) + 128 : WEXITSTATUS(status);