Преглед изворни кода

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.
Jan Klemkow пре 6 година
родитељ
комит
6d1a3bbbb8
1 измењених фајлова са 3 додато и 3 уклоњено
  1. 3 3
      scroll.c

+ 3 - 3
scroll.c

@@ -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:");
@@ -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 */