aboutsummaryrefslogtreecommitdiff
path: root/sbin/ping/ping.c
diff options
context:
space:
mode:
authorSean Eric Fagan <sef@FreeBSD.org>1997-07-13 06:16:44 +0000
committerSean Eric Fagan <sef@FreeBSD.org>1997-07-13 06:16:44 +0000
commita2a008880568eaeb87d8404b39627b83df851f34 (patch)
treec9dfcbb86b9ae283daf85e1ed60294b9cfe150af /sbin/ping/ping.c
parent7503ccc1c8c31ff7fba47cc48e8a6abfa2d6adaf (diff)
downloadsrc-a2a008880568eaeb87d8404b39627b83df851f34.tar.gz
src-a2a008880568eaeb87d8404b39627b83df851f34.zip
Fix a problem introduced with a recent change that caused a hang with
unreachable hosts. Note that most of this consists of telling SIGINT and SIGALRM to interrupt the system call, instead of restarting them. Also try to get rid of some potential races Bruce didn't like; hopefully they aren't a problem (potential or otherwise) now. Reviewed by: julian
Notes
Notes: svn path=/head/; revision=27354
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r--sbin/ping/ping.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index 5f89641eddd4..5479d64d51c3 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -45,7 +45,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
*/
static const char rcsid[] =
- "$Id: ping.c,v 1.22 1997/07/09 19:40:43 julian Exp $";
+ "$Id: ping.c,v 1.23 1997/07/09 20:33:58 julian Exp $";
#endif /* not lint */
/*
@@ -423,16 +423,25 @@ main(argc, argv)
else
(void)printf("PING %s: %d data bytes\n", hostname, datalen);
- (void)signal(SIGINT, stopit);
- (void)signal(SIGALRM, catcher);
-
/*
- * Use sigaction instead of signal() to get unambiguous semantics
- * for SIGINFO, in particular with SA_RESTART not set.
+ * Use sigaction() instead of signal() to get unambiguous semantics,
+ * in particular with SA_RESTART not set.
*/
- si_sa.sa_handler = status;
+
sigemptyset(&si_sa.sa_mask);
si_sa.sa_flags = 0;
+
+ si_sa.sa_handler = stopit;
+ if (sigaction(SIGINT, &si_sa, 0) == -1) {
+ err(EX_OSERR, "sigaction SIGINT");
+ }
+
+ si_sa.sa_handler = catcher;
+ if (sigaction(SIGALRM, &si_sa, 0) == -1) {
+ err(EX_OSERR, "sigaction SIGALRM");
+ }
+
+ si_sa.sa_handler = status;
if (sigaction(SIGINFO, &si_sa, 0) == -1) {
err(EX_OSERR, "sigaction");
}
@@ -508,11 +517,12 @@ static void
catcher(int sig)
{
int waittime;
+ struct sigaction si_sa;
pinger();
- (void)signal(SIGALRM, catcher);
+
if (!npackets || ntransmitted < npackets)
- alarm((u_int)interval);
+ (void)alarm((u_int)interval);
else {
if (nreceived) {
waittime = 2 * tmax / 1000;
@@ -520,7 +530,14 @@ catcher(int sig)
waittime = 1;
} else
waittime = MAXWAIT;
- (void)signal(SIGALRM, stopit);
+
+ si_sa.sa_handler = stopit;
+ sigemptyset(&si_sa.sa_mask);
+ si_sa.sa_flags = 0;
+ if (sigaction(SIGALRM, &si_sa, 0) == -1) {
+ finish_up = 1;
+ return;
+ }
(void)alarm((u_int)waittime);
}
}
@@ -889,6 +906,7 @@ finish(int sig)
struct termios ts;
(void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGALRM, SIG_IGN);
(void)putchar('\n');
(void)fflush(stdout);
(void)printf("--- %s ping statistics ---\n", hostname);