shithub: riscv

Download patch

ref: dbf165e1bdcc65d94ed9c0d70e5d24df5ad4fc8f
parent: 6031dd83b632651013a7e7e707632ebabb68367f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Aug 26 17:07:59 EDT 2014

ping: don't spin when we get error reading icmp connection, print error and sleep

--- a/sys/src/cmd/ip/ping.c
+++ b/sys/src/cmd/ip/ping.c
@@ -303,6 +303,7 @@
 	int i, n, munged;
 	ushort x;
 	vlong now;
+	char err[ERRMAX];
 	uchar buf[64*1024+512];
 	Icmphdr *icmp;
 	Req *r;
@@ -312,9 +313,16 @@
 		alarm((nmsg-lostmsgs-rcvdmsgs)*interval+waittime);
 		n = read(fd, buf, sizeof buf);
 		alarm(0);
+		if(n == 0)
+			strcpy(err, "got eof");
+		else if(n < 0)
+			rerrstr(err, sizeof(err));
 		now = nsec();
-		if(n <= 0){	/* read interrupted - time to go */
+		if(n <= 0){
+			print("%s\n", err);
 			clean(0, now+MINUTE, nil);
+			if(strstr(err, "interrupted") == nil)
+				sleep(waittime);
 			continue;
 		}
 		if(n < msglen){
@@ -572,7 +580,7 @@
 	switch(rfork(RFPROC|RFMEM|RFFDG)){
 	case -1:
 		fprint(2, "%s: can't fork: %r\n", argv0);
-		/* fallthrough */
+		exits("forking");
 	case 0:
 		rcvr(fd, msglen, interval, nmsg);
 		exits(0);