From 8d1784140bef23ca79a0b649f5fe990371ccb88e Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 1 Jun 2006 15:59:31 +0000 Subject: [PATCH] PR/33623: Chuck Cranor: Ping stops when ran in the background because it tries to set the tty not to print kerninfo. Change it to only only play with the tty when ping is running in the foreground (and will not stop when calling tcsetattr()). In my opinion, it is preferable to print the kerninfo line with the ping info message rather than to mess with the tty, but that's just me. --- sbin/ping/ping.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 2b7ac5b08fca..0573e82dd7b5 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $NetBSD: ping.c,v 1.78 2006/05/09 20:18:08 mrg Exp $ */ +/* $NetBSD: ping.c,v 1.79 2006/06/01 15:59:31 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -58,7 +58,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ping.c,v 1.78 2006/05/09 20:18:08 mrg Exp $"); +__RCSID("$NetBSD: ping.c,v 1.79 2006/06/01 15:59:31 christos Exp $"); #endif #include @@ -638,10 +638,14 @@ main(int argc, char *argv[]) (void)signal(SIGINT, prefinish); #if defined(SIGINFO) && defined(NOKERNINFO) - if (tcgetattr (0, &ts) != -1) { - reset_kerninfo = !(ts.c_lflag & NOKERNINFO); - ts.c_lflag |= NOKERNINFO; - tcsetattr (STDIN_FILENO, TCSANOW, &ts); + if (tcgetattr(STDIN_FILENO, &ts) != -1) { + pid_t ttypgrp = tcgetpgrp(STDIN_FILENO); + pid_t pgrp = getpgid(0); + if (ttypgrp != -1 && pgrp != -1 && ttypgrp == pgrp) { + reset_kerninfo = !(ts.c_lflag & NOKERNINFO); + ts.c_lflag |= NOKERNINFO; + (void)tcsetattr(STDIN_FILENO, TCSANOW, &ts); + } } #endif @@ -1351,9 +1355,9 @@ finish(int dummy) #if defined(SIGINFO) && defined(NOKERNINFO) struct termios ts; - if (reset_kerninfo && tcgetattr (0, &ts) != -1) { + if (reset_kerninfo && tcgetattr(STDIN_FILENO, &ts) != -1) { ts.c_lflag &= ~NOKERNINFO; - tcsetattr (STDIN_FILENO, TCSANOW, &ts); + (void)tcsetattr(STDIN_FILENO, TCSANOW, &ts); } (void)signal(SIGINFO, SIG_IGN); #else