ping: don't spin when we get error reading icmp connection, print error and sleep
This commit is contained in:
parent
6031dd83b6
commit
dbf165e1bd
1 changed files with 10 additions and 2 deletions
|
@ -303,6 +303,7 @@ rcvr(int fd, int msglen, int interval, int nmsg)
|
||||||
int i, n, munged;
|
int i, n, munged;
|
||||||
ushort x;
|
ushort x;
|
||||||
vlong now;
|
vlong now;
|
||||||
|
char err[ERRMAX];
|
||||||
uchar buf[64*1024+512];
|
uchar buf[64*1024+512];
|
||||||
Icmphdr *icmp;
|
Icmphdr *icmp;
|
||||||
Req *r;
|
Req *r;
|
||||||
|
@ -312,9 +313,16 @@ rcvr(int fd, int msglen, int interval, int nmsg)
|
||||||
alarm((nmsg-lostmsgs-rcvdmsgs)*interval+waittime);
|
alarm((nmsg-lostmsgs-rcvdmsgs)*interval+waittime);
|
||||||
n = read(fd, buf, sizeof buf);
|
n = read(fd, buf, sizeof buf);
|
||||||
alarm(0);
|
alarm(0);
|
||||||
|
if(n == 0)
|
||||||
|
strcpy(err, "got eof");
|
||||||
|
else if(n < 0)
|
||||||
|
rerrstr(err, sizeof(err));
|
||||||
now = nsec();
|
now = nsec();
|
||||||
if(n <= 0){ /* read interrupted - time to go */
|
if(n <= 0){
|
||||||
|
print("%s\n", err);
|
||||||
clean(0, now+MINUTE, nil);
|
clean(0, now+MINUTE, nil);
|
||||||
|
if(strstr(err, "interrupted") == nil)
|
||||||
|
sleep(waittime);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(n < msglen){
|
if(n < msglen){
|
||||||
|
@ -572,7 +580,7 @@ main(int argc, char **argv)
|
||||||
switch(rfork(RFPROC|RFMEM|RFFDG)){
|
switch(rfork(RFPROC|RFMEM|RFFDG)){
|
||||||
case -1:
|
case -1:
|
||||||
fprint(2, "%s: can't fork: %r\n", argv0);
|
fprint(2, "%s: can't fork: %r\n", argv0);
|
||||||
/* fallthrough */
|
exits("forking");
|
||||||
case 0:
|
case 0:
|
||||||
rcvr(fd, msglen, interval, nmsg);
|
rcvr(fd, msglen, interval, nmsg);
|
||||||
exits(0);
|
exits(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue