From: Ralph Corderoy Date: Fri, 22 Sep 2017 11:49:47 +0000 (+0100) Subject: runpty.c: Handle fork(2) failure first, rather than child. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/4098fa3e458c685b90a312e703bed622461b66e9?hp=fad589fd1879f684ba437645e53811320942f8a4 runpty.c: Handle fork(2) failure first, rather than child. Gets the error handling out of the way so it can be forgotten. --- diff --git a/test/runpty.c b/test/runpty.c index ef5cf822..9a742133 100644 --- a/test/runpty.c +++ b/test/runpty.c @@ -43,7 +43,9 @@ main(int argc, char *argv[]) master_in = open_master_pty("input"); master_out = open_master_pty("output"); - child = fork(); + if ((child = fork()) == -1) { + die("fork() failed: %s\n", strerror(errno)); + } /* * Start the child process if we are in the child; open the two @@ -83,9 +85,6 @@ main(int argc, char *argv[]) execvp(argv[2], argv + 2); die("execvp(%s) failed: %s\n", argv[2], strerror(errno)); - - } else if (child < 0) { - die("fork() failed: %s\n", strerror(errno)); } if (!(output = fopen(argv[1], "w"))) {