[hackers] [scroll] avoid race condition with sigwinch || Jan Klemkow

From: <git_AT_suckless.org>
Date: Tue, 28 Apr 2020 21:23:04 +0200 (CEST)

commit 6d1a3bbbb870a303b47f790ba76146e61a4c7b6a
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
AuthorDate: Tue Apr 28 21:20:42 2020 +0200
Commit: Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Tue Apr 28 21:20:42 2020 +0200

    avoid race condition with sigwinch
    
    if sigwinch comes before forking the child process,
    we are traped into an endless loop. because, the
    variable child is zero. Thus, we propagating sigwinch
    to ourself in the signal handler.

diff --git a/scroll.c b/scroll.c
index b42bd48..26b0527 100644
--- a/scroll.c
+++ b/scroll.c
_AT_@ -428,9 +428,6 @@ main(int argc, char *argv[])
         if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1)
                 die("ioctl:");
 
- if (signal(SIGWINCH, sigwinch) == SIG_ERR)
- die("signal:");
-
         child = forkpty(&mfd, NULL, &dfl, &ws);
         if (child == -1)
                 die("forkpty:");
_AT_@ -457,6 +454,9 @@ main(int argc, char *argv[])
                 die("pledge:");
 #endif
 
+ 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 */
Received on Tue Apr 28 2020 - 21:23:04 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 28 2020 - 21:24:37 CEST