commit d40d23e29abf05092af051831c400a220c41ffb7
Author: Jan Klemkow <[email protected]>
AuthorDate: Tue Apr 14 21:33:11 2020 +0200
Commit: Jan Klemkow <[email protected]>
CommitDate: Tue Apr 14 21:33:11 2020 +0200
move signal handling before fork to avoid race with sigchild
diff --git a/scroll.c b/scroll.c
index a560999..cf12ff3 100644
--- a/scroll.c
+++ b/scroll.c
@@ -415,6 +415,11 @@ 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:");
+
child = forkpty(&mfd, NULL, &dfl, &ws);
if (child == -1)
die("forkpty:");
@@ -441,11 +446,6 @@ main(int argc, char *argv[])
die("pledge:");
#endif
- if (signal(SIGCHLD, sigchld) == SIG_ERR)
- die("signal:");
- if (signal(SIGWINCH, sigwinch) == SIG_ERR)
- die("signal:");
-
struct termios new = dfl;
cfmakeraw(&new);
new.c_cc[VMIN ] = 1; /* return read if at least one byte in buffer */