Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1112/2

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Fix a few races.
 [rsc] --rw-rw-r-- M 118305 glenda sys 5708 Nov 12 08:42 sys/src/cmd/ip/ping.c
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:81,86 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:81,88
	  	USED(a);
	  	if(strstr(msg, "alarm"))
	  		noted(NCONT);
	+ 	else if(strstr(msg, "die"))
	+ 		exits("errors");
	  	else
	  		noted(NDFLT);
	  }
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:94,100 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:96,102
	  	for(l = &first; *l; ){
	  		r = *l;
	  
	- 		if(r->seq == seq){
	+ 		if(ip && r->seq == seq){
	  			r->rtt = now-r->time;
	  			r->ttl = ip->ttl;
	  			reply(r, ip);
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:103,109 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:105,112
	  		if(now-r->time > MINUTE){
	  			*l = r->next;
	  			r->rtt = now-r->time;
	- 			r->ttl = ip->ttl;
	+ 			if(ip)
	+ 				r->ttl = ip->ttl;
	  			if(r->replied == 0)
	  				lost(r, ip);
	  			free(r);
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:177,190 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:180,194
	  	ip = (Icmp*)buf;
	  	sum = 0;
	  
	- 	while(!done || first != nil){
	+ 	while(lostmsgs+rcvdmsgs < nmsg){
	  		alarm((nmsg-lostmsgs-rcvdmsgs)*interval+5000);
	  		n = read(fd, buf, sizeof(buf));
	  		alarm(0);
	  		now = nsec();
	- 		if(n <= 0){
	- 			print("read: %r\n");
	- 			break;
	+ 		if(n <= 0){	/* read interrupted - time to go */
	+ fprint(2, "clean\n");
	+ 			clean(0, now+MINUTE, nil);
	+ 			continue;
	  		}
	  		if(n < msglen){
	  			print("bad len %d/%d\n", n, msglen);
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:213,219 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:217,222
	  
	  	if(lostmsgs)
	  		print("%d out of %d messages lost\n", lostmsgs, lostmsgs+rcvdmsgs);
	- 	postnote(PNPROC, senderpid, "die");
	  }
	  
	  void
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:229,234 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:232,238
	  	int fd;
	  	int msglen, interval, nmsg;
	  	int pid;
	+ 	char err[ERRMAX];
	  
	  	nsec();		/* make sure time file is already open */
	  
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:299,307 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:303,312
	  void
	  reply(Req *r, Icmp *ip)
	  {
	- 	rcvdmsgs++;
	  	r->rtt /= 1000LL;
	  	sum += r->rtt;
	+ 	if(!r->replied)
	+ 		rcvdmsgs++;
	  	if(!quiet && !lostonly){
	  		if(addresses)
	  			print("%ud: %V->%V rtt %lld µs, avg rtt %lld µs, ttl = %d\n",
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/ip/ping.c:321,334 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/ip/ping.c:326,336
	  {
	  	if(!quiet){
	  		if(addresses)
	- 			print("lost %ud: %V->%V avg rtt %lld µs\n",
	- 				r->seq-firstseq,
	- 				ip->src, ip->dst,
	- 				sum/rcvdmsgs);
	+ 			print("lost %ud: %V->%V\n", r->seq-firstseq,
	+ 				ip->src, ip->dst);
	  		else
	- 			print("lost %ud: avg rtt %lld µs\n",
	- 				r->seq-firstseq,
	- 				sum/rcvdmsgs);
	+ 			print("lost %ud\n", r->seq-firstseq);
	  	}
	  	lostmsgs++;
	  }
	+ 


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].