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

cleanup the null address (::) when the command gets interrupted.
This commit is contained in:
cinap_lenrek 2019-09-06 18:48:35 +02:00
parent 8cbe3772c4
commit 98e2ea45fb
2 changed files with 17 additions and 4 deletions

View file

@ -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 {

View file

@ -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) */