shithub: riscv

Download patch

ref: c994152a90f479a5f3165590f72b749017b6af3e
parent: 48a644aa316c7d12a77c9dc1d788ad0ef08b93f1
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 18 15:20:31 EDT 2014

ipconfig: fix dhcp watch

in dhcpwatch, the sleep time "secs" could become
zero potentially freezing the lease time.

give up when in Sinit state in dhcpquery() as this
is a terminal state.

--- a/sys/src/cmd/ip/ipconfig/ipconfig.h
+++ b/sys/src/cmd/ip/ipconfig/ipconfig.h
@@ -103,7 +103,7 @@
 void	dhcpquery(int, int);
 void	dhcprecv(void);
 void	dhcpsend(int);
-int	dhcptimer(void);
+void	dhcptimer(void);
 void	dhcpwatch(int);
 void	doadd(int);
 void	doremove(void);
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -182,7 +182,7 @@
 void	dhcpquery(int, int);
 void	dhcprecv(void);
 void	dhcpsend(int);
-int	dhcptimer(void);
+void	dhcptimer(void);
 void	dhcpwatch(int);
 void	doadd(int);
 void	doremove(void);
@@ -933,10 +933,9 @@
 	conf.resend = 0;
 	conf.timeout = time(0) + 4;
 
-	while(conf.state != Sbound){
+	while(conf.state != Sbound && conf.state != Sinit){
 		dhcprecv();
-		if(dhcptimer() < 0)
-			break;
+		dhcptimer();
 	}
 	close(conf.fd);
 
@@ -956,8 +955,7 @@
 void
 dhcpwatch(int needconfig)
 {
-	int secs, s;
-	ulong t;
+	ulong secs, s, t;
 
 	if(nodhcpwatch)
 		return;
@@ -973,10 +971,9 @@
 	procsetname("dhcpwatch");
 	/* keep trying to renew the lease */
 	for(;;){
-		if(conf.lease == 0)
+		secs = conf.lease/2;
+		if(secs < 5)
 			secs = 5;
-		else
-			secs = conf.lease >> 1;
 
 		/* avoid overflows */
 		for(s = secs; s > 0; s -= t){
@@ -1022,7 +1019,7 @@
 	}
 }
 
-int
+void
 dhcptimer(void)
 {
 	ulong now;
@@ -1029,7 +1026,7 @@
 
 	now = time(0);
 	if(now < conf.timeout)
-		return 0;
+		return;
 
 	switch(conf.state) {
 	default:
@@ -1042,10 +1039,8 @@
 	case Srebinding:
 		dhcpsend(conf.state == Sselecting? Discover: Request);
 		conf.timeout = now + 4;
-		if(++conf.resend > 5) {
+		if(++conf.resend > 5)
 			conf.state = Sinit;
-			return -1;
-		}
 		break;
 	case Srenewing:
 		dhcpsend(Request);
@@ -1056,7 +1051,6 @@
 		}
 		break;
 	}
-	return 0;
 }
 
 void