From: Roy Marples Date: Wed, 12 Apr 2017 09:38:44 +0000 (+0100) Subject: Add logdebugx, similar to logerrx and logwarnx. X-Git-Tag: v7.0.0-beta3~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e56d022c743ab3aab813fc8a0d6f82e56e7fc63;p=thirdparty%2Fdhcpcd.git Add logdebugx, similar to logerrx and logwarnx. logdebug now logs errors like logerr and logwarn. --- diff --git a/src/arp.c b/src/arp.c index 74f6f6d6..f6b650d6 100644 --- a/src/arp.c +++ b/src/arp.c @@ -152,7 +152,7 @@ arp_packet(struct interface *ifp, uint8_t *data, size_t len) } if (ifn) { #ifdef ARP_DEBUG - logdebug("%s: ignoring ARP from self", ifp->name); + logdebugx("%s: ignoring ARP from self", ifp->name); #endif return; } @@ -256,7 +256,7 @@ arp_probe1(void *arg) tv.tv_nsec = 0; eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate); } - logdebug("%s: ARP probing %s (%d of %d), next in %0.1f seconds", + logdebugx("%s: ARP probing %s (%d of %d), next in %0.1f seconds", ifp->name, inet_ntoa(astate->addr), astate->probes ? astate->probes : PROBE_NUM, PROBE_NUM, timespec_to_double(&tv)); @@ -278,7 +278,7 @@ arp_probe(struct arp_state *astate) logerr(__func__); } astate->probes = 0; - logdebug("%s: probing for %s", + logdebugx("%s: probing for %s", astate->iface->name, inet_ntoa(astate->addr)); arp_probe1(astate); } @@ -311,12 +311,12 @@ arp_announce1(void *arg) astate->claims++; #else if (++astate->claims < ANNOUNCE_NUM) - logdebug("%s: ARP announcing %s (%d of %d), " + logdebugx("%s: ARP announcing %s (%d of %d), " "next in %d.0 seconds", ifp->name, inet_ntoa(astate->addr), astate->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT); else - logdebug("%s: ARP announcing %s (%d of %d)", + logdebugx("%s: ARP announcing %s (%d of %d)", ifp->name, inet_ntoa(astate->addr), astate->claims, ANNOUNCE_NUM); if (arp_request(ifp, astate->addr.s_addr, astate->addr.s_addr) == -1) diff --git a/src/dev.c b/src/dev.c index 452f3cd6..acd320ed 100644 --- a/src/dev.c +++ b/src/dev.c @@ -61,7 +61,7 @@ dev_stop1(struct dhcpcd_ctx *ctx, int stop) if (ctx->dev) { if (stop) - logdebug("dev: unloaded %s", ctx->dev->name); + logdebugx("dev: unloaded %s", ctx->dev->name); eloop_event_delete(ctx->eloop, ctx->dev_fd); ctx->dev->stop(); free(ctx->dev); @@ -138,7 +138,7 @@ dev_start1(struct dhcpcd_ctx *ctx) dp = opendir(DEVDIR); if (dp == NULL) { - logdebug("dev: %s: %m", DEVDIR); + logdebug("dev: %s", DEVDIR); return 0; } diff --git a/src/dhcp.c b/src/dhcp.c index 2105f1f3..1d4dc477 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -600,7 +600,7 @@ get_option_routes(struct rt_head *routes, struct interface *ifp, if (!(ifo->options & DHCPCD_CSR_WARNED) && !(state->added & STATE_FAKE)) { - logdebug("%s: using %sClassless Static Routes", + logdebugx("%s: using %sClassless Static Routes", ifp->name, csr); ifo->options |= DHCPCD_CSR_WARNED; } @@ -1128,7 +1128,7 @@ write_lease(const struct interface *ifp, const struct bootp *bootp, size_t len) ssize_t bytes; const struct dhcp_state *state = D_CSTATE(ifp); - logdebug("%s: writing lease `%s'", ifp->name, state->leasefile); + logdebugx("%s: writing lease `%s'", ifp->name, state->leasefile); fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) @@ -1169,9 +1169,9 @@ read_lease(struct interface *ifp, struct bootp **bootp) return 0; } if (state->leasefile[0] == '\0') - logdebug("reading standard input"); + logdebugx("reading standard input"); else - logdebug("%s: reading lease `%s'", + logdebugx("%s: reading lease `%s'", ifp->name, state->leasefile); bytes = dhcp_read_lease_fd(fd, (void **)&lease); @@ -1210,15 +1210,15 @@ read_lease(struct interface *ifp, struct bootp **bootp) if (dhcp_auth_validate(&state->auth, &ifp->options->auth, lease, bytes, 4, type, auth, auth_len) == NULL) { - logdebug("%s: dhcp_auth_validate", ifp->name); + logerr("%s: authentication failed", ifp->name); free(lease); return 0; } if (state->auth.token) - logdebug("%s: validated using 0x%08" PRIu32, + logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, state->auth.token->secretid); else - logdebug("%s: accepted reconfigure key", ifp->name); + logdebugx("%s: accepted reconfigure key", ifp->name); } else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) == DHCPCD_AUTH_SENDREQUIRE) { @@ -1687,7 +1687,7 @@ send_message(struct interface *ifp, uint8_t type, /* No carrier? Don't bother sending the packet. */ if (ifp->carrier == LINK_DOWN) return; - logdebug("%s: sending %s with xid 0x%x", + logdebugx("%s: sending %s with xid 0x%x", ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type), state->xid); @@ -1707,7 +1707,7 @@ send_message(struct interface *ifp, uint8_t type, * However, we do need to advance the timeout. */ if (ifp->carrier == LINK_DOWN) goto fail; - logdebug("%s: sending %s (xid 0x%x), next in %0.1f seconds", + logdebugx("%s: sending %s (xid 0x%x), next in %0.1f seconds", ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type), state->xid, @@ -1960,7 +1960,7 @@ dhcp_startrenew(void *arg) eloop_timeout_delete(ifp->ctx->eloop, dhcp_startrenew, ifp); lease = &state->lease; - logdebug("%s: renewing lease of %s", ifp->name, + logdebugx("%s: renewing lease of %s", ifp->name, inet_ntoa(lease->addr)); state->state = DHS_RENEW; dhcp_new_xid(ifp); @@ -1983,7 +1983,7 @@ dhcp_rebind(void *arg) struct dhcp_lease *lease = &state->lease; logwarnx("%s: failed to renew DHCP, rebinding", ifp->name); - logdebug("%s: expire in %"PRIu32" seconds", + logdebugx("%s: expire in %"PRIu32" seconds", ifp->name, lease->leasetime - lease->rebindtime); state->state = DHS_REBIND; eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp); @@ -2031,7 +2031,7 @@ dhcp_arp_probed(struct arp_state *astate) if (state->state == DHS_BOUND) return; - logdebug("%s: DAD completed for %s", + logdebugx("%s: DAD completed for %s", ifp->name, inet_ntoa(astate->addr)); if (state->state != DHS_INFORM) dhcp_bind(ifp); @@ -2226,7 +2226,7 @@ dhcp_bind(struct interface *ifp) if (state->addr && lease->addr.s_addr == state->addr->addr.s_addr && !(state->added & STATE_FAKE)) - logdebug("%s: leased %s for %"PRIu32" seconds", + logdebugx("%s: leased %s for %"PRIu32" seconds", ifp->name, inet_ntoa(lease->addr), lease->leasetime); else @@ -2263,7 +2263,7 @@ dhcp_bind(struct interface *ifp) (time_t)lease->rebindtime, dhcp_rebind, ifp); eloop_timeout_add_sec(ifp->ctx->eloop, (time_t)lease->leasetime, dhcp_expire, ifp); - logdebug("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32 + logdebugx("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32 " seconds", ifp->name, lease->renewaltime, lease->rebindtime); } @@ -2751,7 +2751,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, /* Handled in our BPF filter. */ #if 0 if (bootp->op != BOOTREPLY) { - logdebug("%s: op (%d) is not BOOTREPLY", + logdebugx("%s: op (%d) is not BOOTREPLY", ifp->name, bootp->op); return; } @@ -2761,7 +2761,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, { char buf[sizeof(bootp->chaddr) * 3]; - logdebug("%s: xid 0x%x is for hwaddr %s", + logdebugx("%s: xid 0x%x is for hwaddr %s", ifp->name, ntohl(bootp->xid), hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr), buf, sizeof(buf))); @@ -2774,7 +2774,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, bootp, bootp_len, DHO_MESSAGETYPE) == -1) type = 0; else if (ifo->options & DHCPCD_BOOTP) { - logdebug("%s: ignoring DHCP reply (expecting BOOTP)", + logdebugx("%s: ignoring DHCP reply (expecting BOOTP)", ifp->name); return; } @@ -2788,13 +2788,11 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, (uint8_t *)bootp, bootp_len, 4, type, auth, auth_len) == NULL) { - logdebug("%s: dhcp_auth_validate", - ifp->name); LOGDHCP0(logerrx, "authentication failed"); return; } if (state->auth.token) - logdebug("%s: validated using 0x%08" PRIu32, + logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, state->auth.token->secretid); else loginfo("%s: accepted reconfigure key", ifp->name); @@ -2822,7 +2820,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, return; } if (state->state != DHS_BOUND && state->state != DHS_INFORM) { - LOGDHCP(logdebug, "not bound, ignoring Force Renew"); + LOGDHCP(logdebugx, "not bound, ignoring Force Renew"); return; } LOGDHCP(loginfo, "Force Renew from"); @@ -2845,7 +2843,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, /* Before we supported FORCERENEW we closed off the raw * port so we effectively ignored all messages. * As such we'll not log by default here. */ - //LOGDHCP(logdebug, "bound, ignoring"); + //LOGDHCP(logdebugx, "bound, ignoring"); return; } @@ -2853,7 +2851,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, #if 0 /* Ensure it's the right transaction */ if (state->xid != ntohl(bootp->xid)) { - logdebug("%s: wrong xid 0x%x (expecting 0x%x) from %s", + logdebugx("%s: wrong xid 0x%x (expecting 0x%x) from %s", ifp->name, ntohl(bootp->xid), state->xid, inet_ntoa(*from)); return; @@ -2862,7 +2860,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, if (state->state == DHS_PROBE) { /* Ignore any DHCP messages whilst probing a lease to bind. */ - LOGDHCP(logdebug, "probing, ignoring"); + LOGDHCP(logdebugx, "probing, ignoring"); return; } @@ -3077,14 +3075,14 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, DHO_RAPIDCOMMIT, NULL)) state->state = DHS_REQUEST; else { - LOGDHCP(logdebug, "ignoring ack of"); + LOGDHCP(logdebugx, "ignoring ack of"); return; } } rapidcommit: if (!(ifo->options & DHCPCD_INFORM)) - LOGDHCP(logdebug, "acknowledged"); + LOGDHCP(logdebugx, "acknowledged"); else ifo->options &= ~DHCPCD_STATIC; } @@ -3445,11 +3443,11 @@ dhcp_init(struct interface *ifp) return 0; if (ifo->options & DHCPCD_CLIENTID) - logdebug("%s: using ClientID %s", ifp->name, + logdebugx("%s: using ClientID %s", ifp->name, hwaddr_ntoa(state->clientid + 1, state->clientid[0], buf, sizeof(buf))); else if (ifp->hwlen) - logdebug("%s: using hwaddr %s", ifp->name, + logdebugx("%s: using hwaddr %s", ifp->name, hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf))); return 0; @@ -3594,7 +3592,7 @@ dhcp_start1(void *arg) if (now == -1 || (time_t)state->lease.leasetime < now - st.st_mtime) { - logdebug("%s: discarding expired lease", + logdebugx("%s: discarding expired lease", ifp->name); free(state->offer); state->offer = NULL; @@ -3702,7 +3700,7 @@ dhcp_start(struct interface *ifp) tv.tv_nsec = (suseconds_t)arc4random_uniform( (DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC); timespecnorm(&tv); - logdebug("%s: delaying IPv4 for %0.1f seconds", + logdebugx("%s: delaying IPv4 for %0.1f seconds", ifp->name, timespec_to_double(&tv)); eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_start1, ifp); diff --git a/src/dhcp6.c b/src/dhcp6.c index 631ae083..be7f24fb 100644 --- a/src/dhcp6.c +++ b/src/dhcp6.c @@ -1085,7 +1085,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) } if (!callback) - logdebug("%s: %s %s with xid 0x%02x%02x%02x", + logdebugx("%s: %s %s with xid 0x%02x%02x%02x", ifp->name, broad_uni, dhcp6_get_op(state->send->type), @@ -1152,7 +1152,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *)) logsend: if (ifp->carrier != LINK_DOWN) - logdebug("%s: %s %s (xid 0x%02x%02x%02x)," + logdebugx("%s: %s %s (xid 0x%02x%02x%02x)," " next in %0.1f seconds", ifp->name, broad_uni, @@ -1363,7 +1363,7 @@ dhcp6_dadcallback(void *arg) } } if (!wascompleted) { - logdebug("%s: DHCPv6 DAD completed", + logdebugx("%s: DHCPv6 DAD completed", ifp->name); script_runreason(ifp, ap->delegating_prefix ? @@ -1723,7 +1723,7 @@ dhcp6_checkstatusok(const struct interface *ifp, else farg = m; if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) { - //logdebug("%s: no status", ifp->name); + //logdebugx("%s: no status", ifp->name); return 0; } @@ -2099,7 +2099,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l, if (j == ifo->ia_len && !(ifo->ia_len == 0 && ifp->ctx->options & DHCPCD_DUMPLEASE)) { - logdebug("%s: ignoring unrequested IAID %s", + logdebugx("%s: ignoring unrequested IAID %s", ifp->name, hwaddr_ntoa(ia.iaid, sizeof(ia.iaid), buf, sizeof(buf))); @@ -2228,7 +2228,7 @@ dhcp6_writelease(const struct interface *ifp) ssize_t bytes; state = D6_CSTATE(ifp); - logdebug("%s: writing lease `%s'", ifp->name, state->leasefile); + logdebugx("%s: writing lease `%s'", ifp->name, state->leasefile); fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) { @@ -2258,11 +2258,11 @@ dhcp6_readlease(struct interface *ifp, int validate) state = D6_STATE(ifp); if (state->leasefile[0] == '\0') { - logdebug("reading standard input"); + logdebugx("reading standard input"); fd = fileno(stdin); fd_opened = false; } else { - logdebug("%s: reading lease `%s'", ifp->name, state->leasefile); + logdebugx("%s: reading lease `%s'", ifp->name, state->leasefile); fd = open(state->leasefile, O_RDONLY); if (fd != -1 && fstat(fd, &st) == -1) { close(fd); @@ -2307,7 +2307,7 @@ dhcp6_readlease(struct interface *ifp, int validate) state->leasefile[0] != '\0') { if ((time_t)state->expire < now - st.st_mtime) { - logdebug("%s: discarding expired lease", ifp->name); + logdebugx("%s: discarding expired lease", ifp->name); retval = 0; goto ex; } @@ -2323,12 +2323,11 @@ auth: (uint8_t *)state->new, state->new_len, 6, state->new->type, o, ol) == NULL) { - logdebug("%s: dhcp_auth_validate", __func__); logerr("%s: authentication failed", ifp->name); goto ex; } if (state->auth.token) - logdebug("%s: validated using 0x%08" PRIu32, + logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, state->auth.token->secretid); else loginfo("%s: accepted reconfigure key", ifp->name); @@ -2525,7 +2524,7 @@ dhcp6_script_try_run(struct interface *ifp, int delegated) if (!delegated) dhcpcd_daemonise(ifp->ctx); } else - logdebug("%s: waiting for DHCPv6 DAD to complete", ifp->name); + logdebugx("%s: waiting for DHCPv6 DAD to complete", ifp->name); } #ifdef SMALL @@ -2570,7 +2569,7 @@ dhcp6_delegate_prefix(struct interface *ifp) if (ap->flags & IPV6_AF_NEW) logfunc = loginfo; else - logfunc = logdebug; + logfunc = logdebugx; /* We only want to log this the once as we loop * through many interfaces first. */ ap->flags |= IPV6_AF_DELEGATEDLOG; @@ -2587,7 +2586,7 @@ dhcp6_delegate_prefix(struct interface *ifp) /* no SLA configured, so lets * automate it */ if (ifd->carrier != LINK_UP) { - logdebug( + logdebugx( "%s: has no carrier, cannot" " delegate addresses", ifd->name); @@ -2603,7 +2602,7 @@ dhcp6_delegate_prefix(struct interface *ifp) if (strcmp(ifd->name, sla->ifname)) continue; if (ifd->carrier != LINK_UP) { - logdebug( + logdebugx( "%s: has no carrier, cannot" " delegate addresses", ifd->name); @@ -2667,7 +2666,7 @@ dhcp6_find_delegates(struct interface *ifp) if (strcmp(ifp->name, sla->ifname)) continue; if (ipv6_linklocal(ifp) == NULL) { - logdebug( + logdebugx( "%s: delaying adding" " delegated addresses for" " LL address", @@ -2768,7 +2767,7 @@ dhcp6_handledata(void *arg) break; } if (ifp == NULL) { - logdebug("DHCPv6 reply for unexpected interface from %s", + logdebugx("DHCPv6 reply for unexpected interface from %s", ctx->sfrom); return; } @@ -2786,7 +2785,7 @@ dhcp6_handledata(void *arg) if (r->type != DHCP6_RECONFIGURE && (state->state == DH6S_BOUND || state->state == DH6S_INFORMED)) { - logdebug("%s: DHCPv6 reply received but already bound", + logdebugx("%s: DHCPv6 reply received but already bound", ifp->name); return; } @@ -2796,7 +2795,7 @@ dhcp6_handledata(void *arg) r->xid[1] != state->send->xid[1] || r->xid[2] != state->send->xid[2])) { - logdebug("%s: wrong xid 0x%02x%02x%02x" + logdebugx("%s: wrong xid 0x%02x%02x%02x" " (expecting 0x%02x%02x%02x) from %s", ifp->name, r->xid[0], r->xid[1], r->xid[2], @@ -2807,7 +2806,7 @@ dhcp6_handledata(void *arg) } if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) { - logdebug("%s: no DHCPv6 server ID from %s", + logdebugx("%s: no DHCPv6 server ID from %s", ifp->name, ctx->sfrom); return; } @@ -2816,7 +2815,7 @@ dhcp6_handledata(void *arg) if (o == NULL || ol != ctx->duid_len || memcmp(o, ctx->duid, ol) != 0) { - logdebug("%s: incorrect client ID from %s", + logdebugx("%s: incorrect client ID from %s", ifp->name, ctx->sfrom); return; } @@ -2849,13 +2848,12 @@ dhcp6_handledata(void *arg) if (dhcp_auth_validate(&state->auth, &ifo->auth, (uint8_t *)r, len, 6, r->type, auth, auth_len) == NULL) { - logdebug("dhcp_auth_validate"); - logerrx("%s: authentication failed from %s", + logerr("%s: authentication failed from %s", ifp->name, ctx->sfrom); return; } if (state->auth.token) - logdebug("%s: validated using 0x%08" PRIu32, + logdebugx("%s: validated using 0x%08" PRIu32, ifp->name, state->auth.token->secretid); else loginfo("%s: accepted reconfigure key", ifp->name); @@ -2948,7 +2946,7 @@ dhcp6_handledata(void *arg) memcpy(&max_rt, o, sizeof(max_rt)); max_rt = ntohl(max_rt); if (max_rt >= 60 && max_rt <= 86400) { - logdebug("%s: SOL_MAX_RT %llu -> %u", + logdebugx("%s: SOL_MAX_RT %llu -> %u", ifp->name, (unsigned long long)state->sol_max_rt, max_rt); @@ -2964,7 +2962,7 @@ dhcp6_handledata(void *arg) memcpy(&max_rt, o, sizeof(max_rt)); max_rt = ntohl(max_rt); if (max_rt >= 60 && max_rt <= 86400) { - logdebug("%s: INF_MAX_RT %llu -> %u", + logdebugx("%s: INF_MAX_RT %llu -> %u", ifp->name, (unsigned long long)state->inf_max_rt, max_rt); @@ -3070,7 +3068,7 @@ dhcp6_handledata(void *arg) break; } } - lognewinfo = has_new ? loginfo : logdebug; + lognewinfo = has_new ? loginfo : logdebugx; lognewinfo("%s: %s received from %s", ifp->name, op, ctx->sfrom); state->reason = NULL; @@ -3393,7 +3391,7 @@ gogogo: dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile), AF_INET6, ifp); if (ipv6_linklocal(ifp) == NULL) { - logdebug("%s: delaying DHCPv6 soliciation for LL address", + logdebugx("%s: delaying DHCPv6 soliciation for LL address", ifp->name); ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp); return 0; diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 4b504bd7..aafe1a73 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -258,14 +258,14 @@ dhcpcd_ipwaited(struct dhcpcd_ctx *ctx) TAILQ_FOREACH(ifp, ctx->ifaces, next) { if ((af = dhcpcd_ifafwaiting(ifp)) != AF_MAX) { - logdebug("%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) { - logdebug("waiting for an %s address", + logdebugx("waiting for an %s address", dhcpcd_af(af)); return 0; } @@ -303,7 +303,7 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx) if (ctx->options & DHCPCD_DAEMONISED || !(ctx->options & DHCPCD_DAEMONISE)) return 0; - logdebug("forking to background"); + logdebugx("forking to background"); /* Setup a signal pipe so parent knows when to exit. */ if (pipe(sidpipe) == -1) { @@ -557,7 +557,7 @@ dhcpcd_selectprofile(struct interface *ifp, const char *profile) pssid[0] = '\0'; ifo = read_config(ifp->ctx, ifp->name, pssid, profile); if (ifo == NULL) { - logdebug("%s: no profile %s", ifp->name, profile); + logdebugx("%s: no profile %s", ifp->name, profile); return -1; } if (profile != NULL) { @@ -983,7 +983,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) return -1; } if (ifp->active) { - logdebug("%s: interface departed", ifp->name); + logdebugx("%s: interface departed", ifp->name); ifp->options->options |= DHCPCD_DEPARTED; stop_interface(ifp); } @@ -1018,7 +1018,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) iff = if_find(ctx->ifaces, ifp->name); if (iff) { if (iff->active) - logdebug("%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; @@ -1029,7 +1029,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname) TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next); if (!ifp->active) continue; - logdebug("%s: interface added", ifp->name); + logdebugx("%s: interface added", ifp->name); dhcpcd_initstate(ifp, 0); run_preinit(ifp); iff = ifp; @@ -1722,7 +1722,7 @@ printpidfile: len = control_send(&ctx, argc, argv); control_close(&ctx); if (len > 0) { - logdebug("send OK"); + logdebugx("send OK"); goto exit_success; } else { logerr("%s: control_send", __func__); @@ -1801,7 +1801,7 @@ printpidfile: } #endif - logdebug(PACKAGE "-" VERSION " starting"); + logdebugx(PACKAGE "-" VERSION " starting"); ctx.options |= DHCPCD_STARTED; #ifdef USE_SIGNALS if (eloop_signal_set_cb(ctx.eloop, @@ -1853,7 +1853,7 @@ printpidfile: logfunc_t *logfunc; logfunc = ctx.options & DHCPCD_INACTIVE ? - logdebug : logerrx; + logdebugx : logerrx; logfunc("no valid interfaces found"); } else goto exit_failure; @@ -1902,7 +1902,7 @@ printpidfile: logfunc_t *logfunc; logfunc = ctx.options & DHCPCD_INACTIVE ? - logdebug : logwarnx; + logdebugx : logwarnx; logfunc("no interfaces have a carrier"); if (dhcpcd_daemonise(&ctx)) goto exit_success; diff --git a/src/if-bsd.c b/src/if-bsd.c index 89e0fae9..6ba1b5e8 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -1346,7 +1346,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp) if (!(ctx->options & DHCPCD_TEST) && flags & ND6_IFF_AUTO_LINKLOCAL) { - logdebug("%s: disabling Kernel IPv6 auto " + logdebugx("%s: disabling Kernel IPv6 auto " "link-local support", ifp->name); flags &= ~ND6_IFF_AUTO_LINKLOCAL; @@ -1364,7 +1364,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp) if (!(ctx->options & DHCPCD_TEST) && flags & ND6_IFF_ACCEPT_RTADV) { - logdebug("%s: disabling Kernel IPv6 RA support", + logdebugx("%s: disabling Kernel IPv6 RA support", ifp->name); flags &= ~ND6_IFF_ACCEPT_RTADV; } @@ -1435,7 +1435,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp) else logerr("IPV6CTL_ACCEPT_RTADV"); else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) { - logdebug("disabling Kernel IPv6 RA support"); + logdebugx("disabling Kernel IPv6 RA support"); if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) { logerr("IPV6CTL_ACCEPT_RTADV"); return ra; diff --git a/src/if-linux.c b/src/if-linux.c index b42b17f4..424da589 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -1645,7 +1645,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp) else if (!(ctx->options & DHCPCD_TEST)) { if (if_disable_autolinklocal(ctx, ifp->index) == -1) logdebug("%s: if_disable_autolinklocal: %s", - ifp->name, strerror(errno)); + ifp->name); } if (ifp) ifname = ifp->name; @@ -1665,13 +1665,13 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp) snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname); ra = check_proc_int(path); if (ra == -1) { - logfunc_t *logfunc = errno == ENOENT? logdebug : logwarnx; + logfunc_t *logfunc = errno == ENOENT? logdebug : logwarn; /* The sysctl probably doesn't exist, but this isn't an * error as such so just log it and continue */ - logfunc("%s: %s", path, strerror(errno)); + logfunc("%s", path); } else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) { - logdebug("%s: disabling kernel IPv6 RA support", ifname); + logdebugx("%s: disabling kernel IPv6 RA support", ifname); if (write_path(path, "0") == -1) { logerr("%s: %s", __func__, path); return ra; diff --git a/src/if.c b/src/if.c index 477f9c28..71385eef 100644 --- a/src/if.c +++ b/src/if.c @@ -359,14 +359,9 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) } if (if_vimaster(ctx, spec.devname) == 1) { - if (argc) - logerr("%s: is a Virtual Interface Master, " - "skipping", - spec.devname); - else - logdebug("%s: is a Virtual Interface Master, " - "skipping", - spec.devname); + logfunc_t *logfunc = argc != 0 ? logerrx : logdebugx; + logfunc("%s: is a Virtual Interface Master, skipping", + spec.devname); continue; } @@ -416,7 +411,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) ctx->ifac == 0 && active && !if_hasconf(ctx, ifp->name)) { - logdebug("%s: ignoring due to" + logdebugx("%s: ignoring due to" " interface type and" " no config", ifp->name); diff --git a/src/ipv4.c b/src/ipv4.c index 6a1aed15..e549f474 100644 --- a/src/ipv4.c +++ b/src/ipv4.c @@ -461,7 +461,7 @@ ipv4_deladdr(struct ipv4_addr *addr, int keeparp) UNUSED(keeparp); #endif - logdebug("%s: deleting IP address %s", + logdebugx("%s: deleting IP address %s", addr->iface->name, addr->saddr); r = if_address(RTM_DELADDR, addr); @@ -627,10 +627,10 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr, return NULL; } if (blank) - logdebug("%s: aliased %s", ia->alias, ia->saddr); + logdebugx("%s: aliased %s", ia->alias, ia->saddr); #endif - logdebug("%s: adding IP address %s broadcast %s", + logdebugx("%s: adding IP address %s broadcast %s", ifp->name, ia->saddr, inet_ntoa(*bcast)); if (if_address(RTM_NEWADDR, ia) == -1) { if (errno != EEXIST) @@ -780,7 +780,7 @@ ipv4_applyaddr(void *arg) if (ia && ia->mask.s_addr == lease->mask.s_addr && ia->brd.s_addr == lease->brd.s_addr) - logdebug("%s: IP address %s already exists", + logdebugx("%s: IP address %s already exists", ifp->name, ia->saddr); else { #if __linux__ diff --git a/src/ipv4ll.c b/src/ipv4ll.c index e9b50ad8..b7d3ca68 100644 --- a/src/ipv4ll.c +++ b/src/ipv4ll.c @@ -202,7 +202,7 @@ ipv4ll_probed(struct arp_state *astate) #ifdef IN_IFF_NOTREADY if (ia->addr_flags & IN_IFF_NOTREADY) return; - logdebug("%s: DAD completed for %s", + logdebugx("%s: DAD completed for %s", ifp->name, inet_ntoa(astate->addr)); #endif test: @@ -297,7 +297,7 @@ ipv4ll_conflicted(struct arp_state *astate, const struct arp_msg *amsg) state->addr->addr.s_addr, state->addr->addr.s_addr) == -1) logerr(__func__); else { - logdebug("%s: defended IPv4LL address %s", + logdebugx("%s: defended IPv4LL address %s", ifp->name, state->addr->saddr); state->defend = now; return; diff --git a/src/ipv6.c b/src/ipv6.c index 7acd06de..b7986140 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -635,7 +635,7 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now) ipv6_iffindaddr(ap->iface, &ap->addr, IN6_IFF_NOTUSEABLE)) ap->flags |= IPV6_AF_DADCOMPLETED; - logfunc = ap->flags & IPV6_AF_NEW ? loginfo : logdebug; + logfunc = ap->flags & IPV6_AF_NEW ? loginfo : logdebugx; logfunc("%s: adding %saddress %s", ap->iface->name, #ifdef IPV6_AF_TEMPORARY ap->flags & IPV6_AF_TEMPORARY ? "temporary " : "", @@ -645,16 +645,16 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now) ap->saddr); if (ap->prefix_pltime == ND6_INFINITE_LIFETIME && ap->prefix_vltime == ND6_INFINITE_LIFETIME) - logdebug("%s: pltime infinity, vltime infinity", + logdebugx("%s: pltime infinity, vltime infinity", ap->iface->name); else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME) - logdebug("%s: pltime infinity, vltime %"PRIu32" seconds", + logdebugx("%s: pltime infinity, vltime %"PRIu32" seconds", ap->iface->name, ap->prefix_vltime); else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME) - logdebug("%s: pltime %"PRIu32"seconds, vltime infinity", + logdebugx("%s: pltime %"PRIu32"seconds, vltime infinity", ap->iface->name, ap->prefix_pltime); else - logdebug("%s: pltime %"PRIu32" seconds, vltime %"PRIu32 + logdebugx("%s: pltime %"PRIu32" seconds, vltime %"PRIu32 " seconds", ap->iface->name, ap->prefix_pltime, ap->prefix_vltime); @@ -683,12 +683,12 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now) ap->prefix_vltime -= (uint32_t)n.tv_sec; #if 0 - logdebug("%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld", + logdebugx("%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld", ap->iface->name, (long long)ap->acquired.tv_sec, ap->acquired.tv_nsec, (long long)now->tv_sec, now->tv_nsec, (long long)n.tv_sec, n.tv_nsec); - logdebug("%s: adj pltime %"PRIu32" seconds, " + logdebugx("%s: adj pltime %"PRIu32" seconds, " "vltime %"PRIu32" seconds", ap->iface->name, ap->prefix_pltime, ap->prefix_vltime); #endif @@ -830,7 +830,7 @@ ipv6_addaddr(struct ipv6_addr *ia, const struct timespec *now) if ((replaced = ipv6_aliasaddr(ia, &replaced_ia)) == -1) return -1; if (blank) - logdebug("%s: aliased %s", ia->alias, ia->saddr); + logdebugx("%s: aliased %s", ia->alias, ia->saddr); #endif if ((r = ipv6_addaddr1(ia, now)) == 0) { @@ -1467,7 +1467,7 @@ ipv6_staticdadcallback(void *arg) logwarnx("%s: DAD detected %s", ia->iface->name, ia->saddr); else if (!wascompleted) { - logdebug("%s: IPv6 static DAD completed", + logdebugx("%s: IPv6 static DAD completed", ia->iface->name); } @@ -2041,7 +2041,7 @@ ipv6_regentempaddr(void *arg) struct ipv6_addr *ia = arg, *ia1; struct timespec tv; - logdebug("%s: regen temp addr %s", ia->iface->name, ia->saddr); + logdebugx("%s: regen temp addr %s", ia->iface->name, ia->saddr); clock_gettime(CLOCK_MONOTONIC, &tv); ia1 = ipv6_createtempaddr(ia, &tv); if (ia1) diff --git a/src/ipv6nd.c b/src/ipv6nd.c index 1fac6446..e46196ca 100644 --- a/src/ipv6nd.c +++ b/src/ipv6nd.c @@ -268,7 +268,7 @@ ipv6nd_sendrsprobe(void *arg) struct in6_pktinfo pi; if (ipv6_linklocal(ifp) == NULL) { - logdebug("%s: delaying Router Solicitation for LL address", + logdebugx("%s: delaying Router Solicitation for LL address", ifp->name); ipv6_addlinklocalcallback(ifp, ipv6nd_sendrsprobe, ifp); return; @@ -302,7 +302,7 @@ ipv6nd_sendrsprobe(void *arg) pi.ipi6_ifindex = ifp->index; memcpy(CMSG_DATA(cm), &pi, sizeof(pi)); - logdebug("%s: sending Router Solicitation", ifp->name); + logdebugx("%s: sending Router Solicitation", ifp->name); if (sendmsg(ctx->nd_fd, &ctx->sndhdr, 0) == -1) { logerr(__func__); /* Allow IPv6ND to continue .... at most a few errors @@ -551,7 +551,7 @@ ipv6nd_scriptrun(struct ra *rap) IN6_IFF_TENTATIVE)) ap->flags |= IPV6_AF_DADCOMPLETED; if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) { - logdebug("%s: waiting for Router Advertisement" + logdebugx("%s: waiting for Router Advertisement" " DAD to complete", rap->iface->name); return 0; @@ -693,7 +693,7 @@ try_script: } if (wascompleted && found) { - logdebug("%s: Router Advertisement DAD " + logdebugx("%s: Router Advertisement DAD " "completed", rap->iface->name); if (ipv6nd_scriptrun(rap)) @@ -741,7 +741,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp, if (ifp == NULL) { #ifdef DEBUG_RS - logdebug("RA for unexpected interface from %s", + logdebugx("RA for unexpected interface from %s", ctx->sfrom); #endif return; @@ -775,14 +775,14 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp, /* We could receive a RA before we sent a RS*/ if (ipv6_linklocal(ifp) == NULL) { #ifdef DEBUG_RS - logdebug("%s: received RA from %s (no link-local)", + logdebugx("%s: received RA from %s (no link-local)", ifp->name, ctx->sfrom); #endif return; } if (ipv6_iffindaddr(ifp, &ctx->from.sin6_addr, IN6_IFF_TENTATIVE)) { - logdebug("%s: ignoring RA from ourself %s", + logdebugx("%s: ignoring RA from ourself %s", ifp->name, ctx->sfrom); return; } @@ -836,7 +836,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp, * routers like to decrease the advertised valid and preferred times * in accordance with the own prefix times which would result in too * much needless log spam. */ - logfunc = new_rap ? loginfo : logdebug, + logfunc = new_rap ? loginfo : logdebugx, logfunc("%s: Router Advertisement from %s", ifp->name, ctx->sfrom); @@ -906,7 +906,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp, switch (ndo.nd_opt_type) { case ND_OPT_PREFIX_INFORMATION: - logfunc = new_data ? logerrx : logdebug; + logfunc = new_data ? logerrx : logdebugx; if (ndo.nd_opt_len != 4) { logfunc("%s: invalid option len for prefix", ifp->name); @@ -1110,7 +1110,7 @@ handle_flag: LOG_DHCP6("dhcp6_start: %s", ifp->name); } else { if (new_data) - logdebug("%s: No DHCPv6 instruction in RA", ifp->name); + logdebugx("%s: No DHCPv6 instruction in RA", ifp->name); nodhcp6: if (ifp->ctx->options & DHCPCD_TEST) { eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS); @@ -1455,7 +1455,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp, if (ifp == NULL) { #ifdef DEBUG_NS - logdebug("NA for unexpected interface from %s", + logdebugx("NA for unexpected interface from %s", ctx->sfrom); #endif return; @@ -1495,14 +1495,14 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp, } if (rap == NULL) { #ifdef DEBUG_NS - logdebug("%s: unexpected NA from %s for %s", + logdebugx("%s: unexpected NA from %s for %s", ifp->name, ctx->sfrom, taddr); #endif return; } #ifdef DEBUG_NS - logdebug("%s: %sNA for %s from %s", + logdebugx("%s: %sNA for %s from %s", ifp->name, is_solicited ? "solicited " : "", taddr, ctx->sfrom); #endif @@ -1657,7 +1657,7 @@ ipv6nd_startrs(struct interface *ifp) tv.tv_nsec = (suseconds_t)arc4random_uniform( MAX_RTR_SOLICITATION_DELAY * NSEC_PER_SEC); timespecnorm(&tv); - logdebug("%s: delaying IPv6 router solicitation for %0.1f seconds", + logdebugx("%s: delaying IPv6 router solicitation for %0.1f seconds", ifp->name, timespec_to_double(&tv)); eloop_timeout_add_tv(ifp->ctx->eloop, &tv, ipv6nd_startrs1, ifp); return; diff --git a/src/logerr.c b/src/logerr.c index eb55217f..1be66484 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -225,6 +225,16 @@ logdebug(const char *fmt, ...) { va_list args; + va_start(args, fmt); + vlogerrmessage(LOG_DEBUG, fmt, args); + va_end(args); +} + +void +logdebugx(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); vlogmessage(LOG_DEBUG, fmt, args); va_end(args); diff --git a/src/logerr.h b/src/logerr.h index ebff3de2..ff22483f 100644 --- a/src/logerr.h +++ b/src/logerr.h @@ -41,6 +41,7 @@ __printflike(1, 2) typedef void logfunc_t(const char *, ...); __printflike(1, 2) void logdebug(const char *, ...); +__printflike(1, 2) void logdebugx(const char *, ...); __printflike(1, 2) void loginfo(const char *, ...); __printflike(1, 2) void logwarn(const char *, ...); __printflike(1, 2) void logwarnx(const char *, ...); diff --git a/src/script.c b/src/script.c index ca93b5e2..f8daf893 100644 --- a/src/script.c +++ b/src/script.c @@ -696,7 +696,7 @@ script_runreason(const struct interface *ifp, const char *reason) argv[0] = ifp->options->script ? ifp->options->script : UNCONST(SCRIPT); argv[1] = NULL; - logdebug("%s: executing `%s' %s", ifp->name, argv[0], reason); + logdebugx("%s: executing `%s' %s", ifp->name, argv[0], reason); /* Resize for PATH and RC_SVCNAME */ svcname = getenv(RC_SVCNAME);