code: plan9front

Download patch

ref: 98e2ea45fb498274b4ea2af48db5c500d7614f7b
parent: 8cbe3772c45431b962971e45581d831772a85947
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Sep 6 14:48:35 EDT 2019

ip/ipconfig: don't leave behind null address when dhcp gets interrupted

cleanup the null address (::) when the command gets interrupted.

--- a/sys/src/cmd/ip/ipconfig/dhcp.c
+++ b/sys/src/cmd/ip/ipconfig/dhcp.c
@@ -155,11 +155,25 @@
 	memcpy(requested, defrequested, nrequested);
 }
 
+static void
+removenulladdr(void)
+{
+	fprint(conf.cfd, "remove %I %M", IPnoaddr, IPnoaddr);
+	atexitdont(removenulladdr);
+}
+
+static void
+addnulladdr(void)
+{
+	atexit(removenulladdr);
+	fprint(conf.cfd, "add %I %M", IPnoaddr, IPnoaddr);
+}
+
 void
 dhcpquery(int needconfig, int startstate)
 {
 	if(needconfig)
-		fprint(conf.cfd, "add %I %M", IPnoaddr, IPnoaddr);
+		addnulladdr();
 
 	conf.fd = openlisten();
 	if(conf.fd < 0){
@@ -192,8 +206,7 @@
 	close(conf.fd);
 
 	if(needconfig)
-		fprint(conf.cfd, "remove %I %M", IPnoaddr, IPnoaddr);
-
+		removenulladdr();
 }
 
 enum {
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -806,7 +806,7 @@
 {
 	if(strstr(msg, "alarm"))
 		noted(NCONT);
-	noted(NDFLT);
+	exits(msg);
 }
 
 /* return pseudo-random integer in range low...(hi-1) */