Skip to content

Commit

Permalink
Removed a SIGWINCH race.
Browse files Browse the repository at this point in the history
[nelhage@nelhage.com: Use sig_atomic_t, and document the remaining race better]
  • Loading branch information
robryk authored and nelhage committed Feb 28, 2012
1 parent 0c34e73 commit 022d0ad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions reptyr.c
Expand Up @@ -108,7 +108,7 @@ int writeall(int fd, const void *buf, ssize_t count) {
return 0;
}

int winch_happened = 0;
volatile sig_atomic_t winch_happened = 0;

void do_winch(int signal) {
winch_happened = 1;
Expand All @@ -120,9 +120,13 @@ void do_proxy(int pty) {
fd_set set;
while (1) {
if (winch_happened) {
resize_pty(pty);
/* FIXME: racy against a second resize */
winch_happened = 0;
/*
* FIXME: If a signal comes in after this point but before
* select(), the resize will be delayed until we get more
* input. signalfd() is probably the cleanest solution.
*/
resize_pty(pty);
}
FD_ZERO(&set);
FD_SET(0, &set);
Expand Down Expand Up @@ -244,11 +248,11 @@ int main(int argc, char **argv) {
}

setup_raw(&saved_termios);
resize_pty(pty);
memset(&act, 0, sizeof act);
act.sa_handler = do_winch;
act.sa_flags = 0;
sigaction(SIGWINCH, &act, NULL);
resize_pty(pty);
do_proxy(pty);
tcsetattr(0, TCSANOW, &saved_termios);

Expand Down

0 comments on commit 022d0ad

Please sign in to comment.