ref: 7706417f512c8c14104600e8b119f9899e0deb62
parent: 7d2ef012c68599e409197cd415d5b0a708d5c2b4
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) */
--
⑨