From 865ecaf732e2f220f925db95c2af5b0d4ddcaadd Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 20 Mar 2013 22:14:04 +0100 Subject: [PATCH] xmp: update tty state as soon as we are in the foreground When xmp is _running_ in the background, and then is brought to the foreground, the program will not necessarily be notified of this state change from external sources, as shells generally do not seem to send gratitious SIGCONTs. Therefore, to get keyboard input and status updates working again once xmp is in the foreground, xmp actively needs to monitor the pgrps itself, which this patch implements. (rsync does it the same way.) --- src/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index f3062f4..98d6555 100644 --- a/src/main.c +++ b/src/main.c @@ -78,14 +78,18 @@ static void sigtstp_handler(int n) static void sigcont_handler(int sig) { #ifdef HAVE_TERMIOS_H + unsigned int old_in = foreground_in; + foreground_in = tcgetpgrp(STDIN_FILENO) == getpgrp(); foreground_out = tcgetpgrp(STDERR_FILENO) == getpgrp(); - if (foreground_in) + if (old_in != foreground_in) + /* Only call if it was not already prepared */ set_tty(); #endif - refresh_status = 1; + if (sig != 0) + refresh_status = 1; signal(SIGCONT, sigcont_handler); signal(SIGTSTP, sigtstp_handler); @@ -379,6 +383,7 @@ int main(int argc, char **argv) if (!control.loop && old_loop != fi.loop_count) break; + sigcont_handler(0); if (foreground_out && opt.verbose > 0) { info_frame(&mi, &fi, &control, refresh_status); refresh_status = 0;