commit 3fc721d074811416f4024976c472ddc396c4f00d
Author:     Jan Klemkow <[email protected]>
AuthorDate: Thu Apr 16 22:34:15 2020 +0200
Commit:     Jan Klemkow <[email protected]>
CommitDate: Thu Apr 16 22:34:15 2020 +0200

    ptty: wait for corrent child pid

diff --git a/ptty.c b/ptty.c
index 9d7ee3b..156e1a5 100644
--- a/ptty.c
+++ b/ptty.c
@@ -79,8 +79,8 @@ main(int argc, char *argv[])
                usage();
 
        int mfd;
-       pid_t pid = forkpty(&mfd, NULL, NULL, &ws);
-       switch (pid) {
+       pid_t child = forkpty(&mfd, NULL, NULL, &ws);
+       switch (child) {
        case -1:
                die("forkpty");
        case  0: /* child */
@@ -138,8 +138,11 @@ main(int argc, char *argv[])
                        break;
        }
 
+       pid_t pid;
        int status;
-       waitpid(pid, &status, 0);
+       while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
+               if (pid != child)
+                       continue;
 
        return WEXITSTATUS(status);
 }

Reply via email to