From 4098fa3e458c685b90a312e703bed622461b66e9 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Fri, 22 Sep 2017 12:49:47 +0100 Subject: [PATCH] runpty.c: Handle fork(2) failure first, rather than child. Gets the error handling out of the way so it can be forgotten. --- test/runpty.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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"))) { -- 2.56.0