Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-2]: src/sbin/ping Pull up following revision(s) (requested by ghe...



details:   https://anonhg.NetBSD.org/src/rev/9a11ccc2271c
branches:  netbsd-2
changeset: 564605:9a11ccc2271c
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Aug 11 14:08:43 2007 +0000

description:
Pull up following revision(s) (requested by ghen in ticket #11351):
        sbin/ping/ping.c: revision 1.79, 1.80
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.
Factor out the tty code and explain we prefer to stop in the ^Z bg case
when we exit, rather than kill the tty setting.

diffstat:

 sbin/ping/ping.c |  39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)

diffs (84 lines):

diff -r 96c0b8e2aaa2 -r 9a11ccc2271c sbin/ping/ping.c
--- a/sbin/ping/ping.c  Sat Aug 11 14:03:47 2007 +0000
+++ b/sbin/ping/ping.c  Sat Aug 11 14:08:43 2007 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ping.c,v 1.75 2004/01/26 02:21:30 itojun Exp $ */
+/*     $NetBSD: ping.c,v 1.75.4.1 2007/08/11 14:08:43 bouyer Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -58,7 +58,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.75 2004/01/26 02:21:30 itojun Exp $");
+__RCSID("$NetBSD: ping.c,v 1.75.4.1 2007/08/11 14:08:43 bouyer Exp $");
 #endif
 
 #include <stdio.h>
@@ -241,7 +241,9 @@
 static void gethost(const char *, const char *,
                    struct sockaddr_in *, char *, int);
 static void usage(void);
-
+#if defined(SIGINFO) && defined(NOKERNINFO)
+static int fgtty(int, struct termios *);
+#endif
 
 int
 main(int argc, char *argv[])
@@ -638,10 +640,10 @@
        (void)signal(SIGINT, prefinish);
 
 #if defined(SIGINFO) && defined(NOKERNINFO)
-       if (tcgetattr (0, &ts) != -1) {
+       if (fgtty(STDIN_FILENO, &ts) != -1) {
                reset_kerninfo = !(ts.c_lflag & NOKERNINFO);
                ts.c_lflag |= NOKERNINFO;
-               tcsetattr (STDIN_FILENO, TCSANOW, &ts);
+               (void)tcsetattr(STDIN_FILENO, TCSANOW, &ts);
        }
 #endif
 
@@ -1340,6 +1342,22 @@
                npackets = ntransmitted;
 }
 
+#if defined(SIGINFO) && defined(NOKERNINFO)
+static int
+fgtty(int fd, struct termios *ts)
+{
+       pid_t ttypgrp, pgrp;
+
+       if (tcgetattr(fd, ts) == -1)
+               return -1;
+       if ((ttypgrp = tcgetpgrp(fd)) == -1)
+               return -1;
+       if ((pgrp = getpgid(0)) == -1)
+               return -1;
+
+       return ttypgrp == pgrp ? 0 : -1;
+}
+#endif
 
 /*
  * Print statistics and give up.
@@ -1351,9 +1369,16 @@
 #if defined(SIGINFO) && defined(NOKERNINFO)
        struct termios ts;
 
-       if (reset_kerninfo && tcgetattr (0, &ts) != -1) {
+       /*
+        * Note that the following will suspend the ping program
+        * if it is in the background. We could have used fgtty()
+        * to avoid this, but then we would fail to restore the
+        * tty setting. So we prefer to suspend here. XXX: NOKERNINFO
+        * should prolly be a signal struct attribute
+        */
+       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



Home | Main Index | Thread Index | Old Index