]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Ensure that dhcpcd.sh is always called.
authorRoy Marples <roy@marples.name>
Sun, 13 May 2007 17:43:56 +0000 (17:43 +0000)
committerRoy Marples <roy@marples.name>
Sun, 13 May 2007 17:43:56 +0000 (17:43 +0000)
ChangeLog
client.c
configure.c
dhcpcd.sh
info.c
interface.c

index 6ea14c647d9fae9b912db47209d619a5755746f8..222fe08bc588791873a7ed32cf37a1a780c7018e 100644 (file)
--- 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
index a76c654f49a9d50f8efd35a9906ab4836744088e..cf51ff4eaed0b5f2ab22035b946b280eeb486e75 100644 (file)
--- 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");
index d121c4261d10a3d98a52e554c2d2121aa900527d..8a178dd58b20c58cf120b2f62d4239349b01a074 100644 (file)
@@ -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;
        }
 
index 7df0c32207bc2092fc83942b5d1fa0fbf33e7403..46e164d8294d61e77a6bb09c6b29868bb393f002 100755 (executable)
--- 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 55e79b454c475af7b19b5ee6cfa12d208c615204..014be53550452492b9072cec13f11cc5436ff3ba 100644 (file)
--- 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);
 }
index bdd9a565e640b384007e5f75126ef2e9924b13c1..0f2a6fb939854f7a614da7cd90d0e20125efadb0 100644 (file)
@@ -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;