]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Re-jig the order of doing things to improve our logging.
authorRoy Marples <roy@marples.name>
Thu, 14 Aug 2008 16:16:06 +0000 (16:16 +0000)
committerRoy Marples <roy@marples.name>
Thu, 14 Aug 2008 16:16:06 +0000 (16:16 +0000)
dhcpcd.c

index 2f345ef7f8287f8a16bc992a17a50e60fda1ebc6..d895016db79487db7d09b28a803ebce64a28347d 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -803,39 +803,10 @@ main(int argc, char **argv)
        options->options &= ~DHCPCD_DAEMONISE;
 #endif
 
-       if (options->request_address.s_addr == 0 &&
-           (options->options & DHCPCD_INFORM ||
-            options->options & DHCPCD_REQUEST))
-       {
-               if (get_address(options->interface,
-                               &options->request_address,
-                               &options->request_netmask) != 1)
-               {
-                       logger(LOG_ERR, "no existing address");
-                       goto abort;
-               }
-       }
-
-       if (IN_LINKLOCAL(ntohl(options->request_address.s_addr))) {
-               logger(LOG_ERR,
-                      "you are not allowed to request a link local address");
-               goto abort;
-       }
-
        if (geteuid())
                logger(LOG_WARNING, PACKAGE " will not work correctly unless"
                       " run as root");
 
-       prefix = xmalloc(sizeof(char) * (IF_NAMESIZE + 3));
-       snprintf(prefix, IF_NAMESIZE, "%s: ", options->interface);
-       setlogprefix(prefix);
-       snprintf(options->pidfile, sizeof(options->pidfile), PIDFILE,
-                options->interface);
-       free(prefix);
-
-       chdir("/");
-       umask(022);
-
        if (options->options & DHCPCD_TEST) {
                if (options->options & DHCPCD_REQUEST ||
                    options->options & DHCPCD_INFORM) {
@@ -856,6 +827,39 @@ main(int argc, char **argv)
                }
        }
 
+       prefix = xmalloc(sizeof(char) * (IF_NAMESIZE + 3));
+       snprintf(prefix, IF_NAMESIZE, "%s: ", options->interface);
+       setlogprefix(prefix);
+       snprintf(options->pidfile, sizeof(options->pidfile), PIDFILE,
+                options->interface);
+       free(prefix);
+
+       if (options->request_address.s_addr == 0 &&
+           (options->options & DHCPCD_INFORM ||
+            options->options & DHCPCD_REQUEST))
+       {
+               errno = 0;
+               if (get_address(options->interface,
+                               &options->request_address,
+                               &options->request_netmask) != 1)
+               {
+                       if (errno)
+                               logger(LOG_ERR, "get_address: %s",
+                                      strerror(errno));
+                       else
+                               logger(LOG_ERR, "no existing address");
+                       goto abort;
+               }
+       }
+       if (IN_LINKLOCAL(ntohl(options->request_address.s_addr))) {
+               logger(LOG_ERR,
+                      "you are not allowed to request a link local address");
+               goto abort;
+       }
+
+       chdir("/");
+       umask(022);
+
        if (sig != 0 && !(options->options & DHCPCD_DAEMONISED)) {
                i = -1;
                pid = read_pid(options->pidfile);