From 5b9bb79c00873ea890cfad1e678aa73d6533b0ba Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 20 Mar 2013 20:59:05 +0100 Subject: [PATCH] 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 --- src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index e9b989a..98900d3 100644 --- a/src/main.c +++ b/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();