From: Roy Marples Date: Thu, 14 Aug 2008 16:16:06 +0000 (+0000) Subject: Re-jig the order of doing things to improve our logging. X-Git-Tag: v4.0.2~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68e04b443823cfd04b747a8accd4bdea4f6f74f2;p=thirdparty%2Fdhcpcd.git Re-jig the order of doing things to improve our logging. --- diff --git a/dhcpcd.c b/dhcpcd.c index 2f345ef7..d895016d 100644 --- 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);