From: Roy Marples Date: Tue, 16 Jan 2007 17:54:07 +0000 (+0000) Subject: For infinite timeout, we now resent the last request at TIMEOUT_MINI X-Git-Tag: v3.2.3~326 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d19de577b30a50cc124067698d71a0dc1b51ca6;p=thirdparty%2Fdhcpcd.git For infinite timeout, we now resent the last request at TIMEOUT_MINI intervals like we do otherwise. We now return a non zero exit code on SIGTERM and SIGINT if we have not forked into the background. When NIS and/or NTP servers are updated, we restart the service for them if we can. --- diff --git a/ChangeLog b/ChangeLog index 3960c5f8..893ad31e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +For infinite timeout, we now resent the last request at TIMEOUT_MINI +intervals like we do otherwise. +We now return a non zero exit code on SIGTERM and SIGINT if we have not +forked into the background. +When NIS and/or NTP servers are updated, we restart the service for them +if we can. + dhcpcd-3.0.9 Add static routes before any default routes as a router may require a host route in the static routes. diff --git a/Makefile b/Makefile index 27c678a2..e5708e22 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Should work for both GNU make and BSD make -VERSION = 3.0.9 +VERSION = 3.0.10_pre1 CFLAGS ?= -O2 -pipe @@ -59,7 +59,7 @@ install: $(TARGET) $(INSTALL) -m 0755 $(MAN8_TARGETS) $(MANDIR)/man8 clean: - rm -f $(TARGET) $(dhcpcd_H) *.o *~ + rm -f $(TARGET) $(dhcpcd_H) *.o *~ *.core dist: $(INSTALL) -m 0755 -d /tmp/dhcpcd-$(VERSION) diff --git a/arp.c b/arp.c index 2c9ff0ad..4d210bc8 100644 --- a/arp.c +++ b/arp.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/arp.h b/arp.h index 4dfd007d..25563c60 100644 --- a/arp.h +++ b/arp.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2005 - 2007 Roy Marples * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by diff --git a/client.c b/client.c index 0116f84d..0c0abedf 100644 --- a/client.c +++ b/client.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * @@ -172,8 +172,16 @@ int dhcp_run (const options_t *options) if (options->timeout == 0 || dhcp->leasetime == (unsigned) -1) { logger (LOG_DEBUG, "waiting on select for infinity"); - maxfd = signal_fd_set (&rset, iface->fd); - retval = select (maxfd + 1, &rset, NULL, NULL, NULL); + retval = 0; + while (retval == 0) + { + tv.tv_sec = TIMEOUT_MINI; + tv.tv_usec = 0; + maxfd = signal_fd_set (&rset, iface->fd); + retval = select (maxfd + 1, &rset, NULL, NULL, &tv); + if (retval == 0) + SEND_MESSAGE (last_type); + } } else { @@ -216,12 +224,12 @@ int dhcp_run (const options_t *options) { case SIGINT: logger (LOG_INFO, "receieved SIGINT, stopping"); - retval = 0; + retval = (! daemonised); goto eexit; case SIGTERM: logger (LOG_INFO, "receieved SIGTERM, stopping"); - retval = 0; + retval = (! daemonised); goto eexit; case SIGALRM: diff --git a/client.h b/client.h index 3acbfeaf..88c460e1 100644 --- a/client.h +++ b/client.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/common.c b/common.c index 5739e4ff..c7a50e02 100644 --- a/common.c +++ b/common.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/common.h b/common.h index dee34d6d..3ef15804 100644 --- a/common.h +++ b/common.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/configure.c b/configure.c index c7b26920..3ff4d84d 100644 --- a/configure.c +++ b/configure.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -74,11 +75,50 @@ static char *cleanmetas (const char *cstr) return b; } +/* IMPORTANT: Ensure that the last parameter is NULL when calling */ +static int exec_cmd (const char *cmd, const char *args, ...) +{ + va_list va; + pid_t pid; + char **argv; + int n = 1; + + va_start (va, args); + while (va_arg (va, char *) != NULL) + n++; + va_end (va); + argv = alloca ((n + 1) * sizeof (*argv)); + if (argv == NULL) + { + errno = ENOMEM; + return -1; + } + + va_start (va, args); + n = 2; + argv[0] = (char *) cmd; + argv[1] = (char *) args; + while ((argv[n] = va_arg (va, char *)) != NULL) + n++; + va_end (va); + + if ((pid = fork ()) == 0) + { + if (execve (cmd, argv, NULL) && errno != ENOENT) + logger (LOG_ERR, "error executing \"%s\": %s", + cmd, strerror (errno)); + exit (0); + } + else if (pid == -1) + logger (LOG_ERR, "fork: %s", strerror (errno)); + + return 0; +} + static void exec_script (const char *script, const char *infofile, const char *arg) { struct stat buf; - pid_t pid; if (! script || ! infofile || ! arg) return; @@ -91,19 +131,7 @@ static void exec_script (const char *script, const char *infofile, } logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg); - - /* We don't wait for the user script to finish - do we trust it? */ - /* Don't use vfork as we lose our memory when dhcpcd exits - causing the script to fail */ - if ((pid = fork ()) == 0) - { - if (execle (script, script, infofile, arg, NULL, NULL)) - logger (LOG_ERR, "error executing \"%s %s %s\": %s", - script, infofile, arg, strerror (errno)); - exit (0); - } - else if (pid == -1) - logger (LOG_ERR, "fork: %s", strerror (errno)); + exec_cmd (script, infofile, arg, NULL); } static int make_resolv (const char *ifname, const dhcp_t *dhcp) @@ -157,27 +185,12 @@ static int make_resolv (const char *ifname, const dhcp_t *dhcp) static void restore_resolv(const char *ifname) { struct stat buf; - pid_t pid; if (stat (RESOLVCONF, &buf) < 0) return; logger (LOG_DEBUG, "removing information from resolvconf"); - - /* Don't wait around here as we should only be called when - dhcpcd is closing down and something may do a kill -9 - if we take too long */ - /* Don't use vfork as we lose our memory when dhcpcd exits - causing the script to fail */ - if ((pid = fork ()) == 0) - { - if (execle (RESOLVCONF, RESOLVCONF, "-d", ifname, NULL, NULL)) - logger (LOG_ERR, "error executing \"%s -d %s\": %s", - RESOLVCONF, ifname, strerror (errno)); - exit (0); - } - else if (pid == -1) - logger (LOG_ERR, "fork: %s", strerror (errno)); + exec_cmd (RESOLVCONF, "-d", ifname, NULL); } static int make_ntp (const char *ifname, const dhcp_t *dhcp) @@ -206,6 +219,8 @@ static int make_ntp (const char *ifname, const dhcp_t *dhcp) fprintf (f, "driftfile " NTPDRIFTFILE "\n"); fprintf (f, "logfile " NTPLOGFILE "\n"); fclose (f); + + exec_cmd (NTPSERVICE, NTPRESTARTARGS, NULL); return 0; } @@ -240,6 +255,7 @@ static int make_nis (const char *ifname, const dhcp_t *dhcp) fclose (f); + exec_cmd (NISSERVICE, NISRESTARTARGS, NULL); return 0; } diff --git a/configure.h b/configure.h index 59b7003d..a7e54632 100644 --- a/configure.h +++ b/configure.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/dhcp.c b/dhcp.c index 72ba37b3..3fa18bed 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/dhcp.h b/dhcp.h index 64de6161..b6fbfefc 100644 --- a/dhcp.h +++ b/dhcp.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/dhcpcd.c b/dhcpcd.c index 0eb942e3..feb03dbb 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/dhcpcd.h b/dhcpcd.h index 1d55a09f..25e7ef97 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by diff --git a/interface.c b/interface.c index 2990817a..8ee0ad5d 100644 --- a/interface.c +++ b/interface.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/interface.h b/interface.h index bc1eaefb..131b42ef 100644 --- a/interface.h +++ b/interface.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/logger.c b/logger.c index d9e3700f..303dadec 100644 --- a/logger.c +++ b/logger.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/logger.h b/logger.h index d98d5cf0..e37c8201 100644 --- a/logger.h +++ b/logger.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * diff --git a/pathnames.h b/pathnames.h index d748948a..b80a9e15 100644 --- a/pathnames.h +++ b/pathnames.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2005 - 2006 Roy Marples + * Copyright 2005 - 2007 Roy Marples * * dhcpcd is an RFC2131 compliant DHCP client daemon. * @@ -28,9 +28,17 @@ #define ETCDIR "/etc" #define RESOLVFILE ETCDIR "/resolv.conf" + #define NISFILE ETCDIR "/yp.conf" +#define NISSERVICE ETCDIR "/init.d/ypbind" +#define NISRESTARTARGS "--quiet", "conditionalrestart" + #define NTPFILE ETCDIR "/ntp.conf" #define NTPDRIFTFILE ETCDIR "/ntp.drift" +#define NTPLOGFILE "/var/log/ntp.log" +#define NTPSERVICE ETCDIR "/init.d/ntpd" +#define NTPRESTARTARGS "--quiet", "conditionalrestart" + #define DEFAULT_SCRIPT ETCDIR "/" PACKAGE ".sh" #define STATEDIR "/var" @@ -39,6 +47,4 @@ #define CONFIGDIR STATEDIR "/lib/" PACKAGE #define INFOFILE CONFIGDIR "/" PACKAGE "-%s.info" -#define NTPLOGFILE "/var/log/ntp.log" - #endif diff --git a/socket.c b/socket.c index 07909086..69c12ef2 100644 --- a/socket.c +++ b/socket.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * although a lot was lifted from udhcp * * dhcpcd is an RFC2131 compliant DHCP client daemon. diff --git a/socket.h b/socket.h index 3259b070..beb60f48 100644 --- a/socket.h +++ b/socket.h @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - - * Copyright (C) 2006 Roy Marples + * Copyright 2006-2007 Roy Marples * although a lot was lifted from udhcp * * dhcpcd is an RFC2131 compliant DHCP client daemon.