diff options
author | Marius Halden <marius.h@lden.org> | 2015-10-29 00:33:11 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-10-29 00:33:11 +0100 |
commit | 9be0faf753d559164949c6bf4545028960f4c8cc (patch) | |
tree | e5761a86e865e720f81c6ffdfb154adacba6b80a /piper.c | |
parent | dceb90521adabea6271947f26f3fe059f95b48e1 (diff) | |
download | piper-9be0faf753d559164949c6bf4545028960f4c8cc.tar.gz piper-9be0faf753d559164949c6bf4545028960f4c8cc.tar.bz2 piper-9be0faf753d559164949c6bf4545028960f4c8cc.tar.xz |
Add even more error checking
Diffstat (limited to 'piper.c')
-rw-r--r-- | piper.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -121,7 +121,7 @@ run_cmd(struct proc *proc) if (dup2(proc->_stderr, 2) == -1) fail(1, "dup2"); } - close(fds[0]); + close(fds[0]); // These aren't very important if they fail close(fds[1]); execvp(proc->argv[0], proc->argv); @@ -211,7 +211,12 @@ main(int argc, char **argv) err(1, "sigaction"); procs[0].cmd = strdup(argv[1]); + if (procs[0].cmd == NULL) + err(1, "strdup"); + procs[1].cmd = strdup(argv[2]); + if (procs[1].cmd == NULL) + err(1, "strdup"); int i; for (i = 0; i < NUM_PROCS; i++) { @@ -222,7 +227,8 @@ main(int argc, char **argv) gen_argv(&procs[i]); } - pipe(fds); // XXX: Check return code + if (pipe(fds) == -1) + err(1, "pipe"); procs[0]._stdout = fds[1]; procs[0]._stderr = fds[1]; @@ -239,8 +245,12 @@ main(int argc, char **argv) signal_procs(); pid = wait(&status); - if (pid == -1 && errno == EINTR) - continue; + if (pid == -1) { + if (errno == EINTR) + continue; + else + fail(1, "wait"); + } struct proc *p = proc_by_pid(pid); if (p == NULL) |