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.)
master
Jan Engelhardt 13 years ago
parent 14c1121c1b
commit 865ecaf732
  1. 9
      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;

Loading…
Cancel
Save