From 9be0faf753d559164949c6bf4545028960f4c8cc Mon Sep 17 00:00:00 2001 From: Marius Halden Date: Thu, 29 Oct 2015 00:33:11 +0100 Subject: Add even more error checking --- piper.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'piper.c') diff --git a/piper.c b/piper.c index 5d47880..cc176e4 100644 --- a/piper.c +++ b/piper.c @@ -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) -- cgit v1.2.3