aboutsummaryrefslogtreecommitdiff
path: root/lib/roken/simple_exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/roken/simple_exec.c')
-rw-r--r--lib/roken/simple_exec.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/roken/simple_exec.c b/lib/roken/simple_exec.c
index 97679d7e4175..552e121b0d22 100644
--- a/lib/roken/simple_exec.c
+++ b/lib/roken/simple_exec.c
@@ -144,17 +144,31 @@ ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
pipe_execv(FILE **stdin_fd, FILE **stdout_fd, FILE **stderr_fd,
const char *file, ...)
{
- int in_fd[2], out_fd[2], err_fd[2];
+ int in_fd[2] = {-1, -1};
+ int out_fd[2] = {-1, -1};
+ int err_fd[2] = {-1, -1};
pid_t pid;
va_list ap;
char **argv;
+ int ret = 0;
if(stdin_fd != NULL)
- pipe(in_fd);
- if(stdout_fd != NULL)
- pipe(out_fd);
- if(stderr_fd != NULL)
- pipe(err_fd);
+ ret = pipe(in_fd);
+ if(ret != -1 && stdout_fd != NULL)
+ ret = pipe(out_fd);
+ if(ret != -1 && stderr_fd != NULL)
+ ret = pipe(err_fd);
+
+ if (ret == -1) {
+ close(in_fd[0]);
+ close(in_fd[1]);
+ close(out_fd[0]);
+ close(out_fd[1]);
+ close(err_fd[0]);
+ close(err_fd[1]);
+ return SE_E_UNSPECIFIED;
+ }
+
pid = fork();
switch(pid) {
case 0: