Module Name: src Committed By: roy Date: Fri Apr 14 09:56:32 UTC 2017
Modified Files: src/external/bsd/dhcpcd/dist/src: bpf.c dhcpcd.c if-options.c Removed Files: src/external/bsd/dhcpcd/dist/test: GNUmakefile Makefile test.c test.h test_hmac_md5.c Log Message: Sync To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/external/bsd/dhcpcd/dist/src/bpf.c \ src/external/bsd/dhcpcd/dist/src/dhcpcd.c \ src/external/bsd/dhcpcd/dist/src/if-options.c cvs rdiff -u -r1.1.1.1 -r0 src/external/bsd/dhcpcd/dist/test/GNUmakefile \ src/external/bsd/dhcpcd/dist/test/Makefile \ src/external/bsd/dhcpcd/dist/test/test.c \ src/external/bsd/dhcpcd/dist/test/test.h \ src/external/bsd/dhcpcd/dist/test/test_hmac_md5.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/dhcpcd/dist/src/bpf.c diff -u src/external/bsd/dhcpcd/dist/src/bpf.c:1.2 src/external/bsd/dhcpcd/dist/src/bpf.c:1.3 --- src/external/bsd/dhcpcd/dist/src/bpf.c:1.2 Mon Apr 3 00:42:20 2017 +++ src/external/bsd/dhcpcd/dist/src/bpf.c Fri Apr 14 09:56:32 2017 @@ -48,13 +48,13 @@ #include <stddef.h> #include <stdlib.h> #include <string.h> -#include <syslog.h> #include "common.h" #include "arp.h" #include "bpf.h" #include "dhcp.h" #include "if.h" +#include "logerr.h" #define ARP_ADDRS_MAX 3 @@ -150,7 +150,7 @@ bpf_open(struct interface *ifp, int (*fi goto eexit; if (pv.bv_major != BPF_MAJOR_VERSION || pv.bv_minor < BPF_MINOR_VERSION) { - syslog(LOG_ERR, "BPF version mismatch - recompile"); + logerrx("BPF version mismatch - recompile"); goto eexit; } @@ -174,7 +174,6 @@ bpf_open(struct interface *ifp, int (*fi goto eexit; state->buffer = nb; state->buffer_size = buf_len; - state->buffer_len = state->buffer_pos = 0; } #ifdef BIOCIMMEDIATE @@ -222,8 +221,6 @@ bpf_read(struct interface *ifp, int fd, bytes = -1; memcpy(&packet, state->buffer + state->buffer_pos, sizeof(packet)); - if (packet.bh_caplen != packet.bh_datalen) - goto next; /* Incomplete packet, drop. */ if (state->buffer_pos + packet.bh_caplen + packet.bh_hdrlen > state->buffer_len) goto next; /* Packet beyond buffer, drop. */ @@ -288,6 +285,16 @@ bpf_send(const struct interface *ifp, in } #endif +int +bpf_close(struct interface *ifp, int fd) +{ + struct ipv4_state *state = IPV4_STATE(ifp); + + /* Rewind the buffer on closing. */ + state->buffer_len = state->buffer_pos = 0; + return close(fd); +} + static unsigned int bpf_cmp_hwaddr(struct bpf_insn *bpf, size_t bpf_len, size_t off, bool equal, uint8_t *hwaddr, size_t hwaddr_len) @@ -428,6 +435,7 @@ bpf_arp(struct interface *ifp, int fd) struct bpf_insn bpf[3+ bpf_arp_filter_len + bpf_arp_hw + bpf_arp_extra]; struct bpf_insn *bp; struct iarp_state *state; + uint16_t arp_len; if (fd == -1) return 0; @@ -438,6 +446,7 @@ bpf_arp(struct interface *ifp, int fd) case ARPHRD_ETHER: memcpy(bp, bpf_arp_ether, sizeof(bpf_arp_ether)); bp += bpf_arp_ether_len; + arp_len = sizeof(struct ether_header)+sizeof(struct ether_arp); break; default: errno = EINVAL; @@ -465,13 +474,13 @@ bpf_arp(struct interface *ifp, int fd) TAILQ_FOREACH(astate, &state->arp_states, next) { if (++naddrs > ARP_ADDRS_MAX) { errno = ENOBUFS; - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); break; } BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K, htonl(astate->addr.s_addr), 0, 1); bp++; - BPF_SET_STMT(bp, BPF_RET + BPF_K, BPF_WHOLEPACKET); + BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len); bp++; } @@ -496,8 +505,7 @@ bpf_arp(struct interface *ifp, int fd) BPF_SET_JUMP(bp, BPF_JMP + BPF_JEQ + BPF_K, htonl(astate->addr.s_addr), 0, 1); bp++; - BPF_SET_STMT(bp, BPF_RET + BPF_K, - BPF_WHOLEPACKET); + BPF_SET_STMT(bp, BPF_RET + BPF_K, arp_len); bp++; } Index: src/external/bsd/dhcpcd/dist/src/dhcpcd.c diff -u src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.2 src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.3 --- src/external/bsd/dhcpcd/dist/src/dhcpcd.c:1.2 Thu Apr 6 14:00:34 2017 +++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c Fri Apr 14 09:56:32 2017 @@ -44,7 +44,6 @@ const char dhcpcd_copyright[] = "Copyrig #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <syslog.h> #include <unistd.h> #include <time.h> @@ -63,6 +62,7 @@ const char dhcpcd_copyright[] = "Copyrig #include "ipv4ll.h" #include "ipv6.h" #include "ipv6nd.h" +#include "logerr.h" #include "script.h" #ifdef HAVE_UTIL_H @@ -173,7 +173,7 @@ handle_exit_timeout(void *arg) struct dhcpcd_ctx *ctx; ctx = arg; - syslog(LOG_ERR, "timed out"); + logerrx("timed out"); if (!(ctx->options & DHCPCD_MASTER)) { eloop_exit(ctx->eloop, EXIT_FAILURE); return; @@ -258,16 +258,14 @@ dhcpcd_ipwaited(struct dhcpcd_ctx *ctx) TAILQ_FOREACH(ifp, ctx->ifaces, next) { if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) { - syslog(LOG_DEBUG, - "%s: waiting for an %s address", + logdebugx("%s: waiting for an %s address", ifp->name, dhcpcd_af(af)); return 0; } } if ((af = dhcpcd_afwaiting(ctx)) != AF_MAX) { - syslog(LOG_DEBUG, - "waiting for an %s address", + logdebugx("waiting for an %s address", dhcpcd_af(af)); return 0; } @@ -296,7 +294,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) } if (ctx->options & DHCPCD_ONESHOT) { - syslog(LOG_INFO, "exiting due to oneshot"); + loginfox("exiting due to oneshot"); eloop_exit(ctx->eloop, EXIT_SUCCESS); return 0; } @@ -305,11 +303,11 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) if (ctx->options & DHCPCD_DAEMONISED || !(ctx->options & DHCPCD_DAEMONISE)) return 0; - syslog(LOG_DEBUG, "forking to background"); + logdebugx("forking to background"); /* Setup a signal pipe so parent knows when to exit. */ if (pipe(sidpipe) == -1) { - syslog(LOG_ERR, "pipe: %m"); + logerr("%s: pipe", __func__); return 0; } @@ -322,22 +320,21 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) switch (pid = fork()) { case -1: - syslog(LOG_ERR, "fork: %m"); + logerr("%s: fork", __func__); return 0; case 0: if ((lpid = pidfile_lock(ctx->pidfile)) != 0) - syslog(LOG_ERR, "%s: pidfile_lock %d: %m", - __func__, lpid); + logerr("%s: pidfile_lock %d", __func__, lpid); setsid(); /* Notify parent it's safe to exit as we've detached. */ close(sidpipe[0]); if (write(sidpipe[1], &buf, 1) == -1) - syslog(LOG_ERR, "failed to notify parent: %m"); + logerr("%s: write", __func__); close(sidpipe[1]); /* Some polling methods don't survive after forking, * so ensure we can requeue all our events. */ if (eloop_requeue(ctx->eloop) == -1) { - syslog(LOG_ERR, "eloop_requeue: %m"); + logerr("%s: eloop_requeue", __func__); eloop_exit(ctx->eloop, EXIT_FAILURE); } if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { @@ -352,9 +349,9 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) /* Wait for child to detach */ close(sidpipe[1]); if (read(sidpipe[0], &buf, 1) == -1) - syslog(LOG_ERR, "failed to read child: %m"); + logerr("%s: read", __func__); close(sidpipe[0]); - syslog(LOG_INFO, "forked to background, child pid %d", pid); + loginfox("forked to background, child pid %d", pid); ctx->options |= DHCPCD_FORKED; eloop_exit(ctx->eloop, EXIT_SUCCESS); return pid; @@ -380,7 +377,7 @@ stop_interface(struct interface *ifp) struct dhcpcd_ctx *ctx; ctx = ifp->ctx; - syslog(LOG_INFO, "%s: removing interface", ifp->name); + loginfox("%s: removing interface", ifp->name); ifp->options->options |= DHCPCD_STOPPING; dhcpcd_drop(ifp, 1); @@ -518,7 +515,7 @@ configure_interface1(struct interface *i { ifo->ia = malloc(sizeof(*ifo->ia)); if (ifo->ia == NULL) - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); else { ifo->ia_len = 1; ifo->ia->ia_type = D6_OPTION_IA_NA; @@ -553,20 +550,19 @@ dhcpcd_selectprofile(struct interface *i r = print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid, ifp->ssid_len); if (r == -1) { - syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__); + logerr(__func__); pssid[0] = '\0'; } } else pssid[0] = '\0'; ifo = read_config(ifp->ctx, ifp->name, pssid, profile); if (ifo == NULL) { - syslog(LOG_DEBUG, "%s: no profile %s", ifp->name, profile); + logdebugx("%s: no profile %s", ifp->name, profile); return -1; } if (profile != NULL) { strlcpy(ifp->profile, profile, sizeof(ifp->profile)); - syslog(LOG_INFO, "%s: selected profile %s", - ifp->name, profile); + loginfox("%s: selected profile %s", ifp->name, profile); } else *ifp->profile = '\0'; @@ -599,8 +595,8 @@ configure_interface(struct interface *if /* If the mtime has changed drop any old lease */ if (old != 0 && ifp->options->mtime != old) { - syslog(LOG_WARNING, - "%s: confile file changed, expiring leases", ifp->name); + logwarnx("%s: confile file changed, expiring leases", + ifp->name); dhcpcd_drop(ifp, 0); } } @@ -631,7 +627,7 @@ dhcpcd_initstate2(struct interface *ifp, if (options) { if ((ifo = default_config(ifp->ctx)) == NULL) { - syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__); + logerr(__func__); return; } ifo->options |= options; @@ -641,7 +637,7 @@ dhcpcd_initstate2(struct interface *ifp, ifo = ifp->options; if (ifo->options & DHCPCD_IPV6 && ipv6_init(ifp->ctx) == -1) { - syslog(LOG_ERR, "ipv6_init: %m"); + logerr(__func__); ifo->options &= ~DHCPCD_IPV6; } } @@ -700,11 +696,11 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx * if (carrier == LINK_UNKNOWN) { if (errno != ENOTTY) /* For example a PPP link on BSD */ - syslog(LOG_ERR, "%s: carrier_status: %m", ifname); + logerr("%s: %s", ifp->name, __func__); } else if (carrier == LINK_DOWN || (ifp->flags & IFF_UP) == 0) { if (ifp->carrier != LINK_DOWN) { if (ifp->carrier == LINK_UP) - syslog(LOG_INFO, "%s: carrier lost", ifp->name); + loginfox("%s: carrier lost", ifp->name); ifp->carrier = LINK_DOWN; script_runreason(ifp, "NOCARRIER"); #ifdef NOCARRIER_PRESERVE_IP @@ -719,7 +715,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx * } } else if (carrier == LINK_UP && ifp->flags & IFF_UP) { if (ifp->carrier != LINK_UP) { - syslog(LOG_INFO, "%s: carrier acquired", ifp->name); + loginfox("%s: carrier acquired", ifp->name); ifp->carrier = LINK_UP; #if !defined(__linux__) && !defined(__NetBSD__) /* BSD does not emit RTM_NEWADDR or RTM_CHGADDR when the @@ -779,8 +775,7 @@ warn_iaid_conflict(struct interface *ifp /* This is only a problem if the interfaces are on the same network. */ if (ifn) - syslog(LOG_ERR, - "%s: IAID conflicts with one assigned to %s", + logerr("%s: IAID conflicts with one assigned to %s", ifp->name, ifn->name); } @@ -799,7 +794,7 @@ dhcpcd_startinterface(void *arg) case LINK_UP: break; case LINK_DOWN: - syslog(LOG_INFO, "%s: waiting for carrier", ifp->name); + loginfox("%s: waiting for carrier", ifp->name); return; case LINK_UNKNOWN: /* No media state available. @@ -821,7 +816,7 @@ dhcpcd_startinterface(void *arg) if (ifp->ctx->duid == NULL) { if (duid_init(ifp) == 0) return; - syslog(LOG_INFO, "DUID %s", + loginfox("DUID %s", hwaddr_ntoa(ifp->ctx->duid, ifp->ctx->duid_len, buf, sizeof(buf))); @@ -830,7 +825,7 @@ dhcpcd_startinterface(void *arg) if (ifo->options & (DHCPCD_DUID | DHCPCD_IPV6)) { /* Report IAIDs */ - syslog(LOG_INFO, "%s: IAID %s", ifp->name, + loginfox("%s: IAID %s", ifp->name, hwaddr_ntoa(ifo->iaid, sizeof(ifo->iaid), buf, sizeof(buf))); warn_iaid_conflict(ifp, ifo->iaid); @@ -838,7 +833,7 @@ dhcpcd_startinterface(void *arg) if (memcmp(ifo->iaid, ifo->ia[i].iaid, sizeof(ifo->iaid))) { - syslog(LOG_INFO, "%s: IAID %s", + loginfox("%s: IAID %s", ifp->name, hwaddr_ntoa(ifo->ia[i].iaid, sizeof(ifo->ia[i].iaid), buf, sizeof(buf))); @@ -848,7 +843,7 @@ dhcpcd_startinterface(void *arg) } if (ifo->options & DHCPCD_IPV6 && ipv6_start(ifp) == -1) { - syslog(LOG_ERR, "%s: ipv6_start: %m", ifp->name); + logerr("%s: ipv6_start", ifp->name); ifo->options &= ~DHCPCD_IPV6; } if (ifo->options & DHCPCD_IPV6) { @@ -886,8 +881,7 @@ dhcpcd_startinterface(void *arg) #endif } if (nolease == -1) - syslog(LOG_ERR, "%s: dhcp6_start: %m", - ifp->name); + logerr("%s: dhcp6_start", ifp->name); } } @@ -908,7 +902,7 @@ dhcpcd_prestartinterface(void *arg) if ((!(ifp->ctx->options & DHCPCD_MASTER) || ifp->options->options & DHCPCD_IF_UP) && if_up(ifp) == -1) - syslog(LOG_ERR, "%s: if_up: %m", ifp->name); + logerr("%s: %s", __func__, ifp->name); if (ifp->options->options & DHCPCD_LINK && ifp->carrier == LINK_UNKNOWN) @@ -920,8 +914,7 @@ dhcpcd_prestartinterface(void *arg) ifp->flags, ifp->name); return; } - syslog(LOG_INFO, - "%s: unknown carrier, waiting for interface flags", + loginfox("%s: unknown carrier, waiting for interface flags", ifp->name); } @@ -966,7 +959,7 @@ dhcpcd_handlelink(void *arg) ctx = arg; if (if_handlelink(ctx) == -1) { - syslog(LOG_ERR, "if_handlelink: %m"); + logerr(__func__); eloop_event_delete(ctx->eloop, ctx->link_fd); close(ctx->link_fd); ctx->link_fd = -1; @@ -990,8 +983,7 @@ dhcpcd_handleinterface(void *arg, int ac return -1; } if (ifp->active) { - syslog(LOG_DEBUG, "%s: interface departed", - ifp->name); + logdebugx("%s: interface departed", ifp->name); ifp->options->options |= DHCPCD_DEPARTED; stop_interface(ifp); } @@ -1003,7 +995,7 @@ dhcpcd_handleinterface(void *arg, int ac i = -1; ifs = if_discover(ctx, -1, UNCONST(argv)); if (ifs == NULL) { - syslog(LOG_ERR, "%s: if_discover: %m", __func__); + logerr(__func__); return -1; } TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) { @@ -1026,8 +1018,7 @@ dhcpcd_handleinterface(void *arg, int ac iff = if_find(ctx->ifaces, ifp->name); if (iff) { if (iff->active) - syslog(LOG_DEBUG, "%s: interface updated", - iff->name); + logdebugx("%s: interface updated", iff->name); /* The flags and hwaddr could have changed */ iff->flags = ifp->flags; iff->hwlen = ifp->hwlen; @@ -1038,7 +1029,7 @@ dhcpcd_handleinterface(void *arg, int ac TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next); if (!ifp->active) continue; - syslog(LOG_DEBUG, "%s: interface added", ifp->name); + logdebugx("%s: interface added", ifp->name); dhcpcd_initstate(ifp, 0); run_preinit(ifp); iff = ifp; @@ -1072,14 +1063,14 @@ dhcpcd_handlehwaddr(struct dhcpcd_ctx *c if (hwlen > sizeof(ifp->hwaddr)) { errno = ENOBUFS; - syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__); + logerr("%s: %s", __func__, ifp->name); return; } if (ifp->hwlen == hwlen && memcmp(ifp->hwaddr, hwaddr, hwlen) == 0) return; - syslog(LOG_INFO, "%s: new hardware address: %s", ifp->name, + loginfox("%s: new hardware address: %s", ifp->name, hwaddr_ntoa(hwaddr, hwlen, buf, sizeof(buf))); ifp->hwlen = hwlen; memcpy(ifp->hwaddr, hwaddr, hwlen); @@ -1202,19 +1193,19 @@ signal_cb(int sig, void *arg) exit_code = EXIT_FAILURE; switch (sig) { case SIGINT: - syslog(LOG_INFO, sigmsg, "SIGINT", "stopping"); + loginfox(sigmsg, "SIGINT", "stopping"); break; case SIGTERM: - syslog(LOG_INFO, sigmsg, "SIGTERM", "stopping"); + loginfox(sigmsg, "SIGTERM", "stopping"); exit_code = EXIT_SUCCESS; break; case SIGALRM: - syslog(LOG_INFO, sigmsg, "SIGALRM", "releasing"); + loginfox(sigmsg, "SIGALRM", "releasing"); opts |= DHCPCD_RELEASE; exit_code = EXIT_SUCCESS; break; case SIGHUP: - syslog(LOG_INFO, sigmsg, "SIGHUP", "rebinding"); + loginfox(sigmsg, "SIGHUP", "rebinding"); reload_config(ctx); /* Preserve any options passed on the commandline * when we were started. */ @@ -1222,20 +1213,20 @@ signal_cb(int sig, void *arg) ctx->argc - ctx->ifc); return; case SIGUSR1: - syslog(LOG_INFO, sigmsg, "SIGUSR1", "renewing"); + loginfox(sigmsg, "SIGUSR1", "renewing"); dhcpcd_renew(ctx); return; case SIGUSR2: - closelog(); - openlog(NULL, ctx->log_opts, LOG_DAEMON); - syslog(LOG_INFO, sigmsg, "SIGUSR2", "reopened syslog"); + loginfox(sigmsg, "SIGUSR2", "reopening log"); + logclose(); + if (logopen(ctx->logfile) == -1) + logerr(__func__); return; case SIGPIPE: - syslog(LOG_WARNING, "received SIGPIPE"); + logwarnx("received SIGPIPE"); return; default: - syslog(LOG_ERR, "received signal %d, " - "but don't know what to do with it", + logerrx("received signal %d but don't know what to do with it", sig); return; } @@ -1276,7 +1267,7 @@ dhcpcd_getinterfaces(void *arg) if (!ifp->active) continue; if (send_interface(fd, ifp) == -1) - syslog(LOG_ERR, "send_interface %d: %m", fd->fd); + logerr(__func__); } } @@ -1331,7 +1322,7 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx *p++ = ' '; } *--p = '\0'; - syslog(LOG_INFO, "control command: %s", tmp); + loginfox("control command: %s", tmp); free(tmp); optind = 0; @@ -1408,6 +1399,7 @@ main(int argc, char **argv) struct interface *ifp; uint16_t family = 0; int opt, oi = 0, i; + unsigned int logopts; time_t t; ssize_t len; #if defined(USE_SIGNALS) || !defined(THERE_IS_NO_FORK) @@ -1469,13 +1461,7 @@ main(int argc, char **argv) #ifdef INET ctx.udp_fd = -1; #endif - ctx.log_opts = LOG_PID; -#ifdef LOG_PERROR - ctx.log_opts |= LOG_PERROR; -#endif -#ifdef LOG_PTRIM - ctx.log_opts |= LOG_PTRIM; -#endif + logopts = LOGERR_ERR|LOGERR_LOG|LOGERR_LOG_DATE|LOGERR_LOG_PID; i = 0; while ((opt = getopt_long(argc, argv, ctx.options & DHCPCD_PRINT_PIDFILE ? NOERR_IF_OPTS : IF_OPTS, @@ -1491,6 +1477,10 @@ main(int argc, char **argv) case 'f': ctx.cffile = optarg; break; + case 'j': + free(ctx.logfile); + ctx.logfile = strdup(optarg); + break; #ifdef USE_SIGNALS case 'k': sig = SIGALRM; @@ -1507,10 +1497,8 @@ main(int argc, char **argv) i = 4; break; case 'q': -#ifdef LOG_PERROR - ctx.log_opts &= ~LOG_PERROR; + logopts |= LOGERR_QUIET; break; -#endif case 'x': sig = SIGTERM; siga = "TERM"; @@ -1525,9 +1513,7 @@ main(int argc, char **argv) break; case 'T': i = 1; -#ifdef LOG_NLOG - ctx.log_opts |= LOG_NLOG; -#endif + logopts &= ~LOGERR_LOG; break; case 'U': i = 3; @@ -1543,8 +1529,8 @@ main(int argc, char **argv) } } - openlog(NULL, ctx.log_opts, LOG_DAEMON); - setlogmask(LOG_UPTO(LOG_INFO)); + logsetopts(logopts); + logopen(ctx.logfile); ctx.argv = argv; ctx.argc = argc; @@ -1609,7 +1595,7 @@ main(int argc, char **argv) #endif if (ctx.options & DHCPCD_DEBUG) - setlogmask(LOG_UPTO(LOG_DEBUG)); + logsetopts(logopts | LOGERR_DEBUG); if (!(ctx.options & (DHCPCD_TEST | DHCPCD_DUMPLEASE))) { printpidfile: @@ -1619,8 +1605,7 @@ printpidfile: const char *per; if (strlen(argv[optind]) > IF_NAMESIZE) { - syslog(LOG_ERR, - "%s: interface name too long", + logerrx("%s: interface name too long", argv[optind]); goto exit_failure; } @@ -1649,21 +1634,27 @@ printpidfile: } if (chdir("/") == -1) - syslog(LOG_ERR, "chdir `/': %m"); + logerr("%s: chdir `/'", __func__); /* Freeing allocated addresses from dumping leases can trigger * eloop removals as well, so init here. */ if ((ctx.eloop = eloop_new()) == NULL) { - syslog(LOG_ERR, "%s: eloop_init: %m", __func__); + logerr("%s: eloop_init", __func__); goto exit_failure; } /* Open our persistent sockets. * This is needed early for dumping leases on valid interfaces. */ - if (if_opensockets(&ctx) == -1) { - syslog(LOG_ERR, "if_opensockets: %m"); - goto exit_failure; +#ifdef USE_SIGNALS + if (sig == 0) { +#endif + if (if_opensockets(&ctx) == -1) { + logerr("%s: if_opensockets", __func__); + goto exit_failure; + } +#ifdef USE_SIGNALS } +#endif if (ctx.options & DHCPCD_DUMPLEASE) { if (optind != argc) { @@ -1676,14 +1667,14 @@ printpidfile: TAILQ_INIT(ctx.ifaces); } if (ctx.ifaces == NULL) { - syslog(LOG_ERR, "if_discover: %m"); + logerr("%s: if_discover", __func__); goto exit_failure; } ifp = if_find(ctx.ifaces, argv[optind]); if (ifp == NULL) { ifp = calloc(1, sizeof(*ifp)); if (ifp == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); goto exit_failure; } if (optind != argc) @@ -1727,20 +1718,19 @@ printpidfile: if (ctx.control_fd == -1) ctx.control_fd = control_open(NULL); if (ctx.control_fd != -1) { - syslog(LOG_INFO, - "sending commands to master dhcpcd process"); + loginfox("sending commands to master dhcpcd process"); len = control_send(&ctx, argc, argv); control_close(&ctx); if (len > 0) { - syslog(LOG_DEBUG, "send OK"); + logdebugx("send OK"); goto exit_success; } else { - syslog(LOG_ERR, "failed to send commands"); + logerr("%s: control_send", __func__); goto exit_failure; } } else { if (errno != ENOENT) - syslog(LOG_ERR, "control_open: %m"); + logerr("%s: control_open", __func__); } #ifdef USE_SIGNALS } @@ -1750,13 +1740,12 @@ printpidfile: if (sig != 0) { pid = pidfile_read(ctx.pidfile); if (pid != 0 && pid != -1) - syslog(LOG_INFO, "sending signal %s to pid %d", - siga, pid); + loginfox("sending signal %s to pid %d", siga, pid); if (pid == 0 || pid == -1 || kill(pid, sig) != 0) { if (sig != SIGHUP && sig != SIGUSR1 && errno != EPERM) - syslog(LOG_ERR, ""PACKAGE" not running"); + logerrx(PACKAGE" not running"); if (pid != 0 && pid != -1 && errno != ESRCH) { - syslog(LOG_ERR, "kill: %m"); + logerr("kill"); goto exit_failure; } unlink(ctx.pidfile); @@ -1768,7 +1757,7 @@ printpidfile: if (sig == SIGHUP || sig == SIGUSR1) goto exit_success; /* Spin until it exits */ - syslog(LOG_INFO, "waiting for pid %d to exit", pid); + loginfox("waiting for pid %d to exit", pid); ts.tv_sec = 0; ts.tv_nsec = 100000000; /* 10th of a second */ for(i = 0; i < 100; i++) { @@ -1776,7 +1765,7 @@ printpidfile: if (pidfile_read(ctx.pidfile) == -1) goto exit_success; } - syslog(LOG_ERR, "pid %d failed to exit", pid); + logerrx("pid %d failed to exit", pid); goto exit_failure; } } @@ -1784,16 +1773,15 @@ printpidfile: if (!(ctx.options & DHCPCD_TEST)) { /* Ensure we have the needed directories */ if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST) - syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR); + logerr("%s: mkdir `%s'", __func__, RUNDIR); if (mkdir(DBDIR, 0755) == -1 && errno != EEXIST) - syslog(LOG_ERR, "mkdir `%s': %m", DBDIR); + logerr("%s: mkdir `%s'", __func__, DBDIR); if ((pid = pidfile_lock(ctx.pidfile)) != 0) { if (pid == -1) - syslog(LOG_ERR, "%s: pidfile_lock: %m", - __func__); + logerr("%s: pidfile_lock", __func__); else - syslog(LOG_ERR, ""PACKAGE + logerrx(PACKAGE " already running on pid %d (%s)", pid, ctx.pidfile); goto exit_failure; @@ -1802,30 +1790,30 @@ printpidfile: if (ctx.options & DHCPCD_MASTER) { if (control_start(&ctx, NULL) == -1) - syslog(LOG_ERR, "control_start: %m"); + logerr("%s: control_start", __func__); } #else if (control_start(&ctx, ctx.options & DHCPCD_MASTER ? NULL : argv[optind]) == -1) { - syslog(LOG_ERR, "control_start: %m"); + logerr("%s: control_start", __func__); goto exit_failure; } #endif - syslog(LOG_DEBUG, PACKAGE "-" VERSION " starting"); + logdebugx(PACKAGE "-" VERSION " starting"); ctx.options |= DHCPCD_STARTED; #ifdef USE_SIGNALS if (eloop_signal_set_cb(ctx.eloop, dhcpcd_signals, dhcpcd_signals_len, signal_cb, &ctx) == -1) { - syslog(LOG_ERR, "eloop_signal_set_cb: %m"); + logerr("%s: eloop_signal_set_cb", __func__); goto exit_failure; } /* Save signal mask, block and redirect signals to our handler */ if (eloop_signal_mask(ctx.eloop, &ctx.sigset) == -1) { - syslog(LOG_ERR, "eloop_signal_mask: %m"); + logerr("%s: eloop_signal_mask", __func__); goto exit_failure; } #endif @@ -1847,13 +1835,13 @@ printpidfile: ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv); if (ctx.ifaces == NULL) { - syslog(LOG_ERR, "if_discover: %m"); + logerr("%s: if_discover", __func__); goto exit_failure; } for (i = 0; i < ctx.ifc; i++) { if ((ifp = if_find(ctx.ifaces, ctx.ifv[i])) == NULL || !ifp->active) - syslog(LOG_ERR, "%s: interface not found or invalid", + logerrx("%s: interface not found or invalid", ctx.ifv[i]); } TAILQ_FOREACH(ifp, ctx.ifaces, next) { @@ -1861,15 +1849,16 @@ printpidfile: break; } if (ifp == NULL) { - if (ctx.ifc == 0) - syslog(ctx.options & DHCPCD_INACTIVE ? - LOG_DEBUG : LOG_ERR, - "no valid interfaces found"); - else + if (ctx.ifc == 0) { + logfunc_t *logfunc; + + logfunc = ctx.options & DHCPCD_INACTIVE ? + logdebugx : logerrx; + logfunc("no valid interfaces found"); + } else goto exit_failure; if (!(ctx.options & DHCPCD_LINK)) { - syslog(LOG_ERR, - "aborting as link detection is disabled"); + logerr("aborting as link detection is disabled"); goto exit_failure; } } @@ -1910,9 +1899,11 @@ printpidfile: ctx.options & DHCPCD_LINK && !(ctx.options & DHCPCD_WAITIP)) { - syslog(ctx.options & DHCPCD_INACTIVE ? - LOG_DEBUG : LOG_WARNING, - "no interfaces have a carrier"); + logfunc_t *logfunc; + + logfunc = ctx.options & DHCPCD_INACTIVE ? + logdebugx : logwarnx; + logfunc("no interfaces have a carrier"); if (dhcpcd_daemonise(&ctx)) goto exit_success; } else if (t > 0 && @@ -1935,7 +1926,7 @@ printpidfile: i = eloop_start(ctx.eloop, &ctx.sigset); if (i < 0) { - syslog(LOG_ERR, "eloop_start: %m"); + logerr("%s: eloop_start", __func__); goto exit_failure; } goto exit1; @@ -1949,7 +1940,7 @@ exit_failure: exit1: if (control_stop(&ctx) == -1) - syslog(LOG_ERR, "control_stop: %m:"); + logerr("%s: control_stop", __func__); /* Free memory and close fd's */ if (ctx.ifaces) { while ((ifp = TAILQ_FIRST(ctx.ifaces))) { @@ -1973,8 +1964,9 @@ exit1: free(ctx.iov[0].iov_base); if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED)) - syslog(LOG_INFO, PACKAGE " exited"); - closelog(); + loginfox(PACKAGE " exited"); + logclose(); + free(ctx.logfile); #ifdef USE_SIGNALS if (ctx.options & DHCPCD_FORKED) _exit(i); /* so atexit won't remove our pidfile */ Index: src/external/bsd/dhcpcd/dist/src/if-options.c diff -u src/external/bsd/dhcpcd/dist/src/if-options.c:1.2 src/external/bsd/dhcpcd/dist/src/if-options.c:1.3 --- src/external/bsd/dhcpcd/dist/src/if-options.c:1.2 Thu Apr 6 14:01:27 2017 +++ src/external/bsd/dhcpcd/dist/src/if-options.c Fri Apr 14 09:56:32 2017 @@ -41,7 +41,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <syslog.h> #include <unistd.h> #include <time.h> @@ -53,6 +52,7 @@ #include "if.h" #include "if-options.h" #include "ipv4.h" +#include "logerr.h" #include "sa.h" /* These options only make sense in the config file, so don't use any @@ -115,6 +115,7 @@ const struct option cf_options[] = { {"reconfigure", no_argument, NULL, 'g'}, {"hostname", optional_argument, NULL, 'h'}, {"vendorclassid", optional_argument, NULL, 'i'}, + {"logfile", required_argument, NULL, 'j'}, {"release", no_argument, NULL, 'k'}, {"leasetime", required_argument, NULL, 'l'}, {"metric", required_argument, NULL, 'm'}, @@ -215,12 +216,12 @@ add_environ(struct if_options *ifo, cons match = strdup(value); if (match == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return NULL; } p = strchr(match, '='); if (p == NULL) { - syslog(LOG_ERR, "%s: no assignment: %s", __func__, value); + logerrx("%s: no assignment: %s", __func__, value); free(match); return NULL; } @@ -232,7 +233,7 @@ add_environ(struct if_options *ifo, cons if (uniq) { n = strdup(value); if (n == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(match); return NULL; } @@ -244,7 +245,7 @@ add_environ(struct if_options *ifo, cons lv = strlen(p); n = realloc(lst[i], l + lv + 2); if (n == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(match); return NULL; } @@ -262,12 +263,12 @@ add_environ(struct if_options *ifo, cons free(match); n = strdup(value); if (n == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return NULL; } - newlist = realloc(lst, sizeof(char *) * (i + 2)); + newlist = reallocarray(lst, i + 2, sizeof(char *)); if (newlist == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(n); return NULL; } @@ -440,20 +441,20 @@ splitv(int *argc, char **argv, const cha char *o = strdup(arg), *p, *t, *nt; if (o == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return v; } p = o; while ((t = strsep(&p, ", "))) { nt = strdup(t); if (nt == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(o); return v; } - n = realloc(v, sizeof(char *) * ((size_t)(*argc) + 1)); + n = reallocarray(v, (size_t)(*argc) + 1, sizeof(char *)); if (n == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(o); free(nt); return v; @@ -487,13 +488,13 @@ parse_addr(struct in_addr *addr, struct if (e != 0 || (net != NULL && inet_cidrtoaddr((int)i, net) != 0)) { - syslog(LOG_ERR, "`%s' is not a valid CIDR", p); + logerrx("`%s' is not a valid CIDR", p); return -1; } } if (addr != NULL && inet_aton(arg, addr) == 0) { - syslog(LOG_ERR, "`%s' is not a valid IP address", arg); + logerrx("`%s' is not a valid IP address", arg); return -1; } if (p != NULL) @@ -508,7 +509,7 @@ parse_addr(__unused struct in_addr *addr __unused const char *arg) { - syslog(LOG_ERR, "No IPv4 support"); + logerrx("No IPv4 support"); return -1; } #endif @@ -705,7 +706,7 @@ parse_option(struct dhcpcd_ctx *ctx, con free(ifo->script); ifo->script = strdup(arg); if (ifo->script == NULL) - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); break; case 'd': ifo->options |= DHCPCD_DEBUG; @@ -721,11 +722,11 @@ parse_option(struct dhcpcd_ctx *ctx, con } s = parse_string(ifo->hostname, HOSTNAME_MAX_LEN, arg); if (s == -1) { - syslog(LOG_ERR, "hostname: %m"); + logerr("%s: hostname", __func__); return -1; } if (s != 0 && ifo->hostname[0] == '.') { - syslog(LOG_ERR, "hostname cannot begin with ."); + logerrx("hostname cannot begin with ."); return -1; } ifo->hostname[s] = '\0'; @@ -741,11 +742,21 @@ parse_option(struct dhcpcd_ctx *ctx, con else s = 0; if (s == -1) { - syslog(LOG_ERR, "vendorclassid: %m"); + logerr("vendorclassid"); return -1; } *ifo->vendorclassid = (uint8_t)s; break; + case 'j': + ARG_REQUIRED; + /* per interface logging is not supported + * don't want to overide the commandline */ + if (ifname == NULL && ctx->logfile == NULL) { + logclose(); + ctx->logfile = strdup(arg); + logopen(ctx->logfile); + } + break; case 'k': ifo->options |= DHCPCD_RELEASE; break; @@ -754,7 +765,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ifo->leasetime = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); if (e) { - syslog(LOG_ERR, "failed to convert leasetime %s", arg); + logerrx("failed to convert leasetime %s", arg); return -1; } break; @@ -762,7 +773,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ARG_REQUIRED; ifo->metric = (int)strtoi(arg, NULL, 0, 0, INT32_MAX, &e); if (e) { - syslog(LOG_ERR, "failed to convert metric %s", arg); + logerrx("failed to convert metric %s", arg); return -1; } break; @@ -774,7 +785,7 @@ parse_option(struct dhcpcd_ctx *ctx, con make_option_mask(d, dl, od, odl, no, arg, -1) != 0 || make_option_mask(d, dl, od, odl, reject, arg, -1) != 0) { - syslog(LOG_ERR, "unknown option `%s'", arg); + logerrx("unknown option `%s'", arg); return -1; } break; @@ -786,7 +797,7 @@ parse_option(struct dhcpcd_ctx *ctx, con make_option_mask(d, dl, od, odl, request, arg, -1) != 0 || make_option_mask(d, dl, od, odl, require, arg, -1) != 0) { - syslog(LOG_ERR, "unknown option `%s'", arg); + logerrx("unknown option `%s'", arg); return -1; } break; @@ -818,7 +829,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ARG_REQUIRED; ifo->timeout = (time_t)strtoi(arg, NULL, 0, 0, INT32_MAX, &e); if (e) { - syslog(LOG_ERR, "failed to convert timeout"); + logerrx("failed to convert timeout %s", arg); return -1; } break; @@ -827,7 +838,7 @@ parse_option(struct dhcpcd_ctx *ctx, con s = parse_string((char *)ifo->userclass + ifo->userclass[0] + 2, (size_t)s, arg); if (s == -1) { - syslog(LOG_ERR, "userclass: %m"); + logerr("userclass"); return -1; } if (s != 0) { @@ -839,7 +850,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ARG_REQUIRED; p = strchr(arg, ','); if (!p || !p[1]) { - syslog(LOG_ERR, "invalid vendor format: %s", arg); + logerrx("invalid vendor format: %s", arg); return -1; } @@ -849,7 +860,7 @@ parse_option(struct dhcpcd_ctx *ctx, con s = parse_string((char *)ifo->vendor + 1, VENDOR_MAX_LEN, arg); if (s == -1) { - syslog(LOG_ERR, "vendor: %m"); + logerr("vendor"); return -1; } ifo->vendor[0] = (uint8_t)s; @@ -868,7 +879,7 @@ parse_option(struct dhcpcd_ctx *ctx, con i = (int)strtoi(arg, NULL, 0, 1, 254, &e); *p = ','; if (e) { - syslog(LOG_ERR, "vendor option should be between" + logerrx("vendor option should be between" " 1 and 254 inclusive"); return -1; } @@ -889,7 +900,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ifo->vendor[0] + 3, (size_t)s, arg); } if (s == -1) { - syslog(LOG_ERR, "vendor: %m"); + logerr("vendor"); return -1; } if (s != 0) { @@ -911,7 +922,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ARG_REQUIRED; ifo->reboot = (time_t)strtoi(arg, NULL, 0, 0, UINT32_MAX, &e); if (e) { - syslog(LOG_ERR, "failed to convert reboot %s", arg); + logerr("failed to convert reboot %s", arg); return -1; } break; @@ -936,7 +947,7 @@ parse_option(struct dhcpcd_ctx *ctx, con dl = strlen("skip_hooks=") + strlen(arg) + 1; p = malloc(sizeof(char) * dl); if (p == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } snprintf(p, dl, "skip_hooks=%s", arg); @@ -963,7 +974,7 @@ parse_option(struct dhcpcd_ctx *ctx, con else if (strcmp(arg, "disable") == 0) ifo->fqdn = FQDN_DISABLE; else { - syslog(LOG_ERR, "invalid value `%s' for FQDN", arg); + logerrx("invalid value `%s' for FQDN", arg); return -1; } break; @@ -979,7 +990,7 @@ parse_option(struct dhcpcd_ctx *ctx, con else s = 0; if (s == -1) { - syslog(LOG_ERR, "clientid: %m"); + logerr("clientid"); return -1; } ifo->options |= DHCPCD_CLIENTID; @@ -1005,7 +1016,7 @@ parse_option(struct dhcpcd_ctx *ctx, con make_option_mask(d, dl, od, odl, require, arg, -1) != 0 || make_option_mask(d, dl, od, odl, no, arg, 1) != 0) { - syslog(LOG_ERR, "unknown option `%s'", arg); + logerrx("unknown option `%s'", arg); return -1; } break; @@ -1018,7 +1029,7 @@ parse_option(struct dhcpcd_ctx *ctx, con make_option_mask(d, dl, od, odl, no, arg, -1) != 0 || make_option_mask(d, dl, od, odl, reject, arg, -1) != 0) { - syslog(LOG_ERR, "unknown option `%s'", arg); + logerrx("unknown option `%s'", arg); return -1; } break; @@ -1026,7 +1037,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ARG_REQUIRED; p = strchr(arg, '='); if (p == NULL) { - syslog(LOG_ERR, "static assignment required"); + logerrx("static assignment required"); return -1; } p++; @@ -1055,7 +1066,7 @@ parse_option(struct dhcpcd_ctx *ctx, con fp = np = strwhite(p); if (np == NULL) { - syslog(LOG_ERR, "all routes need a gateway"); + logerrx("all routes need a gateway"); return -1; } *np++ = '\0'; @@ -1092,7 +1103,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ifo->mtu = (unsigned int)strtou(p, NULL, 0, MTU_MIN, MTU_MAX, &e); if (e) { - syslog(LOG_ERR, "invalid MTU %s", p); + logerrx("invalid MTU %s", p); return -1; } } else if (strncmp(arg, "ip6_address=", strlen("ip6_address=")) == 0) { @@ -1104,8 +1115,7 @@ parse_option(struct dhcpcd_ctx *ctx, con ifo->req_prefix_len = (uint8_t)strtou(np, NULL, 0, 0, 128, &e); if (e) { - syslog(LOG_ERR, - "%s: failed to " + logerrx("%s: failed to " "convert prefix len", ifname); return -1; @@ -1122,8 +1132,7 @@ parse_option(struct dhcpcd_ctx *ctx, con { p = strdup(arg); if (p == NULL) { - syslog(LOG_ERR, - "%s: %m", __func__); + logerr(__func__); return -1; } free(ifo->config[dl]); @@ -1135,12 +1144,12 @@ parse_option(struct dhcpcd_ctx *ctx, con } p = strdup(arg); if (p == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } - nconf = realloc(ifo->config, sizeof(char *) * (dl + 2)); + nconf = reallocarray(ifo->config, dl+2, sizeof(char *)); if (nconf == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(p); return -1; } @@ -1154,10 +1163,10 @@ parse_option(struct dhcpcd_ctx *ctx, con return -1; if (strchr(arg, '/') == NULL) addr2.s_addr = INADDR_BROADCAST; - naddr = realloc(ifo->whitelist, - sizeof(in_addr_t) * (ifo->whitelist_len + 2)); + naddr = reallocarray(ifo->whitelist, + ifo->whitelist_len + 2, sizeof(in_addr_t)); if (naddr == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } ifo->whitelist = naddr; @@ -1169,10 +1178,10 @@ parse_option(struct dhcpcd_ctx *ctx, con return -1; if (strchr(arg, '/') == NULL) addr2.s_addr = INADDR_BROADCAST; - naddr = realloc(ifo->blacklist, - sizeof(in_addr_t) * (ifo->blacklist_len + 2)); + naddr = reallocarray(ifo->blacklist, + ifo->blacklist_len + 2, sizeof(in_addr_t)); if (naddr == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } ifo->blacklist = naddr; @@ -1215,10 +1224,10 @@ parse_option(struct dhcpcd_ctx *ctx, con *fp++ = '\0'; if (parse_addr(&addr, NULL, arg) != 0) return -1; - naddr = realloc(ifo->arping, - sizeof(in_addr_t) * ((size_t)ifo->arping_len + 1)); + naddr = reallocarray(ifo->arping, + (size_t)ifo->arping_len + 1, sizeof(in_addr_t)); if (naddr == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } ifo->arping = naddr; @@ -1234,10 +1243,10 @@ parse_option(struct dhcpcd_ctx *ctx, con ifo->dstmask, arg, 2) != 0) { if (errno == EINVAL) - syslog(LOG_ERR, "option `%s' does not take" + logerrx("option `%s' does not take" " an IPv4 address", arg); else - syslog(LOG_ERR, "unknown option `%s'", arg); + logerrx("unknown option `%s'", arg); return -1; } break; @@ -1246,7 +1255,7 @@ parse_option(struct dhcpcd_ctx *ctx, con free(ifo->fallback); ifo->fallback = strdup(arg); if (ifo->fallback == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerrx(__func__); return -1; } break; @@ -1254,12 +1263,11 @@ parse_option(struct dhcpcd_ctx *ctx, con case O_IAID: ARG_REQUIRED; if (ifname == NULL) { - syslog(LOG_ERR, - "IAID must belong in an interface block"); + logerrx("IAID must belong in an interface block"); return -1; } if (parse_iaid(ifo->iaid, arg, sizeof(ifo->iaid)) == -1) { - syslog(LOG_ERR, "invalid IAID %s", arg); + logerrx("invalid IAID %s", arg); return -1; } ifo->options |= DHCPCD_IAID; @@ -1293,15 +1301,15 @@ parse_option(struct dhcpcd_ctx *ctx, con case O_IA_PD: if (i == 0) { if (ifname == NULL) { - syslog(LOG_ERR, - "IA PD must belong in an interface block"); + logerr("IA PD must belong in an " + "interface block"); return -1; } i = D6_OPTION_IA_PD; } if (ifname == NULL && arg) { - syslog(LOG_ERR, - "IA with IAID must belong in an interface block"); + logerrx("IA with IAID must belong in an " + "interface block"); return -1; } ifo->options |= DHCPCD_IA_FORCED; @@ -1315,7 +1323,7 @@ parse_option(struct dhcpcd_ctx *ctx, con if (p) *p++ = '\0'; if (parse_iaid(iaid, arg, sizeof(iaid)) == -1) { - syslog(LOG_ERR, "invalid IAID: %s", arg); + logerr("invalid IAID: %s", arg); return -1; } } @@ -1333,14 +1341,14 @@ parse_option(struct dhcpcd_ctx *ctx, con } } if (ia && ia->ia_type != (uint16_t)i) { - syslog(LOG_ERR, "Cannot mix IA for the same IAID"); + logerrx("Cannot mix IA for the same IAID"); break; } if (ia == NULL) { - ia = realloc(ifo->ia, - sizeof(*ifo->ia) * (ifo->ia_len + 1)); + ia = reallocarray(ifo->ia, + ifo->ia_len + 1, sizeof(*ifo->ia)); if (ia == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } ifo->ia = ia; @@ -1366,15 +1374,14 @@ parse_option(struct dhcpcd_ctx *ctx, con if (p) *p++ = '\0'; if (inet_pton(AF_INET6, arg, &ia->addr) == -1) { - syslog(LOG_ERR, "%s: %m", arg); + logerr("%s", arg); memset(&ia->addr, 0, sizeof(ia->addr)); } if (p && ia->ia_type == D6_OPTION_IA_PD) { ia->prefix_len = (uint8_t)strtou(p, NULL, 0, 8, 120, &e); if (e) { - syslog(LOG_ERR, - "%s: failed to convert" + logerrx("%s: failed to convert" " prefix len", p); ia->prefix_len = 0; @@ -1393,10 +1400,10 @@ parse_option(struct dhcpcd_ctx *ctx, con *fp++ = '\0'; fp = strskipwhite(fp); } - sla = realloc(ia->sla, - sizeof(*ia->sla) * (ia->sla_len + 1)); + sla = reallocarray(ia->sla, + ia->sla_len + 1, sizeof(*ia->sla)); if (sla == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } ia->sla = sla; @@ -1407,8 +1414,7 @@ parse_option(struct dhcpcd_ctx *ctx, con if (strlcpy(sla->ifname, p, sizeof(sla->ifname)) >= sizeof(sla->ifname)) { - syslog(LOG_ERR, - "%s: interface name too long", arg); + logerrx("%s: interface name too long", arg); goto err_sla; } sla->sla_set = 0; @@ -1424,8 +1430,8 @@ parse_option(struct dhcpcd_ctx *ctx, con 0, 0, UINT32_MAX, &e); sla->sla_set = 1; if (e) { - syslog(LOG_ERR, - "%s: failed to convert sla", + logerrx("%s: failed to convert " + "sla", ifname); goto err_sla; } @@ -1440,8 +1446,7 @@ parse_option(struct dhcpcd_ctx *ctx, con sla->prefix_len = (uint8_t)strtou(p, NULL, 0, 0, 120, &e); if (e) { - syslog(LOG_ERR, - "%s: failed to " + logerrx("%s: failed to " "convert prefix len", ifname); goto err_sla; @@ -1457,8 +1462,7 @@ parse_option(struct dhcpcd_ctx *ctx, con sla->suffix = (uint64_t)strtou(p, NULL, 0, 0, UINT64_MAX, &e); if (e) { - syslog(LOG_ERR, - "%s: failed to " + logerrx("%s: failed to " "convert suffix", ifname); goto err_sla; @@ -1469,8 +1473,7 @@ parse_option(struct dhcpcd_ctx *ctx, con for (sl = 0; sl < ia->sla_len - 1; sl++) { slap = &ia->sla[sl]; if (slap->sla_set != sla->sla_set) { - syslog(LOG_ERR, - "%s: cannot mix automatic " + logerrx("%s: cannot mix automatic " "and fixed SLA", sla->ifname); goto err_sla; @@ -1479,8 +1482,7 @@ parse_option(struct dhcpcd_ctx *ctx, con (sla->prefix_len == ia->prefix_len || slap->prefix_len == ia->prefix_len)) { - syslog(LOG_ERR, - "%s: cannot delegte the same" + logerrx("%s: cannot delegte the same" "prefix length more than once", sla->ifname); goto err_sla; @@ -1488,8 +1490,7 @@ parse_option(struct dhcpcd_ctx *ctx, con if (sla->sla_set == 0 && strcmp(slap->ifname, sla->ifname) == 0) { - syslog(LOG_WARNING, - "%s: cannot specify the " + logwarnx("%s: cannot specify the " "same interface twice with " "an automatic SLA", sla->ifname); @@ -1498,7 +1499,7 @@ parse_option(struct dhcpcd_ctx *ctx, con if (slap->sla_set && sla->sla_set && slap->sla == sla->sla) { - syslog(LOG_ERR, "%s: cannot" + logerrx("%s: cannot" " assign the same SLA %u" " more than once", sla->ifname, sla->sla); @@ -1559,8 +1560,8 @@ err_sla: dop = &(*ldop)->embopts; dop_len = &(*ldop)->embopts_len; } else { - syslog(LOG_ERR, - "embed must be after a define or encap"); + logerrx("embed must be after a define " + "or encap"); return -1; } } @@ -1569,7 +1570,7 @@ err_sla: ARG_REQUIRED; if (dop == NULL) { if (*ldop == NULL) { - syslog(LOG_ERR, "encap must be after a define"); + logerrx("encap must be after a define"); return -1; } dop = &(*ldop)->encopts; @@ -1584,18 +1585,18 @@ err_sla: else { fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "invalid syntax: %s", arg); + logerrx("invalid syntax: %s", arg); return -1; } *fp++ = '\0'; u = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); if (e) { - syslog(LOG_ERR, "invalid code: %s", arg); + logerrx("invalid code: %s", arg); return -1; } arg = strskipwhite(fp); if (arg == NULL) { - syslog(LOG_ERR, "invalid syntax"); + logerrx("invalid syntax"); return -1; } } @@ -1610,7 +1611,7 @@ err_sla: bp = NULL; /* No bitflag */ l = (long)strtou(np, NULL, 0, 0, LONG_MAX, &e); if (e) { - syslog(LOG_ERR, "failed to convert length"); + logerrx("failed to convert length"); return -1; } } else { @@ -1625,7 +1626,7 @@ err_sla: arg = strskipwhite(fp); fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "incomplete request type"); + logerrx("incomplete request type"); return -1; } *fp++ = '\0'; @@ -1634,7 +1635,7 @@ err_sla: arg = strskipwhite(fp); fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "incomplete request type"); + logerrx("incomplete request type"); return -1; } *fp++ = '\0'; @@ -1644,7 +1645,7 @@ err_sla: arg = strskipwhite(fp); fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "incomplete optional type"); + logerrx("incomplete optional type"); return -1; } *fp++ = '\0'; @@ -1654,7 +1655,7 @@ err_sla: arg = strskipwhite(fp); fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "incomplete index type"); + logerrx("incomplete index type"); return -1; } *fp++ = '\0'; @@ -1664,7 +1665,7 @@ err_sla: arg = strskipwhite(fp); fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "incomplete array type"); + logerrx("incomplete array type"); return -1; } *fp++ = '\0'; @@ -1714,30 +1715,28 @@ err_sla: else if (strcasecmp(arg, "option") == 0) t |= OT_OPTION; else { - syslog(LOG_ERR, "unknown type: %s", arg); + logerrx("unknown type: %s", arg); return -1; } if (l && !(t & (OT_STRING | OT_BINHEX))) { - syslog(LOG_WARNING, - "ignoring length for type `%s'", arg); + logwarnx("ignoring length for type `%s'", arg); l = 0; } if (t & OT_ARRAY && t & (OT_STRING | OT_BINHEX) && !(t & (OT_RFC1035 | OT_DOMAIN))) { - syslog(LOG_WARNING, "ignoring array for strings"); + logwarnx("ignoring array for strings"); t &= ~OT_ARRAY; } if (t & OT_BITFLAG) { if (bp == NULL) - syslog(LOG_WARNING, - "missing bitflag assignment"); + logwarnx("missing bitflag assignment"); } /* variable */ if (!fp) { if (!(t & OT_OPTION)) { - syslog(LOG_ERR, - "type %s requires a variable name", arg); + logerrx("type %s requires a variable name", + arg); return -1; } np = NULL; @@ -1749,7 +1748,7 @@ err_sla: if (strcasecmp(arg, "reserved")) { np = strdup(arg); if (np == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } } else { @@ -1770,10 +1769,9 @@ err_sla: } else ndop = NULL; if (ndop == NULL) { - if ((ndop = realloc(*dop, - sizeof(**dop) * ((*dop_len) + 1))) == NULL) - { - syslog(LOG_ERR, "%s: %m", __func__); + ndop = reallocarray(*dop, *dop_len + 1, sizeof(**dop)); + if (ndop == NULL) { + logerr(__func__); free(np); return -1; } @@ -1816,23 +1814,23 @@ err_sla: *fp++ = '\0'; u = (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); if (e) { - syslog(LOG_ERR, "invalid code: %s", arg); + logerrx("invalid code: %s", arg); return -1; } if (fp) { s = parse_string(NULL, 0, fp); if (s == -1) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } dl = (size_t)s; if (dl + (sizeof(uint16_t) * 2) > UINT16_MAX) { - syslog(LOG_ERR, "vendor class is too big"); + logerrx("vendor class is too big"); return -1; } np = malloc(dl); if (np == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return -1; } parse_string(np, dl, fp); @@ -1840,10 +1838,10 @@ err_sla: dl = 0; np = NULL; } - vivco = realloc(ifo->vivco, sizeof(*ifo->vivco) * - (ifo->vivco_len + 1)); + vivco = reallocarray(ifo->vivco, + ifo->vivco_len + 1, sizeof(*ifo->vivco)); if (vivco == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr( __func__); return -1; } ifo->vivco = vivco; @@ -1865,7 +1863,7 @@ err_sla: else if (strcasecmp(arg, "delayedrealm") == 0) ifo->auth.protocol = AUTH_PROTO_DELAYEDREALM; else { - syslog(LOG_ERR, "%s: unsupported protocol", arg); + logerrx("%s: unsupported protocol", arg); return -1; } arg = strskipwhite(fp); @@ -1885,7 +1883,7 @@ err_sla: strcasecmp(arg, "hmac-md5") == 0) ifo->auth.algorithm = AUTH_ALG_HMAC_MD5; else { - syslog(LOG_ERR, "%s: unsupported algorithm", arg); + logerrx("%s: unsupported algorithm", arg); return 1; } arg = fp; @@ -1901,13 +1899,13 @@ err_sla: strcasecmp(arg, "monotime") == 0) ifo->auth.rdm = AUTH_RDM_MONOTONIC; else { - syslog(LOG_ERR, "%s: unsupported RDM", arg); + logerrx("%s: unsupported RDM", arg); return -1; } ifo->auth.options |= DHCPCD_AUTH_SEND; break; #else - syslog(LOG_ERR, "no authentication support"); + logerrx("no authentication support"); return -1; #endif case O_AUTHTOKEN: @@ -1915,32 +1913,32 @@ err_sla: #ifdef AUTH fp = strwhite(arg); if (fp == NULL) { - syslog(LOG_ERR, "authtoken requires a realm"); + logerrx("authtoken requires a realm"); return -1; } *fp++ = '\0'; token = malloc(sizeof(*token)); if (token == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(token); return -1; } if (parse_uint32(&token->secretid, arg) == -1) { - syslog(LOG_ERR, "%s: not a number", arg); + logerrx("%s: not a number", arg); free(token); return -1; } arg = fp; fp = strend(arg); if (fp == NULL) { - syslog(LOG_ERR, "authtoken requies an a key"); + logerrx("authtoken requies an a key"); free(token); return -1; } *fp++ = '\0'; s = parse_string(NULL, 0, arg); if (s == -1) { - syslog(LOG_ERR, "realm_len: %m"); + logerr("realm_len"); free(token); return -1; } @@ -1948,8 +1946,8 @@ err_sla: token->realm_len = (size_t)s; token->realm = malloc(token->realm_len); if (token->realm == NULL) { + logerr(__func__); free(token); - syslog(LOG_ERR, "%s: %m", __func__); return -1; } parse_string((char *)token->realm, token->realm_len, @@ -1961,7 +1959,7 @@ err_sla: arg = fp; fp = strend(arg); if (fp == NULL) { - syslog(LOG_ERR, "authtoken requies an an expiry date"); + logerrx("authtoken requies an an expiry date"); free(token->realm); free(token); return -1; @@ -1980,13 +1978,13 @@ err_sla: memset(&tm, 0, sizeof(tm)); if (strptime(arg, "%Y-%m-%d %H:%M", &tm) == NULL) { - syslog(LOG_ERR, "%s: invalid date time", arg); + logerrx("%s: invalid date time", arg); free(token->realm); free(token); return -1; } if ((token->expire = mktime(&tm)) == (time_t)-1) { - syslog(LOG_ERR, "%s: mktime: %m", __func__); + logerr("%s: mktime", __func__); free(token->realm); free(token); return -1; @@ -1995,8 +1993,10 @@ err_sla: arg = fp; s = parse_string(NULL, 0, arg); if (s == -1 || s == 0) { - syslog(LOG_ERR, s == -1 ? "token_len: %m" : - "authtoken needs a key"); + if (s == -1) + logerr("token_len"); + else + logerrx("authtoken needs a key"); free(token->realm); free(token); return -1; @@ -2006,7 +2006,7 @@ err_sla: parse_string((char *)token->key, token->key_len, arg); TAILQ_INSERT_TAIL(&ifo->auth.tokens, token, next); #else - syslog(LOG_ERR, "no authentication support"); + logerrx("no authentication support"); return -1; #endif break; @@ -2035,7 +2035,7 @@ err_sla: dl = (size_t)l; p = malloc(dl); if (p == NULL) { - syslog(LOG_ERR, "%s: malloc: %m", __func__); + logerr(__func__); return -1; } while ((i = getgrnam_r(arg, &grpbuf, p, (size_t)l, &grp)) == @@ -2043,14 +2043,14 @@ err_sla: { size_t nl = dl * 2; if (nl < dl) { - syslog(LOG_ERR, "control_group: out of buffer"); + logerrx("control_group: out of buffer"); free(p); return -1; } dl = nl; np = realloc(p, dl); if (np == NULL) { - syslog(LOG_ERR, "control_group: realloc: %m"); + logerr(__func__); free(p); return -1; } @@ -2058,12 +2058,12 @@ err_sla: } if (i != 0) { errno = i; - syslog(LOG_ERR, "getgrnam_r: %m"); + logerr("getgrnam_r"); free(p); return -1; } if (grp == NULL) { - syslog(LOG_ERR, "controlgroup: %s: not found", arg); + logerrx("controlgroup: %s: not found", arg); free(p); return -1; } @@ -2072,7 +2072,7 @@ err_sla: #else grp = getgrnam(arg); if (grp == NULL) { - syslog(LOG_ERR, "controlgroup: %s: not found", arg); + logerrx("controlgroup: %s: not found", arg); return -1; } ctx->control_group = grp->gr_gid; @@ -2106,7 +2106,7 @@ err_sla: ARG_REQUIRED; s = parse_string((char *)ifo->mudurl + 1, MUDURL_MAX_LEN, arg); if (s == -1) { - syslog(LOG_ERR, "mudurl: %m"); + logerr("mudurl"); return -1; } *ifo->mudurl = (uint8_t)s; @@ -2119,7 +2119,7 @@ err_sla: #ifdef ARG_REQUIRED arg_required: - syslog(LOG_ERR, "option %d requires an argument", opt); + logerrx("option %d requires an argument", opt); return -1; #undef ARG_REQUIRED #endif @@ -2138,9 +2138,7 @@ parse_config_line(struct dhcpcd_ctx *ctx continue; if (cf_options[i].has_arg == required_argument && !line) { - syslog(LOG_ERR, - PACKAGE ": option requires an argument -- %s", - opt); + logerrx("option requires an argument -- %s", opt); return -1; } @@ -2148,7 +2146,7 @@ parse_config_line(struct dhcpcd_ctx *ctx ldop, edop); } - syslog(LOG_ERR, "unknown option: %s", opt); + logerrx("unknown option: %s", opt); return -1; } @@ -2213,7 +2211,7 @@ default_config(struct dhcpcd_ctx *ctx) /* Seed our default options */ if ((ifo = calloc(1, sizeof(*ifo))) == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); return NULL; } ifo->options |= DHCPCD_IF_UP | DHCPCD_LINK | DHCPCD_INITIAL_DELAY; @@ -2286,7 +2284,7 @@ read_config(struct dhcpcd_ctx *ctx, ifo->dhcp_override = calloc(INITDEFINES, sizeof(*ifo->dhcp_override)); if (ifo->dhcp_override == NULL) - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); else ifo->dhcp_override_len = INITDEFINES; #endif @@ -2295,7 +2293,7 @@ read_config(struct dhcpcd_ctx *ctx, ifo->nd_override = calloc(INITDEFINENDS, sizeof(*ifo->nd_override)); if (ifo->nd_override == NULL) - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); else ifo->nd_override_len = INITDEFINENDS; #endif @@ -2303,7 +2301,7 @@ read_config(struct dhcpcd_ctx *ctx, ifo->dhcp6_override = calloc(INITDEFINE6S, sizeof(*ifo->dhcp6_override)); if (ifo->dhcp6_override == NULL) - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); else ifo->dhcp6_override_len = INITDEFINE6S; #endif @@ -2312,14 +2310,14 @@ read_config(struct dhcpcd_ctx *ctx, #ifdef EMBEDDED_CONFIG fp = fopen(EMBEDDED_CONFIG, "r"); if (fp == NULL) - syslog(LOG_ERR, "fopen `%s': %m", EMBEDDED_CONFIG); + logerr("%s: fopen `%s'", __func__, EMBEDDED_CONFIG); while (fp && (line = get_line(&buf, &buflen, fp))) { #else buflen = 80; buf = malloc(buflen); if (buf == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free_options(ifo); return NULL; } @@ -2332,7 +2330,7 @@ read_config(struct dhcpcd_ctx *ctx, buflen = ol; nbuf = realloc(buf, buflen); if (nbuf == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); free(buf); free_options(ifo); return NULL; @@ -2408,7 +2406,7 @@ read_config(struct dhcpcd_ctx *ctx, if (fp == NULL) { /* dhcpcd can continue without it, but no DNS options * would be requested ... */ - syslog(LOG_WARNING, "fopen `%s': %m", ctx->cffile); + logwarn("%s: fopen `%s'", __func__, ctx->cffile); free(buf); return ifo; } @@ -2455,13 +2453,13 @@ read_config(struct dhcpcd_ctx *ctx, n = reallocarray(ctx->ifcv, (size_t)ctx->ifcc + 1, sizeof(char *)); if (n == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); continue; } ctx->ifcv = n; ctx->ifcv[ctx->ifcc] = strdup(line); if (ctx->ifcv[ctx->ifcc] == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); + logerr(__func__); continue; } ctx->ifcc++;