diff options
author | Mark Lumsden <lum@cvs.openbsd.org> | 2016-09-08 07:50:10 +0000 |
---|---|---|
committer | Mark Lumsden <lum@cvs.openbsd.org> | 2016-09-08 07:50:10 +0000 |
commit | e22f08f34ae6c088406f05c5ff7ea2ec413ab8b7 (patch) | |
tree | 8059e83845149b59b3fb6965b6b0495a92d48957 | |
parent | 9fc16e1a4335c3d4a174748940957cb37e168143 (diff) |
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.
ok sunil@ millert@
-rw-r--r-- | usr.bin/mg/region.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/mg/region.c b/usr.bin/mg/region.c index 560a608cc91..0a1a75262c9 100644 --- a/usr.bin/mg/region.c +++ b/usr.bin/mg/region.c @@ -1,4 +1,4 @@ -/* $OpenBSD: region.c,v 1.35 2015/03/19 21:22:15 bcallah Exp $ */ +/* $OpenBSD: region.c,v 1.36 2016/09/08 07:50:09 lum Exp $ */ /* This file is in the public domain. */ @@ -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* const argv[], char* const text, int len, return (FALSE); } - switch(fork()) { + switch((pid = fork())) { case -1: dobeep(); ewprintf("Can't fork"); @@ -548,7 +550,10 @@ pipeio(const char* const path, char* const argv[], char* const text, int len, 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); } |