Browse Source

fix race condition between sigwinch and sigchld

sigwinch died if it tries to set the window size
to a file descriptor of an exited child.  Thus,
we just ignore this error in that situation.
Jan Klemkow 5 years ago
parent
commit
1dbf2dce08
1 changed files with 4 additions and 1 deletions
  1. 4 1
      scroll.c

+ 4 - 1
scroll.c

@@ -96,8 +96,11 @@ sigwinch(int sig)
 
 
 	if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1)
 	if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1)
 		die("ioctl:");
 		die("ioctl:");
-	if (ioctl(mfd, TIOCSWINSZ, &ws) == -1)
+	if (ioctl(mfd, TIOCSWINSZ, &ws) == -1) {
+		if (errno == EBADF)	/* child already exited */
+			return;
 		die("ioctl:");
 		die("ioctl:");
+	}
 	kill(-child, SIGWINCH);
 	kill(-child, SIGWINCH);
 	doredraw = true;
 	doredraw = true;
 }
 }