Source Joachim Nilsson:

    Collect forked off children from M-| command

    Mg left zombies from commands executed when piping a region of text to
    an external command.  This patch makes sure to collect for the child
    before returning.

Looks ok to me. ok?

Index: region.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/region.c,v
retrieving revision 1.35
diff -u -p -u -p -r1.35 region.c
--- region.c    19 Mar 2015 21:22:15 -0000      1.35
+++ region.c    7 Sep 2016 11:58:55 -0000
@@ -12,6 +12,7 @@
 #include <sys/queue.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/wait.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <poll.h>
@@ -515,8 +516,9 @@ int
 pipeio(const char* const path, char* const argv[], char* const text, int len,
     struct buffer *outbp)
 {
-       int s[2];
+       int s[2], ret;
        char *err;
+       pid_t pid;
 
        if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, s) == -1) {
                dobeep();
@@ -524,7 +526,7 @@ pipeio(const char* const path, char* con
                return (FALSE);
        }
 
-       switch(fork()) {
+       switch((pid = fork())) {
        case -1:
                dobeep();
                ewprintf("Can't fork");
@@ -548,7 +550,10 @@ pipeio(const char* const path, char* con
        default:
                /* Parent process */
                close(s[1]);
-               return (iomux(s[0], text, len, outbp));
+               ret = iomux(s[0], text, len, outbp);
+               waitpid(pid, NULL, 0); /* Collect child to prevent zombies */
+
+               return (ret);
        }
        return (FALSE);
 }

Reply via email to