]> diplodocus.org Git - nmh/commitdiff
runpty.c: Handle fork(2) failure first, rather than child.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 22 Sep 2017 11:49:47 +0000 (12:49 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 22 Sep 2017 11:49:47 +0000 (12:49 +0100)
Gets the error handling out of the way so it can be forgotten.

test/runpty.c

index ef5cf822f0da6932dd55401ee2e7dd542342fb6a..9a7421330207bd005fb500670b03b948c46af92e 100644 (file)
@@ -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"))) {