xmp: fix detection of background process

XMP misdetects who is in foreground. The parent may be an arbitrary
process within the process group and thus does not make sense to
compare to. To demonstrate the issue:

$ perl -e 'system "perl -e \"system \\\"xmp Dreamer.it\\\"\""'

XMP will not print the time status, even though there is no background
involved here. The process structure is:

$ ps f -o pid,pgrp,pgid,tpgid,command
  PID  PGRP TPGID COMMAND
16095 16095 19847 bash
19847 19847 19847  \_ perl -e system "perl -e \"system \\\"xmp Dreamer.it\\\"\""
19848 19847 19847      \_ perl -e system "xmp Dreamer.it"
19849 19847 19847          \_ xmp Dreamer.it
master
Jan Engelhardt 13 years ago
parent a44ab1b201
commit 5b9bb79c00
  1. 4
      src/main.c

@ -78,7 +78,7 @@ static void sigtstp_handler(int n)
static void sigcont_handler(int sig)
{
#ifdef HAVE_TERMIOS_H
foreground = (tcgetpgrp(0) != getppid());
foreground = tcgetpgrp(STDIN_FILENO) == getpgrp();
if (foreground)
set_tty();
@ -261,7 +261,7 @@ int main(int argc, char **argv)
#endif
#ifdef HAVE_TERMIOS_H
foreground = (tcgetpgrp (0) != getppid ());
foreground = tcgetpgrp(STDIN_FILENO) == getpgrp();
if (foreground)
set_tty();

Loading…
Cancel
Save