scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs | README

commit 97b90414891e957c95caffe078c69b18aa38e659
parent d10c029b182fef1af4c6ec2713f9a8a3a5245edb
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Fri, 17 Apr 2020 21:46:55 +0200

handle child exit via POLLHUP instead of sigchld

this fix a racecondition which leads to wrong return code.

Diffstat:
Mscroll.c | 21++-------------------
1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -90,19 +90,6 @@ die(const char *fmt, ...) } void -sigchld(int sig) -{ - pid_t pid; - int status; - - assert(sig == SIGCHLD); - - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) - if (pid == child) - exit(WEXITSTATUS(status)); -} - -void sigwinch(int sig) { assert(sig == SIGWINCH); @@ -421,8 +408,6 @@ main(int argc, char *argv[]) if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) die("ioctl:"); - if (signal(SIGCHLD, sigchld) == SIG_ERR) - die("signal:"); if (signal(SIGWINCH, sigwinch) == SIG_ERR) die("signal:"); @@ -553,11 +538,9 @@ main(int argc, char *argv[]) if (close(mfd) == -1) die("close:"); - pid_t pid; int status; - while ((pid = waitpid(-1, &status, WNOHANG)) > 0) - if (pid != child) - continue; + if (waitpid(child, &status, 0) == -1) + die("waitpid:"); return WEXITSTATUS(status); }