From 98e2ea45fb498274b4ea2af48db5c500d7614f7b Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 6 Sep 2019 18:48:35 +0200 Subject: [PATCH] ip/ipconfig: don't leave behind null address when dhcp gets interrupted cleanup the null address (::) when the command gets interrupted. --- sys/src/cmd/ip/ipconfig/dhcp.c | 19 ++++++++++++++++--- sys/src/cmd/ip/ipconfig/main.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/sys/src/cmd/ip/ipconfig/dhcp.c b/sys/src/cmd/ip/ipconfig/dhcp.c index 2b28a7f87..05c363dcb 100644 --- a/sys/src/cmd/ip/ipconfig/dhcp.c +++ b/sys/src/cmd/ip/ipconfig/dhcp.c @@ -155,11 +155,25 @@ dhcpinit(void) 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 @@ dhcpquery(int needconfig, int startstate) close(conf.fd); if(needconfig) - fprint(conf.cfd, "remove %I %M", IPnoaddr, IPnoaddr); - + removenulladdr(); } enum { diff --git a/sys/src/cmd/ip/ipconfig/main.c b/sys/src/cmd/ip/ipconfig/main.c index 20113725c..52cf46fd9 100644 --- a/sys/src/cmd/ip/ipconfig/main.c +++ b/sys/src/cmd/ip/ipconfig/main.c @@ -806,7 +806,7 @@ catch(void*, char *msg) { if(strstr(msg, "alarm")) noted(NCONT); - noted(NDFLT); + exits(msg); } /* return pseudo-random integer in range low...(hi-1) */