From: Roy Marples Date: Sun, 13 May 2007 17:43:56 +0000 (+0000) Subject: Ensure that dhcpcd.sh is always called. X-Git-Tag: v3.2.3~257 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00843933ff261758f2e1544c0267e5826db47ac1;p=thirdparty%2Fdhcpcd.git Ensure that dhcpcd.sh is always called. --- diff --git a/ChangeLog b/ChangeLog index 6ea14c64..222fe08b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +Ensure that dhcpcd.sh is always called. flock the pidfile and stop writing the parent pid to it so we're more robst. Enable DHCP_INFORM support via the -S option (requires -s ipaddr too) Use the DUID stored to create an RFC 4361 conformant client identifier diff --git a/client.c b/client.c index a76c654f..cf51ff4e 100644 --- a/client.c +++ b/client.c @@ -96,7 +96,7 @@ #define DROP_CONFIG { \ memset (&dhcp->address, 0, sizeof (struct in_addr)); \ - if (iface->previous_address.s_addr != 0 && ! options->persistent) \ + if (! options->persistent) \ configure (options, iface, dhcp); \ free_dhcp (dhcp); \ memset (dhcp, 0, sizeof (dhcp_t)); \ @@ -534,7 +534,8 @@ int dhcp_run (const options_t *options, int *pidfd) state = STATE_INIT; timeout = 0; xid = 0; - DROP_CONFIG; + free_dhcp (dhcp); + memset (dhcp, 0, sizeof (dhcp_t)); continue; } @@ -570,11 +571,13 @@ int dhcp_run (const options_t *options, int *pidfd) SOCKET_MODE (SOCKET_OPEN); SEND_MESSAGE (DHCP_DECLINE); SOCKET_MODE (SOCKET_CLOSED); - DROP_CONFIG; + free_dhcp (dhcp); + memset (dhcp, 0, sizeof (dhcp_t)); xid = 0; timeout = 0; state = STATE_INIT; + /* RFC 2131 says that we should wait for 10 seconds before doing anything else */ logger (LOG_INFO, "sleeping for 10 seconds"); diff --git a/configure.c b/configure.c index d121c426..8a178dd5 100644 --- a/configure.c +++ b/configure.c @@ -92,13 +92,8 @@ static void exec_script (const char *script, const char *infofile, { struct stat buf; -#ifdef ENABLE_INFO if (! script || ! infofile || ! arg) return; -#else - if (! script || ! arg) - return ; -#endif if (stat (script, &buf) < 0) { if (strcmp (script, DEFAULT_SCRIPT) != 0) @@ -106,14 +101,8 @@ static void exec_script (const char *script, const char *infofile, return; } -#ifdef ENABLE_INFO - logger (LOG_DEBUG, "exec \"%s %s %s\"", script, infofile, arg); + logger (LOG_DEBUG, "exec \"%s\" \"%s\" \"%s\"", script, infofile, arg); exec_cmd (script, infofile, arg, (char *) NULL); -#else - infofile = NULL; /* appease gcc */ - logger (LOG_DEBUG, "exec \"%s \"\" %s\"", script, arg); - exec_cmd (script, "", arg, (char *) NULL); -#endif } static int make_resolv (const char *ifname, const dhcp_t *dhcp) @@ -376,6 +365,12 @@ int configure (const options_t *options, interface_t *iface, iface->previous_mtu = iface->mtu; } +#ifdef ENABLE_INFO + /* If we haven't created an info file, do so now */ + if (! dhcp->frominfo && iface->previous_address.s_addr == 0) + write_info (iface, dhcp, options); +#endif + /* Only reset things if we had set them before */ if (iface->previous_address.s_addr != 0) { if (! options->keep_address) { @@ -384,12 +379,13 @@ int configure (const options_t *options, interface_t *iface, memset (&iface->previous_address, 0, sizeof (struct in_addr)); memset (&iface->previous_netmask, 0, sizeof (struct in_addr)); } + } - restore_resolv (iface->name); + restore_resolv (iface->name); + /* we currently don't have a resolvconf style programs for ntp/nis */ + + exec_script (options->script, iface->infofile, "down"); - /* we currently don't have a resolvconf style programs for ntp/nis */ - exec_script (options->script, iface->infofile, "down"); - } return 0; } diff --git a/dhcpcd.sh b/dhcpcd.sh index 7df0c322..46e164d8 100755 --- a/dhcpcd.sh +++ b/dhcpcd.sh @@ -21,7 +21,7 @@ hostinfo="$1" state="$2" # Reading HostInfo file for configuration parameters -. "${hostinfo}" +[ -e "${hostinfo}" ] && . "${hostinfo}" case "${state}" in up) diff --git a/info.c b/info.c index 55e79b45..014be535 100644 --- a/info.c +++ b/info.c @@ -77,9 +77,11 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp, return (false); } - fprintf (f, "IPADDR='%s'\n", inet_ntoa (dhcp->address)); - fprintf (f, "NETMASK='%s'\n", inet_ntoa (dhcp->netmask)); - fprintf (f, "BROADCAST='%s'\n", inet_ntoa (dhcp->broadcast)); + if (dhcp->address.s_addr) { + fprintf (f, "IPADDR='%s'\n", inet_ntoa (dhcp->address)); + fprintf (f, "NETMASK='%s'\n", inet_ntoa (dhcp->netmask)); + fprintf (f, "BROADCAST='%s'\n", inet_ntoa (dhcp->broadcast)); + } if (dhcp->mtu > 0) fprintf (f, "MTU='%d'\n", dhcp->mtu); @@ -163,9 +165,11 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp, if (dhcp->rootpath) fprintf (f, "ROOTPATH='%s'\n", cleanmetas (dhcp->rootpath)); - fprintf (f, "DHCPSID='%s'\n", inet_ntoa (dhcp->serveraddress)); - fprintf (f, "DHCPSNAME='%s'\n", cleanmetas (dhcp->servername)); - if (! options->doinform) { + if (dhcp->serveraddress.s_addr) + fprintf (f, "DHCPSID='%s'\n", inet_ntoa (dhcp->serveraddress)); + if (dhcp->servername[0]) + fprintf (f, "DHCPSNAME='%s'\n", cleanmetas (dhcp->servername)); + if (! options->doinform && dhcp->address.s_addr) { fprintf (f, "LEASEDFROM='%u'\n", dhcp->leasedfrom); fprintf (f, "LEASETIME='%u'\n", dhcp->leasetime); fprintf (f, "RENEWALTIME='%u'\n", dhcp->renewaltime); @@ -232,7 +236,6 @@ bool write_info(const interface_t *iface, const dhcp_t *dhcp, } #endif - fprintf (f, "\n"); fclose (f); return (true); } diff --git a/interface.c b/interface.c index bdd9a565..0f2a6fb9 100644 --- a/interface.c +++ b/interface.c @@ -289,7 +289,9 @@ interface_t *read_interface (const char *ifname, int metric) iface = xmalloc (sizeof (interface_t)); memset (iface, 0, sizeof (interface_t)); strlcpy (iface->name, ifname, IF_NAMESIZE); +#ifdef ENABLE_INFO snprintf (iface->infofile, PATH_MAX, INFOFILE, ifname); +#endif memcpy (&iface->hwaddr, hwaddr, hwlen); iface->hwlen = hwlen;