Date: Sat, 15 Feb 2020 15:39:53 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357967 - head/sbin/ping6 Message-ID: <202002151539.01FFdrH7054398@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Sat Feb 15 15:39:53 2020 New Revision: 357967 URL: https://svnweb.freebsd.org/changeset/base/357967 Log: Make ping6(1) return code consistent with the man page. When every sendto() call originated by ping6(1) fails, current code always returns 2 ("transmission was successful but no responses were received") which is incorrect. Return EX_OSERR instead as in many cases it indicates some kernel-level problems. MFC after: 3 weeks Modified: head/sbin/ping6/ping6.c Modified: head/sbin/ping6/ping6.c ============================================================================== --- head/sbin/ping6/ping6.c Sat Feb 15 15:05:25 2020 (r357966) +++ head/sbin/ping6/ping6.c Sat Feb 15 15:39:53 2020 (r357967) @@ -238,6 +238,7 @@ static long npackets; /* max packets to transmit */ static long nreceived; /* # of packets we got back */ static long nrepeats; /* number of duplicates */ static long ntransmitted; /* sequence # for outbound packets = #sent */ +static long ntransmitfailures; /* number of transmit failures */ static int interval = 1000; /* interval between packets in ms */ static int waittime = MAXWAIT; /* timeout for each packet */ static long nrcvtimeout = 0; /* # of packets we got back after waittime */ @@ -1256,7 +1257,12 @@ main(int argc, char *argv[]) if(packet != NULL) free(packet); - exit(nreceived == 0 ? 2 : 0); + if (nreceived > 0) + exit(0); + else if (ntransmitted > ntransmitfailures) + exit(2); + else + exit(EX_OSERR); } static void @@ -1423,8 +1429,10 @@ pinger(void) i = sendmsg(ssend, &smsghdr, 0); if (i < 0 || i != cc) { - if (i < 0) + if (i < 0) { + ntransmitfailures++; warn("sendmsg"); + } (void)printf("ping6: wrote %s %d chars, ret=%d\n", hostname, cc, i); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202002151539.01FFdrH7054398>