Change the exit status for 0 and 2 to be the same as with ping(1)

and be usable in scripts, etc.

This also changes the semantics in case when we lose one of n packets.
In that case, before we exited by SIG, now we exit with return(0).

Submitted by:	Gert Doering (gert space.net)
MFC after:	10 days
This commit is contained in:
bz 2008-05-27 10:51:19 +00:00
parent 87fbf5762c
commit 08921e6dda
2 changed files with 9 additions and 4 deletions

View File

@ -29,7 +29,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd November 15, 2007 .Dd May 27, 2008
.Dt PING6 8 .Dt PING6 8
.Os .Os
.Sh NAME .Sh NAME
@ -409,7 +409,9 @@ option of
The The
.Nm .Nm
utility returns 0 on success (the host is alive), utility returns 0 on success (the host is alive),
and non-zero if the arguments are incorrect or the host is not responding. 2 if the transmission was successful but no responses were received,
any other non-zero value if the arguments are incorrect or
another error has occured.
.Sh EXAMPLES .Sh EXAMPLES
Normally, Normally,
.Nm .Nm

View File

@ -1074,6 +1074,9 @@ main(argc, argv)
/* signal handling */ /* signal handling */
if (seenalrm) { if (seenalrm) {
/* last packet sent, timeout reached? */
if (npackets && ntransmitted >= npackets)
break;
retransmit(); retransmit();
seenalrm = 0; seenalrm = 0;
continue; continue;
@ -1173,7 +1176,7 @@ main(argc, argv)
break; break;
} }
summary(); summary();
exit(nreceived == 0); exit(nreceived == 0 ? 2 : 0);
} }
void void
@ -1224,7 +1227,7 @@ retransmit()
itimer.it_interval.tv_usec = 0; itimer.it_interval.tv_usec = 0;
itimer.it_value.tv_usec = 0; itimer.it_value.tv_usec = 0;
(void)signal(SIGALRM, onint); (void)signal(SIGALRM, onsignal);
(void)setitimer(ITIMER_REAL, &itimer, NULL); (void)setitimer(ITIMER_REAL, &itimer, NULL);
} }