]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
logerr: errx with logging
authorRoy Marples <roy@marples.name>
Sun, 9 Apr 2017 07:44:16 +0000 (08:44 +0100)
committerRoy Marples <roy@marples.name>
Sun, 9 Apr 2017 07:44:16 +0000 (08:44 +0100)
Had a few complaints that the lastlog option was dropped.
It's now been restored, but with a new way of logging which is
the same as errx(3) as found on the BSD platforms but the output
also goes to the logging option of choice.

This allows the function to define the log priority for syslog
and there is no more need to specify %m.
In turn, this makes the code needed to write error messages
a lot shorter than before.

loginfo and logdebug have no optional x suffix because they are not
meant to record errors, unlike logerr and logwarn.

27 files changed:
src/Makefile
src/arp.c
src/bpf.c
src/common.c
src/control.c
src/dev.c
src/dhcp-common.c
src/dhcp.c
src/dhcp6.c
src/dhcpcd.8.in
src/dhcpcd.c
src/dhcpcd.conf.5.in
src/dhcpcd.h
src/duid.c
src/if-bsd.c
src/if-linux.c
src/if-options.c
src/if-options.h
src/if.c
src/ipv4.c
src/ipv4ll.c
src/ipv6.c
src/ipv6nd.c
src/logerr.c [new file with mode: 0644]
src/logerr.h [new file with mode: 0644]
src/route.c
src/script.c

index 39709361061f5259c65c54b7894a365507979de0..248cce57cc3085de71f37d7b0f2f0ce1d2e3f013 100644 (file)
@@ -1,7 +1,7 @@
 # dhcpcd Makefile
 
 PROG=          dhcpcd
-SRCS=          common.c control.c dhcpcd.c duid.c eloop.c
+SRCS=          common.c control.c dhcpcd.c duid.c eloop.c logerr.c
 SRCS+=         if.c if-options.c sa.c route.c
 SRCS+=         dhcp-common.c script.c
 
index 0e19aaf52805d9a61468702f18097e1509976cd4..02047bfed76297687bbf2517d2a52c5fa0ea9608 100644 (file)
--- a/src/arp.c
+++ b/src/arp.c
@@ -38,7 +38,6 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 5
@@ -52,6 +51,7 @@
 #include "if.h"
 #include "if-options.h"
 #include "ipv4ll.h"
+#include "logerr.h"
 
 #if defined(ARP) && (!defined(KERNEL_RFC5227) || defined(ARPING))
 #define ARP_LEN                                                                      \
@@ -152,7 +152,7 @@ arp_packet(struct interface *ifp, uint8_t *data, size_t len)
        }
        if (ifn) {
 #ifdef ARP_DEBUG
-               syslog(LOG_DEBUG, "%s: ignoring ARP from self", ifp->name);
+               logdebug("%s: ignoring ARP from self", ifp->name);
 #endif
                return;
        }
@@ -202,7 +202,7 @@ arp_read(void *arg)
        while (!(flags & BPF_EOF)) {
                bytes = bpf_read(ifp, state->fd, buf, sizeof(buf), &flags);
                if (bytes == -1) {
-                       syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+                       logerr("%s: %s", __func__, ifp->name);
                        arp_close(ifp);
                        return;
                }
@@ -222,7 +222,7 @@ arp_open(struct interface *ifp)
        if (state->fd == -1) {
                state->fd = bpf_open(ifp, bpf_arp);
                if (state->fd == -1) {
-                       syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+                       logerr("%s: %s", __func__, ifp->name);
                        return -1;
                }
                eloop_event_add(ifp->ctx->eloop, state->fd, arp_read, ifp);
@@ -256,13 +256,12 @@ arp_probe1(void *arg)
                tv.tv_nsec = 0;
                eloop_timeout_add_tv(ifp->ctx->eloop, &tv, arp_probed, astate);
        }
-       syslog(LOG_DEBUG,
-           "%s: ARP probing %s (%d of %d), next in %0.1f seconds",
+       logdebug("%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));
        if (arp_request(ifp, 0, astate->addr.s_addr) == -1)
-               syslog(LOG_ERR, "send_arp: %m");
+               logerr(__func__);
 }
 
 void
@@ -270,7 +269,7 @@ arp_probe(struct arp_state *astate)
 {
 
        if (arp_open(astate->iface) == -1) {
-               syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+               logerr(__func__);
                return;
        } else {
                const struct iarp_state *state = ARP_CSTATE(astate->iface);
@@ -278,7 +277,7 @@ arp_probe(struct arp_state *astate)
                bpf_arp(astate->iface, state->fd);
        }
        astate->probes = 0;
-       syslog(LOG_DEBUG, "%s: probing for %s",
+       logdebug("%s: probing for %s",
            astate->iface->name, inet_ntoa(astate->addr));
        arp_probe1(astate);
 }
@@ -311,18 +310,16 @@ arp_announce1(void *arg)
        astate->claims++;
 #else
        if (++astate->claims < ANNOUNCE_NUM)
-               syslog(LOG_DEBUG,
-                   "%s: ARP announcing %s (%d of %d), "
+               logdebug("%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
-               syslog(LOG_DEBUG,
-                   "%s: ARP announcing %s (%d of %d)",
+               logdebug("%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)
-               syslog(LOG_ERR, "arp_request: %m");
+               logerr(__func__);
 #endif
        eloop_timeout_add_sec(ifp->ctx->eloop, ANNOUNCE_WAIT,
            astate->claims < ANNOUNCE_NUM ? arp_announce1 : arp_announced,
@@ -335,7 +332,7 @@ arp_announce(struct arp_state *astate)
 
 #ifndef KERNEL_RFC5227
        if (arp_open(astate->iface) == -1) {
-               syslog(LOG_ERR, "%s: %s: %m", __func__, astate->iface->name);
+               logerr(__func__);
                return;
        }
 #endif
@@ -352,13 +349,13 @@ arp_report_conflicted(const struct arp_state *astate,
        if (amsg != NULL) {
                char buf[HWADDR_LEN * 3];
 
-               syslog(LOG_ERR, "%s: hardware address %s claims %s",
+               logerrx("%s: hardware address %s claims %s",
                    astate->iface->name,
                    hwaddr_ntoa(amsg->sha, astate->iface->hwlen,
                    buf, sizeof(buf)),
                    inet_ntoa(astate->failed));
        } else
-               syslog(LOG_ERR, "%s: DAD detected %s",
+               logerrx("%s: DAD detected %s",
                    astate->iface->name, inet_ntoa(astate->failed));
 }
 
@@ -389,7 +386,7 @@ arp_new(struct interface *ifp, const struct in_addr *addr)
                ifp->if_data[IF_DATA_ARP] = malloc(sizeof(*state));
                state = ARP_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return NULL;
                }
                state->fd = -1;
@@ -400,7 +397,7 @@ arp_new(struct interface *ifp, const struct in_addr *addr)
        }
 
        if ((astate = calloc(1, sizeof(*astate))) == NULL) {
-               syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
+               logerr(__func__);
                return NULL;
        }
        astate->iface = ifp;
index 73a9275b55eaad0cbc7f18db899791be6c349a55..9ab16ec59cc57415c12f3bfa228a6b2b38626722 100644 (file)
--- a/src/bpf.c
+++ b/src/bpf.c
 #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 (*filter)(struct interface *, int))
                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;
        }
 
@@ -474,7 +474,7 @@ 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,
index 35cd9b182ec38c37598f8a95b2c7bb45078d10ae..4a5c6ec747eecd1056453e54b555735eca116151 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
 #include "common.h"
 #include "dhcpcd.h"
 #include "if-options.h"
+#include "logerr.h"
 
 /* Most route(4) messages are less than 256 bytes. */
 #define IOVEC_BUFSIZ   256
@@ -63,9 +63,8 @@ setvar(char **e, const char *prefix, const char *var, const char *value)
 
        if (prefix)
                len += strlen(prefix) + 1;
-       *e = malloc(len);
-       if (*e == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+       if ((*e = malloc(len)) == NULL) {
+               logerr(__func__);
                return -1;
        }
        if (prefix)
index 2613e7fa4acb226f49c94f944a2de801e2f52ea5..05ca1ac39c13743e676b474fa4f8de7885937596 100644 (file)
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -45,6 +44,7 @@
 #include "control.h"
 #include "eloop.h"
 #include "if.h"
+#include "logerr.h"
 
 #ifndef SUN_LEN
 #define SUN_LEN(su) \
@@ -141,7 +141,7 @@ control_handle_data(void *arg)
                }
                *ap = NULL;
                if (dhcpcd_handleargs(fd->ctx, fd, argc, argvp) == -1) {
-                       syslog(LOG_ERR, "%s: dhcpcd_handleargs: %m", __func__);
+                       logerr(__func__);
                        if (errno != EINTR && errno != EAGAIN) {
                                control_delete(fd);
                                return;
@@ -366,7 +366,7 @@ control_writeone(void *arg)
        iov[1].iov_base = data->data;
        iov[1].iov_len = data->data_len;
        if (writev(fd->fd, iov, 2) == -1) {
-               syslog(LOG_ERR, "%s: writev fd %d: %m", __func__, fd->fd);
+               logerr(__func__);
                if (errno != EINTR && errno != EAGAIN)
                        control_delete(fd);
                return;
index c9ae656ed59e3eb25aaeb23c1e8c097d5192b21d..452f3cd642d20c691b2193279d31edf4a7594d94 100644 (file)
--- a/src/dev.c
+++ b/src/dev.c
@@ -28,7 +28,6 @@
 #include <dlfcn.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <string.h>
 
 #define _INDEV
@@ -36,6 +35,7 @@
 #include "dev.h"
 #include "eloop.h"
 #include "dhcpcd.h"
+#include "logerr.h"
 
 int
 dev_initialized(struct dhcpcd_ctx *ctx, const char *ifname)
@@ -61,7 +61,7 @@ dev_stop1(struct dhcpcd_ctx *ctx, int stop)
 
        if (ctx->dev) {
                if (stop)
-                       syslog(LOG_DEBUG, "dev: unloaded %s", ctx->dev->name);
+                       logdebug("dev: unloaded %s", ctx->dev->name);
                eloop_event_delete(ctx->eloop, ctx->dev_fd);
                ctx->dev->stop();
                free(ctx->dev);
@@ -93,18 +93,18 @@ dev_start2(struct dhcpcd_ctx *ctx, const char *name)
        snprintf(file, sizeof(file), DEVDIR "/%s", name);
        h = dlopen(file, RTLD_LAZY);
        if (h == NULL) {
-               syslog(LOG_ERR, "dlopen: %s", dlerror());
+               logerrx("dlopen: %s", dlerror());
                return -1;
        }
        fptr = (void (*)(struct dev *, const struct dev_dhcpcd *))
            dlsym(h, "dev_init");
        if (fptr == NULL) {
-               syslog(LOG_ERR, "dlsym: %s", dlerror());
+               logerrx("dlsym: %s", dlerror());
                dlclose(h);
                return -1;
        }
        if ((ctx->dev = calloc(1, sizeof(*ctx->dev))) == NULL) {
-               syslog(LOG_ERR, "%s: calloc: %m", __func__);
+               logerr("%s: calloc", __func__);
                dlclose(h);
                return -1;
        }
@@ -116,7 +116,7 @@ dev_start2(struct dhcpcd_ctx *ctx, const char *name)
                dlclose(h);
                return -1;
        }
-       syslog(LOG_INFO, "dev: loaded %s", ctx->dev->name);
+       loginfo("dev: loaded %s", ctx->dev->name);
        ctx->dev_handle = h;
        return r;
 }
@@ -129,7 +129,7 @@ dev_start1(struct dhcpcd_ctx *ctx)
        int r;
 
        if (ctx->dev) {
-               syslog(LOG_ERR, "dev: already started %s", ctx->dev->name);
+               logerrx("dev: already started %s", ctx->dev->name);
                return -1;
        }
 
@@ -138,7 +138,7 @@ dev_start1(struct dhcpcd_ctx *ctx)
 
        dp = opendir(DEVDIR);
        if (dp == NULL) {
-               syslog(LOG_DEBUG, "dev: %s: %m", DEVDIR);
+               logdebug("dev: %s: %m", DEVDIR);
                return 0;
        }
 
@@ -171,8 +171,7 @@ dev_start(struct dhcpcd_ctx *ctx)
 {
 
        if (ctx->dev_fd != -1) {
-               syslog(LOG_ERR, "%s: already started on fd %d", __func__,
-                   ctx->dev_fd);
+               logerrx("%s: already started on fd %d", __func__, ctx->dev_fd);
                return ctx->dev_fd;
        }
 
@@ -181,7 +180,7 @@ dev_start(struct dhcpcd_ctx *ctx)
                if (eloop_event_add(ctx->eloop, ctx->dev_fd,
                    dev_handle_data, ctx) == -1)
                {
-                       syslog(LOG_ERR, "%s: eloop_event_add: %m", __func__);
+                       logerr(__func__);
                        dev_stop1(ctx, 1);
                        return -1;
                }
index b4a1af053e055ad6738a7fb89e17845540455e27..da50aac38b50eba6caa7cc05206fffa36cb4f362 100644 (file)
@@ -34,7 +34,6 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #include <arpa/nameser.h> /* after normal includes for sunos */
@@ -46,6 +45,7 @@
 #include "dhcp.h"
 #include "if.h"
 #include "ipv6.h"
+#include "logerr.h"
 
 /* Support very old arpa/nameser.h as found in OpenBSD */
 #ifndef NS_MAXDNAME
@@ -921,7 +921,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                            prefix, opt, 1, od, ol, ifname))
                                return 1;
                        else
-                               syslog(LOG_ERR, "%s: %s %d: %m",
+                               logerr("%s: %s %d",
                                    ifname, __func__, opt->option);
                }
                return 0;
@@ -932,7 +932,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                if (opt->type & OT_INDEX) {
                        if (opt->index > 999) {
                                errno = ENOBUFS;
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                return 0;
                        }
                }
@@ -940,7 +940,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                    (opt->type & OT_INDEX ? 3 : 0);
                pfx = malloc(e);
                if (pfx == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return 0;
                }
                if (opt->type & OT_INDEX)
@@ -958,8 +958,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                eo = dhcp_optlen(eopt, ol);
                if (eo == -1) {
                        if (env == NULL)
-                               syslog(LOG_ERR,
-                                   "%s: %s %d.%d/%zu: "
+                               logerrx("%s: %s %d.%d/%zu: "
                                    "malformed embedded option",
                                    ifname, __func__, opt->option,
                                    eopt->option, i);
@@ -973,8 +972,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                         * option which is optional. */
                        if (env == NULL &&
                            (ol != 0 || !(eopt->type & OT_OPTIONAL)))
-                               syslog(LOG_ERR,
-                                   "%s: %s %d.%d/%zu: missing embedded option",
+                               logerrx("%s: %s %d.%d/%zu: missing embedded option",
                                    ifname, __func__, opt->option,
                                    eopt->option, i);
                        goto out;
@@ -988,8 +986,7 @@ dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
                            pfx, eopt, ov, od, (size_t)eo, ifname))
                                n++;
                        else if (env == NULL)
-                               syslog(LOG_ERR,
-                                   "%s: %s %d.%d/%zu: %m",
+                               logerr("%s: %s %d.%d/%zu",
                                    ifname, __func__,
                                    opt->option, eopt->option, i);
                }
index 204e99da1d62770fce589730cb1e725150cf8126..7073ebd6cd2fde20f0fe83e57910c6c552c5147a 100644 (file)
@@ -49,7 +49,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 2
@@ -65,6 +64,7 @@
 #include "if.h"
 #include "ipv4.h"
 #include "ipv4ll.h"
+#include "logerr.h"
 #include "sa.h"
 #include "script.h"
 
@@ -600,8 +600,7 @@ get_option_routes(struct rt_head *routes, struct interface *ifp,
                if (!(ifo->options & DHCPCD_CSR_WARNED) &&
                    !(state->added & STATE_FAKE))
                {
-                       syslog(LOG_DEBUG,
-                           "%s: using %sClassless Static Routes",
+                       logdebug("%s: using %sClassless Static Routes",
                            ifp->name, csr);
                        ifo->options |= DHCPCD_CSR_WARNED;
                }
@@ -753,10 +752,10 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
 #endif
 
        if ((mtu = if_getmtu(ifp)) == -1)
-               syslog(LOG_ERR, "%s: if_getmtu: %m", ifp->name);
+               logerr("%s: if_getmtu", ifp->name);
        else if (mtu < MTU_MIN) {
                if (if_setmtu(ifp, MTU_MIN) == -1)
-                       syslog(LOG_ERR, "%s: if_setmtu: %m", ifp->name);
+                       logerr("%s: if_setmtu", ifp->name);
                mtu = MTU_MIN;
        }
 
@@ -1014,8 +1013,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
                        {
                                AREA_FIT(vivco->len);
                                if (vivco->len + 2 + *lp > 255) {
-                                       syslog(LOG_ERR,
-                                           "%s: VIVCO option too big",
+                                       logerrx("%s: VIVCO option too big",
                                            ifp->name);
                                        free(bootp);
                                        return -1;
@@ -1084,7 +1082,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
                        alen = -1;
                }
                if (alen == -1)
-                       syslog(LOG_ERR, "%s: dhcp_auth_encode: %m", ifp->name);
+                       logerr("%s: dhcp_auth_encode", ifp->name);
                else if (alen != 0) {
                        auth_len = (uint8_t)alen;
                        AREA_CHECK(auth_len);
@@ -1118,7 +1116,7 @@ make_message(struct bootp **bootpm, const struct interface *ifp, uint8_t type)
        return (ssize_t)len;
 
 toobig:
-       syslog(LOG_ERR, "%s: DHCP message too big", ifp->name);
+       logerrx("%s: DHCP message too big", ifp->name);
        free(bootp);
        return -1;
 }
@@ -1130,8 +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);
 
-       syslog(LOG_DEBUG, "%s: writing lease `%s'",
-           ifp->name, state->leasefile);
+       logdebug("%s: writing lease `%s'", ifp->name, state->leasefile);
 
        fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (fd == -1)
@@ -1167,14 +1164,14 @@ read_lease(struct interface *ifp, struct bootp **bootp)
        }
        if (fd == -1) {
                if (errno != ENOENT)
-                       syslog(LOG_ERR, "%s: open `%s': %m",
+                       logerr("%s: open `%s'",
                            ifp->name, state->leasefile);
                return 0;
        }
        if (state->leasefile[0] == '\0')
-               syslog(LOG_DEBUG, "reading standard input");
+               logdebug("reading standard input");
        else
-               syslog(LOG_DEBUG, "%s: reading lease `%s'",
+               logdebug("%s: reading lease `%s'",
                    ifp->name, state->leasefile);
 
        bytes = dhcp_read_lease_fd(fd, (void **)&lease);
@@ -1182,7 +1179,7 @@ read_lease(struct interface *ifp, struct bootp **bootp)
                close(fd);
        if (bytes == 0) {
                free(lease);
-               syslog(LOG_ERR, "%s: dhcp_read_lease_fd: %m", __func__);
+               logerr("%s: dhcp_read_lease_fd", __func__);
                return 0;
        }
 
@@ -1193,7 +1190,7 @@ read_lease(struct interface *ifp, struct bootp **bootp)
         * scribble whatever in the stored lease file. */
        if (bytes < offsetof(struct bootp, vend) + 4) {
                free(lease);
-               syslog(LOG_ERR, "%s: truncated lease", __func__);
+               logerrx("%s: %s: truncated lease", ifp->name, __func__);
                return 0;
        }
 
@@ -1213,21 +1210,19 @@ 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)
                {
-                       syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
-                           ifp->name);
+                       logdebug("%s: dhcp_auth_validate", ifp->name);
                        free(lease);
                        return 0;
                }
                if (state->auth.token)
-                       syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+                       logdebug("%s: validated using 0x%08" PRIu32,
                            ifp->name, state->auth.token->secretid);
                else
-                       syslog(LOG_DEBUG, "%s: accepted reconfigure key",
-                           ifp->name);
+                       logdebug("%s: accepted reconfigure key", ifp->name);
        } else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
            DHCPCD_AUTH_SENDREQUIRE)
        {
-               syslog(LOG_ERR, "%s: authentication now required", ifp->name);
+               logerrx("%s: authentication now required", ifp->name);
                free(lease);
                return 0;
        }
@@ -1690,7 +1685,7 @@ send_message(struct interface *ifp, uint8_t type,
                /* No carrier? Don't bother sending the packet. */
                if (ifp->carrier == LINK_DOWN)
                        return;
-               syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
+               logdebug("%s: sending %s with xid 0x%x",
                    ifp->name,
                    ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
                    state->xid);
@@ -1710,8 +1705,7 @@ send_message(struct interface *ifp, uint8_t type,
                 * However, we do need to advance the timeout. */
                if (ifp->carrier == LINK_DOWN)
                        goto fail;
-               syslog(LOG_DEBUG,
-                   "%s: sending %s (xid 0x%x), next in %0.1f seconds",
+               logdebug("%s: sending %s (xid 0x%x), next in %0.1f seconds",
                    ifp->name,
                    ifo->options & DHCPCD_BOOTP ? "BOOTP" : get_dhcp_op(type),
                    state->xid,
@@ -1735,8 +1729,7 @@ send_message(struct interface *ifp, uint8_t type,
                s = dhcp_openudp(ifp);
                if (s == -1) {
                        if (errno != EADDRINUSE)
-                               syslog(LOG_ERR, "%s: dhcp_openudp: %m",
-                                   ifp->name);
+                               logerr("%s: dhcp_openudp", ifp->name);
                        /* We cannot renew */
                        state->addr = NULL;
                }
@@ -1762,13 +1755,13 @@ send_message(struct interface *ifp, uint8_t type,
                r = sendto(s, (uint8_t *)bootp, len, 0,
                    (struct sockaddr *)&sin, sizeof(sin));
                if (r == -1)
-                       syslog(LOG_ERR, "%s: dhcp_sendpacket: %m", ifp->name);
+                       logerr("%s: dhcp_sendpacket", ifp->name);
        } else {
                size_t ulen;
 
                udp = dhcp_makeudppacket(&ulen, (uint8_t *)bootp, len, from,to);
                if (udp == NULL) {
-                       syslog(LOG_ERR, "dhcp_makeudppacket: %m");
+                       logerr("%s: dhcp_makeudppacket", ifp->name);
                        r = 0;
                } else {
                        r = bpf_send(ifp, state->bpf_fd,
@@ -1781,7 +1774,7 @@ send_message(struct interface *ifp, uint8_t type,
                 * As such we remove it from consideration without actually
                 * stopping the interface. */
                if (r == -1) {
-                       syslog(LOG_ERR, "%s: if_sendraw: %m", ifp->name);
+                       logerr("%s: if_sendraw", ifp->name);
                        switch(errno) {
                        case ENETDOWN:
                        case ENETRESET:
@@ -1864,10 +1857,10 @@ dhcp_discover(void *arg)
                    ifo->reboot, ipv4ll_start, ifp);
 #endif
        if (ifo->options & DHCPCD_REQUEST)
-               syslog(LOG_INFO, "%s: soliciting a DHCP lease (requesting %s)",
+               loginfo("%s: soliciting a DHCP lease (requesting %s)",
                    ifp->name, inet_ntoa(ifo->req_addr));
        else
-               syslog(LOG_INFO, "%s: soliciting a %s lease",
+               loginfo("%s: soliciting a %s lease",
                    ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
        send_discover(ifp);
 }
@@ -1901,13 +1894,13 @@ dhcp_leaseextend(struct interface *ifp)
                        return -1;
 #endif
 
-               syslog(LOG_WARNING,
-                   "%s: extending lease until DaD failure or DHCP", ifp->name);
+               logwarnx("%s: extending lease until DaD failure or DHCP",
+                   ifp->name);
                return 0;
        }
 #endif
 
-       syslog(LOG_WARNING, "%s: extending lease", ifp->name);
+       logwarnx("%s: extending lease", ifp->name);
        return 0;
 }
 
@@ -1928,11 +1921,11 @@ dhcp_expire(void *arg)
 {
        struct interface *ifp = arg;
 
-       syslog(LOG_ERR, "%s: DHCP lease expired", ifp->name);
+       logerrx("%s: DHCP lease expired", ifp->name);
        if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND) {
                if (dhcp_leaseextend(ifp) == 0)
                        return;
-               syslog(LOG_ERR, "%s: dhcp_leaseextend: %m", ifp->name);
+               logerr(__func__);
        }
        dhcp_expire1(ifp);
 }
@@ -1965,7 +1958,7 @@ dhcp_startrenew(void *arg)
        eloop_timeout_delete(ifp->ctx->eloop, dhcp_startrenew, ifp);
 
        lease = &state->lease;
-       syslog(LOG_DEBUG, "%s: renewing lease of %s", ifp->name,
+       logdebug("%s: renewing lease of %s", ifp->name,
            inet_ntoa(lease->addr));
        state->state = DHS_RENEW;
        dhcp_new_xid(ifp);
@@ -1987,8 +1980,8 @@ dhcp_rebind(void *arg)
        struct dhcp_state *state = D_STATE(ifp);
        struct dhcp_lease *lease = &state->lease;
 
-       syslog(LOG_WARNING, "%s: failed to renew DHCP, rebinding", ifp->name);
-       syslog(LOG_DEBUG, "%s: expire in %"PRIu32" seconds",
+       logwarnx("%s: failed to renew DHCP, rebinding", ifp->name);
+       logdebug("%s: expire in %"PRIu32" seconds",
            ifp->name, lease->leasetime - lease->rebindtime);
        state->state = DHS_REBIND;
        eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
@@ -2036,7 +2029,7 @@ dhcp_arp_probed(struct arp_state *astate)
        if (state->state == DHS_BOUND)
                return;
 
-       syslog(LOG_DEBUG, "%s: DAD completed for %s",
+       logdebug("%s: DAD completed for %s",
            ifp->name, inet_ntoa(astate->addr));
        if (state->state != DHS_INFORM)
                dhcp_bind(ifp);
@@ -2183,13 +2176,13 @@ dhcp_bind(struct interface *ifp)
        }
        get_lease(ifp, lease, state->new, state->new_len);
        if (ifo->options & DHCPCD_STATIC) {
-               syslog(LOG_INFO, "%s: using static address %s/%d",
+               loginfo("%s: using static address %s/%d",
                    ifp->name, inet_ntoa(lease->addr),
                    inet_ntocidr(lease->mask));
                lease->leasetime = ~0U;
                state->reason = "STATIC";
        } else if (ifo->options & DHCPCD_INFORM) {
-               syslog(LOG_INFO, "%s: received approval for %s",
+               loginfo("%s: received approval for %s",
                    ifp->name, inet_ntoa(lease->addr));
                lease->leasetime = ~0U;
                state->reason = "INFORM";
@@ -2200,12 +2193,11 @@ dhcp_bind(struct interface *ifp)
                        lease->renewaltime =
                            lease->rebindtime =
                            lease->leasetime;
-                       syslog(LOG_INFO, "%s: leased %s for infinity",
-                           ifp->name, inet_ntoa(lease->addr));
+                       loginfo("%s: leased %s for infinity",
+                          ifp->name, inet_ntoa(lease->addr));
                } else {
                        if (lease->leasetime < DHCP_MIN_LEASE) {
-                               syslog(LOG_WARNING,
-                                   "%s: minimum lease is %d seconds",
+                               logwarnx("%s: minimum lease is %d seconds",
                                    ifp->name, DHCP_MIN_LEASE);
                                lease->leasetime = DHCP_MIN_LEASE;
                        }
@@ -2215,8 +2207,7 @@ dhcp_bind(struct interface *ifp)
                        else if (lease->rebindtime >= lease->leasetime) {
                                lease->rebindtime =
                                    (uint32_t)(lease->leasetime * T2);
-                               syslog(LOG_WARNING,
-                                   "%s: rebind time greater than lease "
+                               logwarnx("%s: rebind time greater than lease "
                                    "time, forcing to %"PRIu32" seconds",
                                    ifp->name, lease->rebindtime);
                        }
@@ -2226,17 +2217,20 @@ dhcp_bind(struct interface *ifp)
                        else if (lease->renewaltime > lease->rebindtime) {
                                lease->renewaltime =
                                    (uint32_t)(lease->leasetime * T1);
-                               syslog(LOG_WARNING,
-                                   "%s: renewal time greater than rebind "
-                                   "time, forcing to %"PRIu32" seconds",
+                               logwarnx("%s: renewal time greater than "
+                                   "rebind time, forcing to %"PRIu32" seconds",
                                    ifp->name, lease->renewaltime);
                        }
-                       syslog(state->addr &&
+                       if (state->addr &&
                            lease->addr.s_addr == state->addr->addr.s_addr &&
-                           !(state->added & STATE_FAKE) ?
-                           LOG_DEBUG : LOG_INFO,
-                           "%s: leased %s for %"PRIu32" seconds", ifp->name,
-                           inet_ntoa(lease->addr), lease->leasetime);
+                           !(state->added & STATE_FAKE))
+                               logdebug("%s: leased %s for %"PRIu32" seconds",
+                                   ifp->name, inet_ntoa(lease->addr),
+                                   lease->leasetime);
+                       else
+                               loginfo("%s: leased %s for %"PRIu32" seconds",
+                                   ifp->name, inet_ntoa(lease->addr),
+                                   lease->leasetime);
                }
        }
        if (ifp->ctx->options & DHCPCD_TEST) {
@@ -2267,8 +2261,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);
-               syslog(LOG_DEBUG,
-                   "%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
+               logdebug("%s: renew in %"PRIu32" seconds, rebind in %"PRIu32
                    " seconds",
                    ifp->name, lease->renewaltime, lease->rebindtime);
        }
@@ -2278,7 +2271,7 @@ dhcp_bind(struct interface *ifp)
        if (!state->lease.frominfo &&
            !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
                if (write_lease(ifp, state->new, state->new_len) == -1)
-                       syslog(LOG_ERR, "%s: write_lease: %m", __func__);
+                       logerr(__func__);
 
        ipv4_applyaddr(ifp);
 }
@@ -2289,8 +2282,7 @@ dhcp_lastlease(void *arg)
        struct interface *ifp = arg;
        struct dhcp_state *state = D_STATE(ifp);
 
-       syslog(LOG_INFO,
-           "%s: timed out contacting a DHCP server, using last lease",
+       loginfo("%s: timed out contacting a DHCP server, using last lease",
            ifp->name);
        dhcp_bind(ifp);
        /* If we forked, stop here. */
@@ -2300,7 +2292,7 @@ dhcp_lastlease(void *arg)
        if (ifp->options->options & DHCPCD_LASTLEASE_EXTEND &&
            dhcp_leaseextend(ifp) == -1)
        {
-               syslog(LOG_ERR, "%s: dhcp_leaseextend: %m", ifp->name);
+               logerr("%s: %s", ifp->name, __func__);
                dhcp_expire(ifp);
        }
        dhcp_discover(ifp);
@@ -2366,7 +2358,7 @@ dhcp_arp_address(struct interface *ifp)
                        /* Add the address now, let the kernel handle DAD. */
                        ipv4_addaddr(ifp, &l.addr, &l.mask, &l.brd);
                } else
-                       syslog(LOG_INFO, "%s: waiting for DAD on %s",
+                       loginfo("%s: waiting for DAD on %s",
                            ifp->name, inet_ntoa(addr));
                return 0;
        }
@@ -2375,7 +2367,7 @@ dhcp_arp_address(struct interface *ifp)
                struct dhcp_lease l;
 
                get_lease(ifp, &l, state->offer, state->offer_len);
-               syslog(LOG_INFO, "%s: probing address %s/%d",
+               loginfo("%s: probing address %s/%d",
                    ifp->name, inet_ntoa(l.addr), inet_ntocidr(l.mask));
                /* We need to handle DAD. */
                arp_probe(astate);
@@ -2409,7 +2401,7 @@ dhcp_static(struct interface *ifp)
        if (ifo->req_addr.s_addr == INADDR_ANY &&
            (ia = ipv4_iffindaddr(ifp, NULL, NULL)) == NULL)
        {
-               syslog(LOG_INFO, "%s: waiting for 3rd party to "
+               loginfo("%s: waiting for 3rd party to "
                    "configure IP address", ifp->name);
                state->reason = "3RDPARTY";
                script_runreason(ifp, state->reason);
@@ -2445,8 +2437,8 @@ dhcp_inform(struct interface *ifp)
        if (ifo->req_addr.s_addr == INADDR_ANY) {
                ia = ipv4_iffindaddr(ifp, NULL, NULL);
                if (ia == NULL) {
-                       syslog(LOG_INFO,
-                           "%s: waiting for 3rd party to configure IP address",
+                       loginfo("%s: waiting for 3rd party to "
+                           "configure IP address",
                            ifp->name);
                        if (!(ifp->ctx->options & DHCPCD_TEST)) {
                                state->reason = "3RDPARTY";
@@ -2458,8 +2450,7 @@ dhcp_inform(struct interface *ifp)
                ia = ipv4_iffindaddr(ifp, &ifo->req_addr, &ifo->req_mask);
                if (ia == NULL) {
                        if (ifp->ctx->options & DHCPCD_TEST) {
-                               syslog(LOG_ERR,
-                                   "%s: cannot add IP address in test mode",
+                               logerrx("%s: cannot add IP address in test mode",
                                    ifp->name);
                                return;
                        }
@@ -2521,7 +2512,7 @@ dhcp_reboot(struct interface *ifp)
        state->interval = 0;
 
        if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_DOWN) {
-               syslog(LOG_INFO, "%s: waiting for carrier", ifp->name);
+               loginfo("%s: waiting for carrier", ifp->name);
                return;
        }
        if (ifo->options & DHCPCD_STATIC) {
@@ -2529,7 +2520,7 @@ dhcp_reboot(struct interface *ifp)
                return;
        }
        if (ifo->options & DHCPCD_INFORM) {
-               syslog(LOG_INFO, "%s: informing address of %s",
+               loginfo("%s: informing address of %s",
                    ifp->name, inet_ntoa(state->lease.addr));
                dhcp_inform(ifp);
                return;
@@ -2541,7 +2532,7 @@ dhcp_reboot(struct interface *ifp)
        if (!IS_DHCP(state->offer))
                return;
 
-       syslog(LOG_INFO, "%s: rebinding lease of %s",
+       loginfo("%s: rebinding lease of %s",
            ifp->name, inet_ntoa(state->lease.addr));
        dhcp_new_xid(ifp);
        state->lease.server.s_addr = 0;
@@ -2599,7 +2590,7 @@ dhcp_drop(struct interface *ifp, const char *reason)
                    state->new != NULL &&
                    state->lease.server.s_addr != INADDR_ANY)
                {
-                       syslog(LOG_INFO, "%s: releasing lease of %s",
+                       loginfo("%s: releasing lease of %s",
                            ifp->name, inet_ntoa(state->lease.addr));
                        dhcp_new_xid(ifp);
                        send_message(ifp, DHCP_RELEASE, NULL);
@@ -2662,7 +2653,7 @@ whitelisted_ip(const struct if_options *ifo, in_addr_t addr)
 }
 
 static void
-log_dhcp(int lvl, const char *msg,
+log_dhcp(logfunc_t *logfunc, const char *msg,
     const struct interface *ifp, const struct bootp *bootp, size_t bootp_len,
     const struct in_addr *from, int ad)
 {
@@ -2682,7 +2673,7 @@ log_dhcp(int lvl, const char *msg,
                        tmpl = (al * 4) + 1;
                        tmp = malloc(tmpl);
                        if (tmp == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                free(a);
                                return;
                        }
@@ -2694,7 +2685,7 @@ log_dhcp(int lvl, const char *msg,
                addr.s_addr = bootp->yiaddr;
                a = strdup(inet_ntoa(addr));
                if (a == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return;
                }
        } else
@@ -2709,10 +2700,10 @@ log_dhcp(int lvl, const char *msg,
                print_string(sname, sizeof(sname), OT_STRING | OT_DOMAIN,
                    bootp->sname, sizeof(bootp->sname));
                if (a == NULL)
-                       syslog(lvl, "%s: %s %s %s `%s'",
+                       logfunc("%s: %s %s %s `%s'",
                            ifp->name, msg, tfrom, inet_ntoa(addr), sname);
                else
-                       syslog(lvl, "%s: %s %s %s %s `%s'",
+                       logfunc("%s: %s %s %s %s `%s'",
                            ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
        } else {
                if (r != 0) {
@@ -2720,10 +2711,10 @@ log_dhcp(int lvl, const char *msg,
                        addr = *from;
                }
                if (a == NULL)
-                       syslog(lvl, "%s: %s %s %s",
+                       logfunc("%s: %s %s %s",
                            ifp->name, msg, tfrom, inet_ntoa(addr));
                else
-                       syslog(lvl, "%s: %s %s %s %s",
+                       logfunc("%s: %s %s %s %s",
                            ifp->name, msg, a, tfrom, inet_ntoa(addr));
        }
        free(a);
@@ -2757,7 +2748,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
        /* Handled in our BPF filter. */
 #if 0
        if (bootp->op != BOOTREPLY) {
-               syslog(LOG_DEBUG, "%s: op (%d) is not BOOTREPLY",
+               logdebug("%s: op (%d) is not BOOTREPLY",
                    ifp->name, bootp->op);
                return;
        }
@@ -2767,7 +2758,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
        {
                char buf[sizeof(bootp->chaddr) * 3];
 
-               syslog(LOG_DEBUG, "%s: xid 0x%x is for hwaddr %s",
+               logdebug("%s: xid 0x%x is for hwaddr %s",
                    ifp->name, ntohl(bootp->xid),
                    hwaddr_ntoa(bootp->chaddr, sizeof(bootp->chaddr),
                    buf, sizeof(buf)));
@@ -2780,7 +2771,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) {
-               syslog(LOG_DEBUG, "%s: ignoring DHCP reply (expecting BOOTP)",
+               logdebug("%s: ignoring DHCP reply (expecting BOOTP)",
                    ifp->name);
                return;
        }
@@ -2794,23 +2785,22 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                    (uint8_t *)bootp, bootp_len, 4, type,
                    auth, auth_len) == NULL)
                {
-                       syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
+                       logdebug("%s: dhcp_auth_validate",
                            ifp->name);
-                       LOGDHCP0(LOG_ERR, "authentication failed");
+                       LOGDHCP0(logerrx, "authentication failed");
                        return;
                }
                if (state->auth.token)
-                       syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+                       logdebug("%s: validated using 0x%08" PRIu32,
                            ifp->name, state->auth.token->secretid);
                else
-                       syslog(LOG_INFO, "%s: accepted reconfigure key",
-                           ifp->name);
+                       loginfo("%s: accepted reconfigure key", ifp->name);
        } else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
                if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
-                       LOGDHCP0(LOG_ERR, "no authentication");
+                       LOGDHCP0(logerrx, "no authentication");
                        return;
                }
-               LOGDHCP0(LOG_WARNING, "no authentication");
+               LOGDHCP0(logwarnx, "no authentication");
        }
 #endif
 
@@ -2819,20 +2809,20 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                if (from->s_addr == INADDR_ANY ||
                    from->s_addr == INADDR_BROADCAST)
                {
-                       LOGDHCP(LOG_ERR, "discarding Force Renew");
+                       LOGDHCP(logerrx, "discarding Force Renew");
                        return;
                }
 #ifdef AUTH
                if (auth == NULL) {
-                       LOGDHCP(LOG_ERR, "unauthenticated Force Renew");
+                       LOGDHCP(logerrx, "unauthenticated Force Renew");
                        if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
                                return;
                }
                if (state->state != DHS_BOUND && state->state != DHS_INFORM) {
-                       LOGDHCP(LOG_DEBUG, "not bound, ignoring Force Renew");
+                       LOGDHCP(logdebug, "not bound, ignoring Force Renew");
                        return;
                }
-               LOGDHCP(LOG_INFO, "Force Renew from");
+               LOGDHCP(loginfo, "Force Renew from");
                /* The rebind and expire timings are still the same, we just
                 * enter the renew state early */
                if (state->state == DHS_BOUND)
@@ -2843,7 +2833,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                        dhcp_inform(ifp);
                }
 #else
-               LOGDHCP(LOG_ERR, "unauthenticated Force Renew");
+               LOGDHCP(logerrx, "unauthenticated Force Renew");
 #endif
                return;
        }
@@ -2852,7 +2842,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(LOG_DEBUG, "bound, ignoring");
+               //LOGDHCP(logdebug, "bound, ignoring");
                return;
        }
 
@@ -2860,8 +2850,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)) {
-               syslog(LOG_DEBUG,
-                   "%s: wrong xid 0x%x (expecting 0x%x) from %s",
+               logdebug("%s: wrong xid 0x%x (expecting 0x%x) from %s",
                    ifp->name, ntohl(bootp->xid), state->xid,
                    inet_ntoa(*from));
                return;
@@ -2870,7 +2859,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(LOG_DEBUG, "probing, ignoring");
+               LOGDHCP(logdebug, "probing, ignoring");
                return;
        }
 
@@ -2883,7 +2872,7 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                    get_option_uint8(ifp->ctx, &tmp,
                    bootp, bootp_len, (uint8_t)i) == 0)
                {
-                       LOGDHCP(LOG_WARNING, "reject DHCP");
+                       LOGDHCP(logwarnx, "reject DHCP");
                        return;
                }
        }
@@ -2894,16 +2883,16 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                    get_option_addr(ifp->ctx, &addr,
                    bootp, bootp_len, DHO_SERVERID) == -1)
                {
-                       LOGDHCP(LOG_WARNING, "reject NAK");
+                       LOGDHCP(logwarnx, "reject NAK");
                        return;
                }
 
                /* We should restart on a NAK */
-               LOGDHCP(LOG_WARNING, "NAK:");
+               LOGDHCP(logwarnx, "NAK:");
                if ((msg = get_option_string(ifp->ctx,
                    bootp, bootp_len, DHO_MESSAGE)))
                {
-                       syslog(LOG_WARNING, "%s: message: %s", ifp->name, msg);
+                       logwarnx("%s: message: %s", ifp->name, msg);
                        free(msg);
                }
                if (state->state == DHS_INFORM) /* INFORM should not be NAKed */
@@ -2939,18 +2928,18 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                         * always true. */
                        if (type == 0 && i == DHO_SERVERID)
                                continue;
-                       LOGDHCP(LOG_WARNING, "reject DHCP");
+                       LOGDHCP(logwarnx, "reject DHCP");
                        return;
                }
        }
 
        /* DHCP Auto-Configure, RFC 2563 */
        if (type == DHCP_OFFER && bootp->yiaddr == 0) {
-               LOGDHCP(LOG_WARNING, "no address given");
+               LOGDHCP(logwarnx, "no address given");
                if ((msg = get_option_string(ifp->ctx,
                    bootp, bootp_len, DHO_MESSAGE)))
                {
-                       syslog(LOG_WARNING, "%s: message: %s", ifp->name, msg);
+                       logwarnx("%s: message: %s", ifp->name, msg);
                        free(msg);
                }
 #ifdef IPV4LL
@@ -2960,17 +2949,17 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                {
                        switch (tmp) {
                        case 0:
-                               LOGDHCP(LOG_WARNING, "IPv4LL disabled from");
+                               LOGDHCP(logwarnx, "IPv4LL disabled from");
                                ipv4ll_drop(ifp);
                                arp_drop(ifp);
                                break;
                        case 1:
-                               LOGDHCP(LOG_WARNING, "IPv4LL enabled from");
+                               LOGDHCP(logwarnx, "IPv4LL enabled from");
                                ipv4ll_start(ifp);
                                break;
                        default:
-                               syslog(LOG_ERR,
-                                   "%s: unknown auto configuration option %d",
+                               logerrx("%s: unknown auto configuration "
+                                   "option %d",
                                    ifp->name, tmp);
                                break;
                        }
@@ -2988,14 +2977,14 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
            &&
            (bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST))
        {
-               LOGDHCP(LOG_WARNING, "reject invalid address");
+               LOGDHCP(logwarnx, "reject invalid address");
                return;
        }
 
 #ifdef IN_IFF_DUPLICATED
        ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
        if (ia && ia->addr_flags & IN_IFF_DUPLICATED) {
-               LOGDHCP(LOG_WARNING, "declined duplicate address");
+               LOGDHCP(logwarnx, "declined duplicate address");
                if (type)
                        dhcp_decline(ifp);
                ipv4_deladdr(ia, 0);
@@ -3026,11 +3015,11 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                        goto rapidcommit;
                }
 
-               LOGDHCP(LOG_INFO, "offered");
+               LOGDHCP(loginfo, "offered");
                if (state->offer_len < bootp_len) {
                        free(state->offer);
                        if ((state->offer = malloc(bootp_len)) == NULL) {
-                               syslog(LOG_ERR, "%s: malloc: %m", __func__);
+                               logerr(__func__);
                                state->offer_len = 0;
                                return;
                        }
@@ -3067,13 +3056,13 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
 
        if (type) {
                if (type == DHCP_OFFER) {
-                       LOGDHCP(LOG_WARNING, "ignoring offer of");
+                       LOGDHCP(logwarnx, "ignoring offer of");
                        return;
                }
 
                /* We should only be dealing with acks */
                if (type != DHCP_ACK) {
-                       LOGDHCP(LOG_ERR, "not ACK or OFFER");
+                       LOGDHCP(logerr, "not ACK or OFFER");
                        return;
                }
 
@@ -3085,14 +3074,14 @@ dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len,
                            DHO_RAPIDCOMMIT, NULL))
                                state->state = DHS_REQUEST;
                        else {
-                               LOGDHCP(LOG_DEBUG, "ignoring ack of");
+                               LOGDHCP(logdebug, "ignoring ack of");
                                return;
                        }
                }
 
 rapidcommit:
                if (!(ifo->options & DHCPCD_INFORM))
-                       LOGDHCP(LOG_DEBUG, "acknowledged");
+                       LOGDHCP(logdebug, "acknowledged");
                else
                    ifo->options &= ~DHCPCD_STATIC;
        }
@@ -3107,7 +3096,7 @@ rapidcommit:
                if (state->offer_len < bootp_len) {
                        free(state->offer);
                        if ((state->offer = malloc(bootp_len)) == NULL) {
-                               syslog(LOG_ERR, "%s: malloc: %m", __func__);
+                               logerr(__func__);
                                state->offer_len = 0;
                                return;
                        }
@@ -3200,24 +3189,24 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags)
 
        if (valid_udp_packet(data, len, &from, flags & RAW_PARTIALCSUM) == -1)
        {
-               syslog(LOG_ERR, "%s: invalid UDP packet from %s",
+               logerrx("%s: invalid UDP packet from %s",
                    ifp->name, inet_ntoa(from));
                return;
        }
        i = whitelisted_ip(ifp->options, from.s_addr);
        if (i == 0) {
-               syslog(LOG_WARNING, "%s: non whitelisted DHCP packet from %s",
+               logwarnx("%s: non whitelisted DHCP packet from %s",
                    ifp->name, inet_ntoa(from));
                return;
        } else if (i != 1 && blacklisted_ip(ifp->options, from.s_addr) == 1) {
-               syslog(LOG_WARNING, "%s: blacklisted DHCP packet from %s",
+               logwarnx("%s: blacklisted DHCP packet from %s",
                    ifp->name, inet_ntoa(from));
                return;
        }
        if (ifp->flags & IFF_POINTOPOINT &&
            (state->addr == NULL || state->addr->brd.s_addr != from.s_addr))
        {
-               syslog(LOG_WARNING, "%s: server %s is not destination",
+               logwarnx("%s: server %s is not destination",
                    ifp->name, inet_ntoa(from));
        }
 
@@ -3232,7 +3221,7 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags)
        /* udp_len must be correct because the values are checked in
         * valid_udp_packet(). */
        if (udp_len < offsetof(struct bootp, vend)) {
-               syslog(LOG_ERR, "%s: truncated packet (%zu) from %s",
+               logerrx("%s: truncated packet (%zu) from %s",
                    ifp->name, udp_len, inet_ntoa(from));
                return;
        }
@@ -3263,7 +3252,7 @@ dhcp_readpacket(void *arg)
        while (!(flags & BPF_EOF)) {
                bytes = bpf_read(ifp, state->bpf_fd, buf, sizeof(buf), &flags);
                if (bytes == -1) {
-                       syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
+                       logerr(__func__);
                        dhcp_close(ifp);
                        return;
                }
@@ -3285,7 +3274,7 @@ dhcp_handleudp(void *arg)
        /* Just read what's in the UDP fd and discard it as we always read
         * from the raw fd */
        if (read(ctx->udp_fd, buffer, sizeof(buffer)) == -1) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                eloop_event_delete(ctx->eloop, ctx->udp_fd);
                close(ctx->udp_fd);
                ctx->udp_fd = -1;
@@ -3303,13 +3292,12 @@ dhcp_open(struct interface *ifp)
                state->bpf_fd = bpf_open(ifp, bpf_bootp);
                if (state->bpf_fd == -1) {
                        if (errno == ENOENT) {
-                               syslog(LOG_ERR, "%s not found", bpf_name);
+                               logerrx("%s not found", bpf_name);
                                /* May as well disable IPv4 entirely at
                                 * this point as we really need it. */
                                ifp->options->options &= ~DHCPCD_IPV4;
                        } else
-                               syslog(LOG_ERR, "%s: %s: %m",
-                                   __func__, ifp->name);
+                               logerr(__func__);
                        return -1;
                }
                eloop_event_add(ifp->ctx->eloop,
@@ -3331,7 +3319,7 @@ dhcp_dump(struct interface *ifp)
            AF_INET, ifp);
        state->new_len = read_lease(ifp, &state->new);
        if (state->new == NULL) {
-               syslog(LOG_ERR, "%s: %s: %m",
+               logerr("%s: %s",
                    *ifp->name ? ifp->name : state->leasefile, __func__);
                return -1;
        }
@@ -3339,7 +3327,7 @@ dhcp_dump(struct interface *ifp)
        return script_runreason(ifp, state->reason);
 
 eexit:
-       syslog(LOG_ERR, "%s: %m", __func__);
+       logerr(__func__);
        return -1;
 }
 
@@ -3454,16 +3442,16 @@ dhcp_init(struct interface *ifp)
                return 0;
 
        if (ifo->options & DHCPCD_CLIENTID)
-               syslog(LOG_DEBUG, "%s: using ClientID %s", ifp->name,
+               logdebug("%s: using ClientID %s", ifp->name,
                    hwaddr_ntoa(state->clientid + 1, state->clientid[0],
                        buf, sizeof(buf)));
        else if (ifp->hwlen)
-               syslog(LOG_DEBUG, "%s: using hwaddr %s", ifp->name,
+               logdebug("%s: using hwaddr %s", ifp->name,
                    hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
        return 0;
 
 eexit:
-       syslog(LOG_ERR, "%s: error making ClientID: %m", __func__);
+       logerr(__func__);
        return -1;
 }
 
@@ -3488,15 +3476,14 @@ dhcp_start1(void *arg)
                        /* Don't log an error if some other process
                         * is handling this. */
                        if (errno != EADDRINUSE)
-                               syslog(LOG_ERR, "%s: dhcp_openudp: %m",
-                                   __func__);
+                               logerr("%s: dhcp_openudp", __func__);
                } else
                        eloop_event_add(ifp->ctx->eloop,
                            ifp->ctx->udp_fd, dhcp_handleudp, ifp->ctx);
        }
 
        if (dhcp_init(ifp) == -1) {
-               syslog(LOG_ERR, "%s: dhcp_init: %m", ifp->name);
+               logerr("%s: dhcp_init", ifp->name);
                return;
        }
 
@@ -3533,8 +3520,7 @@ dhcp_start1(void *arg)
                return;
        }
        if (ifp->hwlen == 0 && ifo->clientid[0] == '\0') {
-               syslog(LOG_WARNING, "%s: needs a clientid to configure",
-                   ifp->name);
+               logwarnx("%s: needs a clientid to configure", ifp->name);
                dhcp_drop(ifp, "FAIL");
                eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
                return;
@@ -3588,7 +3574,7 @@ dhcp_start1(void *arg)
                                state->added |= STATE_ADDED | STATE_FAKE;
                                rt_build(ifp->ctx, AF_INET);
                        } else
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                }
                if (!IS_DHCP(state->offer)) {
                        free(state->offer);
@@ -3605,8 +3591,8 @@ dhcp_start1(void *arg)
                        if (now == -1 ||
                            (time_t)state->lease.leasetime < now - st.st_mtime)
                        {
-                               syslog(LOG_DEBUG,
-                                   "%s: discarding expired lease", ifp->name);
+                               logdebug("%s: discarding expired lease",
+                                   ifp->name);
                                free(state->offer);
                                state->offer = NULL;
                                state->offer_len = 0;
@@ -3713,7 +3699,7 @@ dhcp_start(struct interface *ifp)
        tv.tv_nsec = (suseconds_t)arc4random_uniform(
            (DHCP_MAX_DELAY - DHCP_MIN_DELAY) * NSEC_PER_SEC);
        timespecnorm(&tv);
-       syslog(LOG_DEBUG, "%s: delaying IPv4 for %0.1f seconds",
+       logdebug("%s: delaying IPv4 for %0.1f seconds",
            ifp->name, timespec_to_double(&tv));
 
        eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_start1, ifp);
@@ -3748,7 +3734,7 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia)
 
        if (cmd == RTM_DELADDR) {
                if (state->addr == ia) {
-                       syslog(LOG_INFO, "%s: deleted IP address %s",
+                       loginfo("%s: deleted IP address %s",
                            ifp->name, ia->saddr);
                        state->addr = NULL;
                        /* Don't clear the added state as we need
index 94b1cd5baf64ee38412727385aeffc2167a204eb..631ae083bf7f24560359449eb95cac1982838514 100644 (file)
@@ -41,7 +41,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -55,6 +54,7 @@
 #include "if.h"
 #include "if-options.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "script.h"
 
 #ifdef HAVE_SYS_BITOPS_H
@@ -216,7 +216,7 @@ dhcp6_makevendor(void *data, const struct interface *ifp)
        }
 
        if (len > UINT16_MAX) {
-               syslog(LOG_ERR, "%s: DHCPv6 Vendor Class too big", ifp->name);
+               logerrx("%s: DHCPv6 Vendor Class too big", ifp->name);
                return 0;
        }
 
@@ -437,7 +437,7 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
                ifp->if_data[IF_DATA_DHCP6] = calloc(1, sizeof(*state));
                state = D6_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return -1;
                }
 
@@ -515,7 +515,7 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
        {
                sa = inet_ntop(AF_INET6, &prefix->prefix,
                    sabuf, sizeof(sabuf));
-               syslog(LOG_ERR, "%s: invalid prefix %s/%d + %d/%d: %m",
+               logerr("%s: invalid prefix %s/%d + %d/%d",
                    ifp->name, sa, prefix->prefix_len,
                    sla->sla, sla->prefix_len);
                return -1;
@@ -526,7 +526,7 @@ dhcp6_delegateaddr(struct in6_addr *addr, struct interface *ifp,
        {
                sa = inet_ntop(AF_INET6, &prefix->prefix_exclude,
                    sabuf, sizeof(sabuf));
-               syslog(LOG_ERR, "%s: cannot delegate excluded prefix %s/%d",
+               logerrx("%s: cannot delegate excluded prefix %s/%d",
                    ifp->name, sa, prefix->prefix_exclude_len);
                return -1;
        }
@@ -753,7 +753,7 @@ dhcp6_makemessage(struct interface *ifp)
                        alen = -1;
                }
                if (alen == -1)
-                       syslog(LOG_ERR, "%s: dhcp_auth_encode: %m", ifp->name);
+                       logerr("%s: %s: dhcp_auth_encode", __func__, ifp->name);
                else if (alen != 0) {
                        auth_len = (uint16_t)alen;
                        len += sizeof(o) + auth_len;
@@ -1085,7 +1085,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
        }
 
        if (!callback)
-               syslog(LOG_DEBUG, "%s: %s %s with xid 0x%02x%02x%02x",
+               logdebug("%s: %s %s with xid 0x%02x%02x%02x",
                    ifp->name,
                    broad_uni,
                    dhcp6_get_op(state->send->type),
@@ -1152,8 +1152,7 @@ dhcp6_sendmessage(struct interface *ifp, void (*callback)(void *))
 
 logsend:
                if (ifp->carrier != LINK_DOWN)
-                       syslog(LOG_DEBUG,
-                           "%s: %s %s (xid 0x%02x%02x%02x),"
+                       logdebug("%s: %s %s (xid 0x%02x%02x%02x),"
                            " next in %0.1f seconds",
                            ifp->name,
                            broad_uni,
@@ -1185,7 +1184,7 @@ logsend:
        if (ifp->options->auth.options & DHCPCD_AUTH_SEND &&
            dhcp6_update_auth(ifp, state->send, state->send_len) == -1)
        {
-               syslog(LOG_ERR, "%s: dhcp6_updateauth: %m", ifp->name);
+               logerr("%s: %s: dhcp6_updateauth", __func__, ifp->name);
                if (errno != ESRCH)
                        return -1;
        }
@@ -1209,7 +1208,7 @@ logsend:
        memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
 
        if (sendmsg(ctx->dhcp6_fd, &ctx->sndhdr, 0) == -1) {
-               syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
+               logerr("%s: %s: sendmsg", __func__, ifp->name);
                /* Allow DHCPv6 to continue .... the errors
                 * would be rate limited by the protocol.
                 * Generally the error is ENOBUFS when struggling to
@@ -1225,7 +1224,7 @@ logsend:
                        eloop_timeout_add_tv(ifp->ctx->eloop,
                            &state->RT, state->MRCcallback, ifp);
                else
-                       syslog(LOG_WARNING, "%s: sent %d times with no reply",
+                       logwarnx("%s: sent %d times with no reply",
                            ifp->name, state->RTC);
        }
        return 0;
@@ -1305,7 +1304,7 @@ dhcp6_startrenew(void *arg)
        state->MRC = 0;
 
        if (dhcp6_makemessage(ifp) == -1)
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
        else
                dhcp6_sendrenew(ifp);
 }
@@ -1344,8 +1343,7 @@ dhcp6_dadcallback(void *arg)
        if (ap->flags & IPV6_AF_DUPLICATED)
                /* XXX FIXME
                 * We should decline the address */
-               syslog(LOG_WARNING, "%s: DAD detected %s",
-                   ap->iface->name, ap->saddr);
+               logwarnx("%s: DAD detected %s", ap->iface->name, ap->saddr);
 
        if (!wascompleted) {
                ifp = ap->iface;
@@ -1365,7 +1363,7 @@ dhcp6_dadcallback(void *arg)
                                }
                        }
                        if (!wascompleted) {
-                               syslog(LOG_DEBUG, "%s: DHCPv6 DAD completed",
+                               logdebug("%s: DHCPv6 DAD completed",
                                    ifp->name);
                                script_runreason(ifp,
                                    ap->delegating_prefix ?
@@ -1396,7 +1394,7 @@ dhcp6_addrequestedaddrs(struct interface *ifp)
                        continue;
                a = calloc(1, sizeof(*a));
                if (a == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return;
                }
                a->flags = IPV6_AF_REQUEST;
@@ -1442,7 +1440,7 @@ dhcp6_startdiscover(void *arg)
 #ifndef SMALL
        dhcp6_delete_delegates(ifp);
 #endif
-       syslog(LOG_INFO, "%s: soliciting a DHCPv6 lease", ifp->name);
+       loginfo("%s: soliciting a DHCPv6 lease", ifp->name);
        state = D6_STATE(ifp);
        state->state = DH6S_DISCOVER;
        state->RTC = 0;
@@ -1462,7 +1460,7 @@ dhcp6_startdiscover(void *arg)
        dhcp6_addrequestedaddrs(ifp);
 
        if (dhcp6_makemessage(ifp) == -1)
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
        else
                dhcp6_senddiscover(ifp);
 }
@@ -1473,7 +1471,7 @@ dhcp6_failconfirm(void *arg)
        struct interface *ifp;
 
        ifp = arg;
-       syslog(LOG_ERR, "%s: failed to confirm prior address", ifp->name);
+       logerrx("%s: failed to confirm prior address", ifp->name);
        /* Section 18.1.2 says that we SHOULD use the last known
         * IP address(s) and lifetimes if we didn't get a reply.
         * I disagree with this. */
@@ -1486,7 +1484,7 @@ dhcp6_failrequest(void *arg)
        struct interface *ifp;
 
        ifp = arg;
-       syslog(LOG_ERR, "%s: failed to request address", ifp->name);
+       logerrx("%s: failed to request address", ifp->name);
        /* Section 18.1.1 says that client local policy dictates
         * what happens if a REQUEST fails.
         * Of the possible scenarios listed, moving back to the
@@ -1503,7 +1501,7 @@ dhcp6_failrebind(void *arg)
        struct interface *ifp;
 
        ifp = arg;
-       syslog(LOG_ERR, "%s: failed to rebind prior delegation", ifp->name);
+       logerrx("%s: failed to rebind prior delegation", ifp->name);
        dhcp6_delete_delegates(ifp);
        /* Section 18.1.2 says that we SHOULD use the last known
         * IP address(s) and lifetimes if we didn't get a reply.
@@ -1543,10 +1541,9 @@ dhcp6_startrebind(void *arg)
        eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrenew, ifp);
        state = D6_STATE(ifp);
        if (state->state == DH6S_RENEW)
-               syslog(LOG_WARNING, "%s: failed to renew DHCPv6, rebinding",
-                   ifp->name);
+               logwarnx("%s: failed to renew DHCPv6, rebinding", ifp->name);
        else
-               syslog(LOG_INFO, "%s: rebinding prior DHCPv6 lease", ifp->name);
+               loginfo("%s: rebinding prior DHCPv6 lease", ifp->name);
        state->state = DH6S_REBIND;
        state->RTC = 0;
        state->MRC = 0;
@@ -1566,7 +1563,7 @@ dhcp6_startrebind(void *arg)
        }
 
        if (dhcp6_makemessage(ifp) == -1)
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
        else
                dhcp6_sendrebind(ifp);
 
@@ -1594,7 +1591,7 @@ dhcp6_startrequest(struct interface *ifp)
        state->MRCcallback = dhcp6_failrequest;
 
        if (dhcp6_makemessage(ifp) == -1) {
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
                return;
        }
 
@@ -1614,9 +1611,9 @@ dhcp6_startconfirm(struct interface *ifp)
        state->MRT = CNF_MAX_RT;
        state->MRC = 0;
 
-       syslog(LOG_INFO, "%s: confirming prior DHCPv6 lease", ifp->name);
+       loginfo("%s: confirming prior DHCPv6 lease", ifp->name);
        if (dhcp6_makemessage(ifp) == -1) {
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
                return;
        }
        dhcp6_sendconfirm(ifp);
@@ -1633,8 +1630,7 @@ dhcp6_startinform(void *arg)
        ifp = arg;
        state = D6_STATE(ifp);
        if (state->new == NULL || ifp->options->options & DHCPCD_DEBUG)
-               syslog(LOG_INFO, "%s: requesting DHCPv6 information",
-                   ifp->name);
+               loginfo("%s: requesting DHCPv6 information", ifp->name);
        state->state = DH6S_INFORM;
        state->RTC = 0;
        state->IMD = INF_MAX_DELAY;
@@ -1643,7 +1639,7 @@ dhcp6_startinform(void *arg)
        state->MRC = 0;
 
        if (dhcp6_makemessage(ifp) == -1)
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
        else
                dhcp6_sendinform(ifp);
 }
@@ -1656,7 +1652,7 @@ dhcp6_startexpire(void *arg)
        ifp = arg;
        eloop_timeout_delete(ifp->ctx->eloop, dhcp6_sendrebind, ifp);
 
-       syslog(LOG_ERR, "%s: DHCPv6 lease expired", ifp->name);
+       logerrx("%s: DHCPv6 lease expired", ifp->name);
        dhcp6_freedrop_addrs(ifp, 1, NULL);
 #ifndef SMALL
        dhcp6_delete_delegates(ifp);
@@ -1665,8 +1661,7 @@ dhcp6_startexpire(void *arg)
        if (ipv6nd_hasradhcp(ifp) || dhcp6_hasprefixdelegation(ifp))
                dhcp6_startdiscover(ifp);
        else
-               syslog(LOG_WARNING, "%s: no advertising IPv6 router wants DHCP",
-                   ifp->name);
+               logwarnx("%s: no advertising IPv6 router wants DHCP",ifp->name);
 }
 
 static void
@@ -1705,7 +1700,7 @@ dhcp6_startrelease(struct interface *ifp)
 #endif
 
        if (dhcp6_makemessage(ifp) == -1)
-               syslog(LOG_ERR, "%s: dhcp6_makemessage: %m", ifp->name);
+               logerr("%s: %s", __func__, ifp->name);
        else {
                dhcp6_sendrelease(ifp);
                dhcp6_finishrelease(ifp);
@@ -1728,12 +1723,12 @@ dhcp6_checkstatusok(const struct interface *ifp,
        else
                farg = m;
        if ((opt = f(farg, len, D6_OPTION_STATUS_CODE, &opt_len)) == NULL) {
-               //syslog(LOG_DEBUG, "%s: no status", ifp->name);
+               //logdebug("%s: no status", ifp->name);
                return 0;
        }
 
        if (opt_len < sizeof(code)) {
-               syslog(LOG_ERR, "%s: status truncated", ifp->name);
+               logerrx("%s: status truncated", ifp->name);
                return -1;
        }
        memcpy(&code, opt, sizeof(code));
@@ -1754,7 +1749,7 @@ dhcp6_checkstatusok(const struct interface *ifp,
                }
        } else {
                if ((sbuf = malloc((size_t)opt_len + 1)) == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return false;
                }
                memcpy(sbuf, opt, opt_len);
@@ -1762,7 +1757,7 @@ dhcp6_checkstatusok(const struct interface *ifp,
                status = sbuf;
        }
 
-       syslog(LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status);
+       logerrx("%s: DHCPv6 REPLY: %s", ifp->name, status);
        free(sbuf);
        return -1;
 }
@@ -1824,8 +1819,7 @@ dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid,
                d = nd;
                if (ol < 24) {
                        errno = EINVAL;
-                       syslog(LOG_ERR, "%s: IA Address option truncated",
-                           ifp->name);
+                       logerrx("%s: IA Address option truncated", ifp->name);
                        continue;
                }
                memcpy(&ia, o, ol);
@@ -1834,8 +1828,8 @@ dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid,
                /* RFC 3315 22.6 */
                if (ia.pltime > ia.vltime) {
                        errno = EINVAL;
-                       syslog(LOG_ERR,
-                           "%s: IA Address pltime %"PRIu32" > vltime %"PRIu32,
+                       logerr("%s: IA Address pltime %"PRIu32
+                           " > vltime %"PRIu32,
                            ifp->name, ia.pltime, ia.vltime);
                        continue;
                }
@@ -1846,7 +1840,7 @@ dhcp6_findna(struct interface *ifp, uint16_t ot, const uint8_t *iaid,
                if (a == NULL) {
                        a = calloc(1, sizeof(*a));
                        if (a == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                break;
                        }
                        a->iface = ifp;
@@ -1917,8 +1911,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                d = nd;
                if (ol < sizeof(pdp)) {
                        errno = EINVAL;
-                       syslog(LOG_ERR, "%s: IA Prefix option truncated",
-                           ifp->name);
+                       logerrx("%s: IA Prefix option truncated", ifp->name);
                        continue;
                }
 
@@ -1928,8 +1921,8 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                /* RFC 3315 22.6 */
                if (pdp.pltime > pdp.vltime) {
                        errno = EINVAL;
-                       syslog(LOG_ERR,
-                           "%s: IA Prefix pltime %"PRIu32" > vltime %"PRIu32,
+                       logerrx("%s: IA Prefix pltime %"PRIu32
+                           " > vltime %"PRIu32,
                            ifp->name, pdp.pltime, pdp.vltime);
                        continue;
                }
@@ -1947,7 +1940,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                if (a == NULL) {
                        a = calloc(1, sizeof(*a));
                        if (a == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                break;
                        }
                        a->iface = ifp;
@@ -2004,7 +1997,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                if (o == NULL)
                        continue;
                if (ol < 2) {
-                       syslog(LOG_ERR, "%s: truncated PD Exclude", ifp->name);
+                       logerrx("%s: truncated PD Exclude", ifp->name);
                        continue;
                }
                a->prefix_exclude_len = *o++;
@@ -2012,8 +2005,7 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                if (((a->prefix_exclude_len - a->prefix_len - 1) / NBBY) + 1
                    != ol)
                {
-                       syslog(LOG_ERR, "%s: PD Exclude length mismatch",
-                           ifp->name);
+                       logerrx("%s: PD Exclude length mismatch", ifp->name);
                        a->prefix_exclude_len = 0;
                        continue;
                }
@@ -2070,7 +2062,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
                o.len = ntohs(o.len);
                if (o.len > l || sizeof(o) + o.len > l) {
                        errno = EINVAL;
-                       syslog(LOG_ERR, "%s: option overflow", ifp->name);
+                       logerrx("%s: option overflow", ifp->name);
                        break;
                }
                p = d + sizeof(o);
@@ -2091,7 +2083,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
                }
                if (o.len < nl) {
                        errno = EINVAL;
-                       syslog(LOG_ERR, "%s: IA option truncated", ifp->name);
+                       logerrx("%s: IA option truncated", ifp->name);
                        continue;
                }
 
@@ -2107,14 +2099,14 @@ 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))
                {
-                       syslog(LOG_DEBUG, "%s: ignoring unrequested IAID %s",
+                       logdebug("%s: ignoring unrequested IAID %s",
                            ifp->name,
                            hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
                            buf, sizeof(buf)));
                        continue;
                }
                if ( j < ifo->ia_len && ifo->ia[j].ia_type != o.code) {
-                       syslog(LOG_ERR, "%s: IAID %s: option type mismatch",
+                       logerrx("%s: IAID %s: option type mismatch",
                            ifp->name,
                            hwaddr_ntoa(ia.iaid, sizeof(ia.iaid),
                            buf, sizeof(buf)));
@@ -2126,8 +2118,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
                        ia.t2 = ntohl(ia.t2);
                        /* RFC 3315 22.4 */
                        if (ia.t2 > 0 && ia.t1 > ia.t2) {
-                               syslog(LOG_WARNING,
-                                   "%s: IAID %s T1 (%d) > T2 (%d) from %s",
+                               logwarnx("%s: IAID %s T1(%d) > T2(%d) from %s",
                                    ifp->name,
                                    hwaddr_ntoa(iaid, sizeof(iaid), buf,
                                                sizeof(buf)),
@@ -2145,8 +2136,7 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
                        if (dhcp6_findpd(ifp, ia.iaid, p, o.len,
                                         acquired) == 0)
                        {
-                               syslog(LOG_WARNING,
-                                   "%s: %s: DHCPv6 REPLY missing Prefix",
+                               logwarnx("%s: %s: DHCPv6 REPLY missing Prefix",
                                    ifp->name, sfrom);
                                continue;
                        }
@@ -2155,8 +2145,8 @@ dhcp6_findia(struct interface *ifp, struct dhcp6_message *m, size_t l,
                        if (dhcp6_findna(ifp, o.code, ia.iaid, p, o.len,
                                         acquired) == 0)
                        {
-                               syslog(LOG_WARNING,
-                                   "%s: %s: DHCPv6 REPLY missing IA Address",
+                               logwarnx("%s: %s: DHCPv6 REPLY missing "
+                                   "IA Address",
                                    ifp->name, sfrom);
                                continue;
                        }
@@ -2198,7 +2188,7 @@ dhcp6_validatelease(struct interface *ifp,
        struct timespec aq;
 
        if (len <= sizeof(*m)) {
-               syslog(LOG_ERR, "%s: DHCPv6 lease truncated", ifp->name);
+               logerrx("%s: DHCPv6 lease truncated", ifp->name);
                return -1;
        }
 
@@ -2215,8 +2205,7 @@ dhcp6_validatelease(struct interface *ifp,
        nia = dhcp6_findia(ifp, m, len, sfrom, acquired);
        if (nia == 0) {
                if (state->state != DH6S_CONFIRM && ok != 1) {
-                       syslog(LOG_ERR, "%s: no useable IA found in lease",
-                           ifp->name);
+                       logerrx("%s: no useable IA found in lease", ifp->name);
                        return -1;
                }
 
@@ -2239,12 +2228,11 @@ dhcp6_writelease(const struct interface *ifp)
        ssize_t bytes;
 
        state = D6_CSTATE(ifp);
-       syslog(LOG_DEBUG, "%s: writing lease `%s'",
-           ifp->name, state->leasefile);
+       logdebug("%s: writing lease `%s'", ifp->name, state->leasefile);
 
        fd = open(state->leasefile, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (fd == -1) {
-               syslog(LOG_ERR, "%s: dhcp6_writelease: %m", ifp->name);
+               logerr(__func__);
                return -1;
        }
        bytes = write(fd, state->new, state->new_len);
@@ -2270,12 +2258,11 @@ dhcp6_readlease(struct interface *ifp, int validate)
 
        state = D6_STATE(ifp);
        if (state->leasefile[0] == '\0') {
-               syslog(LOG_DEBUG, "reading standard input");
+               logdebug("reading standard input");
                fd = fileno(stdin);
                fd_opened = false;
        } else {
-               syslog(LOG_DEBUG, "%s: reading lease `%s'",
-                   ifp->name, state->leasefile);
+               logdebug("%s: reading lease `%s'", ifp->name, state->leasefile);
                fd = open(state->leasefile, O_RDONLY);
                if (fd != -1 && fstat(fd, &st) == -1) {
                        close(fd);
@@ -2320,8 +2307,7 @@ dhcp6_readlease(struct interface *ifp, int validate)
            state->leasefile[0] != '\0')
        {
                if ((time_t)state->expire < now - st.st_mtime) {
-                       syslog(LOG_DEBUG,"%s: discarding expired lease",
-                           ifp->name);
+                       logdebug("%s: discarding expired lease", ifp->name);
                        retval = 0;
                        goto ex;
                }
@@ -2337,21 +2323,19 @@ auth:
                    (uint8_t *)state->new, state->new_len, 6, state->new->type,
                    o, ol) == NULL)
                {
-                       syslog(LOG_DEBUG, "%s: dhcp_auth_validate: %m",
-                           ifp->name);
-                       syslog(LOG_ERR, "%s: authentication failed", ifp->name);
+                       logdebug("%s: dhcp_auth_validate", __func__);
+                       logerr("%s: authentication failed", ifp->name);
                        goto ex;
                }
                if (state->auth.token)
-                       syslog(LOG_DEBUG, "%s: validated using 0x%08" PRIu32,
+                       logdebug("%s: validated using 0x%08" PRIu32,
                            ifp->name, state->auth.token->secretid);
                else
-                       syslog(LOG_INFO, "%s: accepted reconfigure key",
-                           ifp->name);
+                       loginfo("%s: accepted reconfigure key", ifp->name);
        } else if ((ifp->options->auth.options & DHCPCD_AUTH_SENDREQUIRE) ==
            DHCPCD_AUTH_SENDREQUIRE)
        {
-               syslog(LOG_ERR, "%s: authentication now required", ifp->name);
+               logerrx("%s: authentication now required", ifp->name);
                goto ex;
        }
 #endif
@@ -2401,8 +2385,7 @@ dhcp6_startinit(struct interface *ifp)
                r = dhcp6_readlease(ifp, 1);
                if (r == -1) {
                        if (errno != ENOENT)
-                               syslog(LOG_ERR, "%s: dhcp6_readlease: %s: %m",
-                                   ifp->name, state->leasefile);
+                               logerr("%s: %s", __func__, state->leasefile);
                } else if (r != 0) {
                        /* RFC 3633 section 12.1 */
 #ifndef SMALL
@@ -2435,8 +2418,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
                if (prefix->prefix_exclude_len == 0) {
                        /* Don't spam the log automatically */
                        if (sla)
-                               syslog(LOG_WARNING,
-                                   "%s: DHCPv6 server does not support "
+                               logwarnx("%s: DHCPv6 server does not support "
                                    "OPTION_PD_EXCLUDE",
                                    ifp->name);
                        return NULL;
@@ -2448,7 +2430,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
                return NULL;
 
        if (fls64(sla->suffix) > 128 - pfxlen) {
-               syslog(LOG_ERR, "%s: suffix %" PRIu64 " + prefix_len %d > 128",
+               logerrx("%s: suffix %" PRIu64 " + prefix_len %d > 128",
                    ifp->name, sla->suffix, pfxlen);
                return NULL;
        }
@@ -2462,8 +2444,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
        } else {
                dadcounter = ipv6_makeaddr(&daddr, ifp, &addr, pfxlen);
                if (dadcounter == -1) {
-                       syslog(LOG_ERR,
-                           "%s: error adding slaac to prefix_len %d",
+                       logerrx("%s: error adding slaac to prefix_len %d",
                            ifp->name, pfxlen);
                        return NULL;
                }
@@ -2478,7 +2459,7 @@ dhcp6_ifdelegateaddr(struct interface *ifp, struct ipv6_addr *prefix,
        if (ia == NULL) {
                ia = calloc(1, sizeof(*ia));
                if (ia == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return NULL;
                }
                ia->iface = ifp;
@@ -2544,8 +2525,7 @@ dhcp6_script_try_run(struct interface *ifp, int delegated)
                if (!delegated)
                        dhcpcd_daemonise(ifp->ctx);
        } else
-               syslog(LOG_DEBUG, "%s: waiting for DHCPv6 DAD to complete",
-                   ifp->name);
+               logdebug("%s: waiting for DHCPv6 DAD to complete", ifp->name);
 }
 
 #ifdef SMALL
@@ -2585,12 +2565,16 @@ dhcp6_delegate_prefix(struct interface *ifp)
                        if (!(ap->flags & IPV6_AF_DELEGATEDPFX))
                                continue;
                        if (!(ap->flags & IPV6_AF_DELEGATEDLOG)) {
+                               logfunc_t *logfunc;
+
+                               if (ap->flags & IPV6_AF_NEW)
+                                       logfunc = loginfo;
+                               else
+                                       logfunc = logdebug;
                                /* We only want to log this the once as we loop
                                 * through many interfaces first. */
                                ap->flags |= IPV6_AF_DELEGATEDLOG;
-                               syslog(ap->flags & IPV6_AF_NEW ?
-                                   LOG_INFO : LOG_DEBUG,
-                                   "%s: delegated prefix %s",
+                               logfunc("%s: delegated prefix %s",
                                    ifp->name, ap->saddr);
                                ap->flags &= ~IPV6_AF_NEW;
                        }
@@ -2603,7 +2587,7 @@ dhcp6_delegate_prefix(struct interface *ifp)
                                        /* no SLA configured, so lets
                                         * automate it */
                                        if (ifd->carrier != LINK_UP) {
-                                               syslog(LOG_DEBUG,
+                                               logdebug(
                                                    "%s: has no carrier, cannot"
                                                    " delegate addresses",
                                                    ifd->name);
@@ -2619,7 +2603,7 @@ dhcp6_delegate_prefix(struct interface *ifp)
                                        if (strcmp(ifd->name, sla->ifname))
                                                continue;
                                        if (ifd->carrier != LINK_UP) {
-                                               syslog(LOG_DEBUG,
+                                               logdebug(
                                                    "%s: has no carrier, cannot"
                                                    " delegate addresses",
                                                    ifd->name);
@@ -2683,7 +2667,7 @@ dhcp6_find_delegates(struct interface *ifp)
                                        if (strcmp(ifp->name, sla->ifname))
                                                continue;
                                        if (ipv6_linklocal(ifp) == NULL) {
-                                               syslog(LOG_DEBUG,
+                                               logdebug(
                                                    "%s: delaying adding"
                                                    " delegated addresses for"
                                                    " LL address",
@@ -2701,7 +2685,7 @@ dhcp6_find_delegates(struct interface *ifp)
        }
 
        if (k) {
-               syslog(LOG_INFO, "%s: adding delegated prefixes", ifp->name);
+               loginfo("%s: adding delegated prefixes", ifp->name);
                state = D6_STATE(ifp);
                state->state = DH6S_DELEGATED;
                ipv6_addaddrs(&state->addrs);
@@ -2733,6 +2717,7 @@ dhcp6_handledata(void *arg)
        struct ipv6_addr *ap;
        bool valid_op, has_new;
        uint32_t u32;
+       logfunc_t *lognewinfo;
 #ifdef AUTH
        uint8_t *auth;
        uint16_t auth_len;
@@ -2742,7 +2727,7 @@ dhcp6_handledata(void *arg)
        ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
        bytes = recvmsg_realloc(ctx->dhcp6_fd, &ctx->rcvhdr, 0);
        if (bytes == -1) {
-               syslog(LOG_ERR, "%s: recvmsg: %m", __func__);
+               logerr("%s: recvmsg_realloc", __func__);
                close(ctx->dhcp6_fd);
                eloop_event_delete(ctx->eloop, ctx->dhcp6_fd);
                ctx->dhcp6_fd = -1;
@@ -2752,7 +2737,7 @@ dhcp6_handledata(void *arg)
        ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
            ctx->ntopbuf, sizeof(ctx->ntopbuf));
        if (len < sizeof(struct dhcp6_message)) {
-               syslog(LOG_ERR, "DHCPv6 packet too short from %s", ctx->sfrom);
+               logerrx("DHCPv6 packet too short from %s", ctx->sfrom);
                return;
        }
 
@@ -2771,7 +2756,7 @@ dhcp6_handledata(void *arg)
                }
        }
        if (pkt.ipi6_ifindex == 0) {
-               syslog(LOG_ERR, "DHCPv6 reply did not contain index from %s",
+               logerrx("DHCPv6 reply did not contain index from %s",
                    ctx->sfrom);
                return;
        }
@@ -2783,15 +2768,14 @@ dhcp6_handledata(void *arg)
                        break;
        }
        if (ifp == NULL) {
-               syslog(LOG_DEBUG,
-                   "DHCPv6 reply for unexpected interface from %s",
+               logdebug("DHCPv6 reply for unexpected interface from %s",
                    ctx->sfrom);
                return;
        }
 
        state = D6_STATE(ifp);
        if (state == NULL || state->send == NULL) {
-               syslog(LOG_DEBUG, "%s: DHCPv6 reply received but not running",
+               logdebug("%s: DHCPv6 reply received but not running",
                    ifp->name);
                return;
        }
@@ -2802,7 +2786,7 @@ dhcp6_handledata(void *arg)
        if (r->type != DHCP6_RECONFIGURE &&
            (state->state == DH6S_BOUND || state->state == DH6S_INFORMED))
        {
-               syslog(LOG_DEBUG, "%s: DHCPv6 reply received but already bound",
+               logdebug("%s: DHCPv6 reply received but already bound",
                    ifp->name);
                return;
        }
@@ -2812,7 +2796,7 @@ dhcp6_handledata(void *arg)
            r->xid[1] != state->send->xid[1] ||
            r->xid[2] != state->send->xid[2]))
        {
-               syslog(LOG_DEBUG, "%s: wrong xid 0x%02x%02x%02x"
+               logdebug("%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],
@@ -2823,7 +2807,7 @@ dhcp6_handledata(void *arg)
        }
 
        if (dhcp6_findmoption(r, len, D6_OPTION_SERVERID, NULL) == NULL) {
-               syslog(LOG_DEBUG, "%s: no DHCPv6 server ID from %s",
+               logdebug("%s: no DHCPv6 server ID from %s",
                    ifp->name, ctx->sfrom);
                return;
        }
@@ -2832,7 +2816,7 @@ dhcp6_handledata(void *arg)
        if (o == NULL || ol != ctx->duid_len ||
            memcmp(o, ctx->duid, ol) != 0)
        {
-               syslog(LOG_DEBUG, "%s: incorrect client ID from %s",
+               logdebug("%s: incorrect client ID from %s",
                    ifp->name, ctx->sfrom);
                return;
        }
@@ -2845,16 +2829,14 @@ dhcp6_handledata(void *arg)
                if (has_option_mask(ifo->requiremask6, opt->option) &&
                    !dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
                {
-                       syslog(LOG_WARNING,
-                           "%s: reject DHCPv6 (no option %s) from %s",
+                       logwarnx("%s: reject DHCPv6 (no option %s) from %s",
                            ifp->name, opt->var, ctx->sfrom);
                        return;
                }
                if (has_option_mask(ifo->rejectmask6, opt->option) &&
                    dhcp6_findmoption(r, len, (uint16_t)opt->option, NULL))
                {
-                       syslog(LOG_WARNING,
-                           "%s: reject DHCPv6 (option %s) from %s",
+                       logwarnx("%s: reject DHCPv6 (option %s) from %s",
                            ifp->name, opt->var, ctx->sfrom);
                        return;
                }
@@ -2867,25 +2849,23 @@ dhcp6_handledata(void *arg)
                if (dhcp_auth_validate(&state->auth, &ifo->auth,
                    (uint8_t *)r, len, 6, r->type, auth, auth_len) == NULL)
                {
-                       syslog(LOG_DEBUG, "dhcp_auth_validate: %m");
-                       syslog(LOG_ERR, "%s: authentication failed from %s",
+                       logdebug("dhcp_auth_validate");
+                       logerrx("%s: authentication failed from %s",
                            ifp->name, ctx->sfrom);
                        return;
                }
                if (state->auth.token)
-                       syslog(LOG_DEBUG,
-                           "%s: validated using 0x%08" PRIu32,
+                       logdebug("%s: validated using 0x%08" PRIu32,
                            ifp->name, state->auth.token->secretid);
                else
-                       syslog(LOG_INFO,
-                           "%s: accepted reconfigure key", ifp->name);
+                       loginfo("%s: accepted reconfigure key", ifp->name);
        } else if (ifo->auth.options & DHCPCD_AUTH_SEND) {
                if (ifo->auth.options & DHCPCD_AUTH_REQUIRE) {
-                       syslog(LOG_ERR, "%s: no authentication from %s",
+                       logerr("%s: no authentication from %s",
                            ifp->name, ctx->sfrom);
                        return;
                }
-               syslog(LOG_WARNING, "%s: no authentication from %s",
+               logwarnx("%s: no authentication from %s",
                    ifp->name, ctx->sfrom);
        }
 #endif
@@ -2968,13 +2948,13 @@ dhcp6_handledata(void *arg)
                        memcpy(&max_rt, o, sizeof(max_rt));
                        max_rt = ntohl(max_rt);
                        if (max_rt >= 60 && max_rt <= 86400) {
-                               syslog(LOG_DEBUG, "%s: SOL_MAX_RT %llu -> %u",
+                               logdebug("%s: SOL_MAX_RT %llu -> %u",
                                    ifp->name,
                                    (unsigned long long)state->sol_max_rt,
                                    max_rt);
                                state->sol_max_rt = (time_t)max_rt;
                        } else
-                               syslog(LOG_ERR, "%s: invalid SOL_MAX_RT %u",
+                               logerr("%s: invalid SOL_MAX_RT %u",
                                    ifp->name, max_rt);
                }
                o = dhcp6_findmoption(r, len, D6_OPTION_INF_MAX_RT, &ol);
@@ -2984,13 +2964,13 @@ dhcp6_handledata(void *arg)
                        memcpy(&max_rt, o, sizeof(max_rt));
                        max_rt = ntohl(max_rt);
                        if (max_rt >= 60 && max_rt <= 86400) {
-                               syslog(LOG_DEBUG, "%s: INF_MAX_RT %llu -> %u",
+                               logdebug("%s: INF_MAX_RT %llu -> %u",
                                    ifp->name,
                                    (unsigned long long)state->inf_max_rt,
                                    max_rt);
                                state->inf_max_rt = (time_t)max_rt;
                        } else
-                               syslog(LOG_ERR, "%s: invalid INF_MAX_RT %u",
+                               logerrx("%s: invalid INF_MAX_RT %u",
                                    ifp->name, max_rt);
                }
                if (dhcp6_validatelease(ifp, r, len, ctx->sfrom, NULL) == -1)
@@ -3000,30 +2980,28 @@ dhcp6_handledata(void *arg)
 #ifdef AUTH
                if (auth == NULL) {
 #endif
-                       syslog(LOG_ERR, "%s: unauthenticated %s from %s",
+                       logerrx("%s: unauthenticated %s from %s",
                            ifp->name, op, ctx->sfrom);
                        if (ifo->auth.options & DHCPCD_AUTH_REQUIRE)
                                return;
 #ifdef AUTH
                }
-               syslog(LOG_INFO, "%s: %s from %s",
-                   ifp->name, op, ctx->sfrom);
+               loginfo("%s: %s from %s", ifp->name, op, ctx->sfrom);
                o = dhcp6_findmoption(r, len, D6_OPTION_RECONF_MSG, &ol);
                if (o == NULL) {
-                       syslog(LOG_ERR,
-                           "%s: missing Reconfigure Message option",
+                       logerrx("%s: missing Reconfigure Message option",
                            ifp->name);
                        return;
                }
                if (ol != 1) {
-                       syslog(LOG_ERR, "%s: missing Reconfigure Message type",
+                       logerrx("%s: missing Reconfigure Message type",
                            ifp->name);
                        return;
                }
                switch(*o) {
                case DHCP6_RENEW:
                        if (state->state != DH6S_BOUND) {
-                               syslog(LOG_ERR, "%s: not bound, ignoring %s",
+                               logerrx("%s: not bound, ignoring %s",
                                    ifp->name, op);
                                return;
                        }
@@ -3031,7 +3009,7 @@ dhcp6_handledata(void *arg)
                        break;
                case DHCP6_INFORMATION_REQ:
                        if (state->state != DH6S_INFORMED) {
-                               syslog(LOG_ERR, "%s: not informed, ignoring %s",
+                               logerrx("%s: not informed, ignoring %s",
                                    ifp->name, op);
                                return;
                        }
@@ -3040,19 +3018,19 @@ dhcp6_handledata(void *arg)
                        dhcp6_startinform(ifp);
                        break;
                default:
-                       syslog(LOG_ERR, "%s: unsupported %s type %d",
+                       logerr("%s: unsupported %s type %d",
                            ifp->name, op, *o);
                        break;
                }
                return;
 #endif
        default:
-               syslog(LOG_ERR, "%s: invalid DHCP6 type %s (%d)",
+               logerrx("%s: invalid DHCP6 type %s (%d)",
                    ifp->name, op, r->type);
                return;
        }
        if (!valid_op) {
-               syslog(LOG_WARNING, "%s: invalid state for DHCP6 type %s (%d)",
+               logwarnx("%s: invalid state for DHCP6 type %s (%d)",
                    ifp->name, op, r->type);
                return;
        }
@@ -3061,7 +3039,7 @@ dhcp6_handledata(void *arg)
                free(state->recv);
                state->recv = malloc(len);
                if (state->recv == NULL) {
-                       syslog(LOG_ERR, "%s: malloc recv: %m", ifp->name);
+                       logerr(__func__);
                        return;
                }
        }
@@ -3078,8 +3056,7 @@ dhcp6_handledata(void *arg)
                }
                if (ap == NULL)
                        ap = TAILQ_FIRST(&state->addrs);
-               syslog(LOG_INFO, "%s: ADV %s from %s",
-                   ifp->name, ap->saddr, ctx->sfrom);
+               loginfo("%s: ADV %s from %s", ifp->name, ap->saddr, ctx->sfrom);
                if (ifp->ctx->options & DHCPCD_TEST)
                        break;
                dhcp6_startrequest(ifp);
@@ -3093,8 +3070,8 @@ dhcp6_handledata(void *arg)
                        break;
                }
        }
-       syslog(has_new ? LOG_INFO : LOG_DEBUG,
-           "%s: %s received from %s", ifp->name, op, ctx->sfrom);
+       lognewinfo = has_new ? loginfo : logdebug;
+       lognewinfo("%s: %s received from %s", ifp->name, op, ctx->sfrom);
 
        state->reason = NULL;
        eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
@@ -3127,7 +3104,7 @@ dhcp6_handledata(void *arg)
                                if (ap->flags & IPV6_AF_STALE)
                                        continue;
                                if (ap->prefix_vltime <= state->renew)
-                                       syslog(LOG_WARNING,
+                                       logwarnx(
                                            "%s: %s will expire before renewal",
                                            ifp->name, ap->saddr);
                                else
@@ -3146,8 +3123,7 @@ dhcp6_handledata(void *arg)
                                 * and T2 fields for the T1 and T2 parameters,
                                 * unless those values in those fields are 0.
                                 */
-                               syslog(LOG_WARNING,
-                                   "%s: ignoring T1 %"PRIu32
+                               logwarnx("%s: ignoring T1 %"PRIu32
                                    " to due address expiry",
                                    ifp->name, state->renew);
                                state->renew = state->rebind = 0;
@@ -3195,19 +3171,16 @@ dhcp6_handledata(void *arg)
                ipv6_addaddrs(&state->addrs);
 
                if (state->state == DH6S_INFORMED)
-                       syslog(has_new ? LOG_INFO : LOG_DEBUG,
-                           "%s: refresh in %"PRIu32" seconds",
+                       lognewinfo("%s: refresh in %"PRIu32" seconds",
                            ifp->name, state->renew);
                else if (state->renew || state->rebind)
-                       syslog(has_new ? LOG_INFO : LOG_DEBUG,
-                           "%s: renew in %"PRIu32", "
+                       lognewinfo("%s: renew in %"PRIu32", "
                            "rebind in %"PRIu32", "
                            "expire in %"PRIu32" seconds",
                            ifp->name,
                            state->renew, state->rebind, state->expire);
                else if (state->expire == 0)
-                       syslog(has_new ? LOG_INFO : LOG_DEBUG,
-                           "%s: will expire", ifp->name);
+                       lognewinfo("%s: will expire", ifp->name);
                if_initrt(ifp->ctx, AF_INET6);
                rt_build(ifp->ctx, AF_INET6);
                dhcp6_writelease(ifp);
@@ -3258,7 +3231,7 @@ dhcp6_open(struct dhcpcd_ctx *ctx)
        n = 1;
        if (setsockopt(ctx->dhcp6_fd, SOL_SOCKET, SO_REUSEPORT,
            &n, sizeof(n)) == -1)
-               syslog(LOG_WARNING, "setsockopt: SO_REUSEPORT: %m");
+               logerr("SO_REUSEPORT");
 #endif
 
        if (!(ctx->options & DHCPCD_MASTER)) {
@@ -3309,14 +3282,12 @@ dhcp6_activateinterfaces(struct interface *ifp)
                        sla = &ia->sla[j];
                        ifd = if_find(ifp->ctx->ifaces, sla->ifname);
                        if (ifd == NULL) {
-                               syslog(LOG_WARNING,
-                                   "%s: cannot delegate to %s: %m",
+                               logwarn("%s: cannot delegate to %s",
                                    ifp->name, sla->ifname);
                                continue;
                        }
                        if (!ifd->active) {
-                               syslog(LOG_INFO,
-                                   "%s: activating for delegation",
+                               loginfo("%s: activating for delegation",
                                    sla->ifname);
                                dhcpcd_activateinterface(ifd,
                                    DHCPCD_IPV6 | DHCPCD_DHCP6);
@@ -3422,8 +3393,7 @@ gogogo:
        dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
            AF_INET6, ifp);
        if (ipv6_linklocal(ifp) == NULL) {
-               syslog(LOG_DEBUG,
-                   "%s: delaying DHCPv6 soliciation for LL address",
+               logdebug("%s: delaying DHCPv6 soliciation for LL address",
                    ifp->name);
                ipv6_addlinklocalcallback(ifp, dhcp6_start1, ifp);
                return 0;
@@ -3640,7 +3610,7 @@ dhcp6_env(char **env, const char *prefix, const struct interface *ifp,
                i = strlen(prefix) + strlen("_dhcp6") + 1;
                pfx = malloc(i);
                if (pfx == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return -1;
                }
                snprintf(pfx, i, "%s_dhcp6", prefix);
@@ -3720,7 +3690,7 @@ delegated:
                i += strlen(prefix) + strlen("_delegated_dhcp6_prefix=");
                 v = val = env[n] = malloc(i);
                if (v == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return -1;
                }
                v += snprintf(val, i, "%s_delegated_dhcp6_prefix=", prefix);
@@ -3750,15 +3720,15 @@ dhcp6_dump(struct interface *ifp)
 
        ifp->if_data[IF_DATA_DHCP6] = state = calloc(1, sizeof(*state));
        if (state == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return -1;
        }
        TAILQ_INIT(&state->addrs);
        dhcp_set_leasefile(state->leasefile, sizeof(state->leasefile),
            AF_INET6, ifp);
        if (dhcp6_readlease(ifp, 0) == -1) {
-               syslog(LOG_ERR, "%s: %s: %m",
-                   *ifp->name ? ifp->name : state->leasefile, __func__);
+               logerr("%s: %s", __func__,
+                   *ifp->name ? ifp->name : state->leasefile);
                return -1;
        }
        state->reason = "DUMP6";
index 4f574b9f10cbee85e16111c269e3dbd6847a7c72..35a9d3eb2f331d58e2c9afa3f1beea33d040e940 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 2, 2017
+.Dd April 8, 2017
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -39,6 +39,7 @@
 .Op Fl h , Fl Fl hostname Ar hostname
 .Op Fl I , Fl Fl clientid Ar clientid
 .Op Fl i , Fl Fl vendorclassid Ar vendorclassid
+.Op Fl j , Fl Fl logfile Ar logfile
 .Op Fl l , Fl Fl leasetime Ar seconds
 .Op Fl m , Fl Fl metric Ar metric
 .Op Fl O , Fl Fl nooption Ar option
@@ -342,6 +343,18 @@ For example
 If not set then none is sent.
 Some badly configured DHCP servers reject unknown vendorclassids.
 To work around it, try and impersonate Windows by using the MSFT vendorclassid.
+.It Fl j , Fl Fl logfile Ar logfile
+Writes to the specified
+.Ar logfile
+rather than
+.Xr syslog 3 .
+The
+.Ar logfile
+is truncated when opened and is reopened when
+.Nm
+receives the
+.Dv SIGUSR2
+signal.
 .It Fl k , Fl Fl release Op Ar interface
 This causes an existing
 .Nm
index 66dbb18a26a7a62ff84322b578c2bb65fa95f235..e7822dde1548deb0bea87053d4d9f28e09ca95b2 100644 (file)
@@ -44,7 +44,6 @@ const char dhcpcd_copyright[] = "Copyright (c) 2006-2017 Roy Marples";
 #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[] = "Copyright (c) 2006-2017 Roy Marples";
 #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",
+                       logdebug("%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",
+               logdebug("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");
+               loginfo("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");
+       logdebug("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);
+               loginfo("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);
+       loginfo("%s: removing interface", ifp->name);
        ifp->options->options |= DHCPCD_STOPPING;
 
        dhcpcd_drop(ifp, 1);
@@ -518,7 +515,7 @@ configure_interface1(struct interface *ifp)
        {
                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 *ifp, const char *profile)
                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);
+               logdebug("%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);
+               loginfo("%s: selected profile %s", ifp->name, profile);
        } else
                *ifp->profile = '\0';
 
@@ -599,8 +595,8 @@ configure_interface(struct interface *ifp, int argc, char **argv,
 
        /* 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, unsigned long long options)
 
        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, unsigned long long options)
                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 *ctx, int carrier, unsigned int flags,
 
        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);
+                               loginfo("%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 *ctx, int carrier, unsigned int flags,
                }
        } else if (carrier == LINK_UP && ifp->flags & IFF_UP) {
                if (ifp->carrier != LINK_UP) {
-                       syslog(LOG_INFO, "%s: carrier acquired", ifp->name);
+                       loginfo("%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, uint8_t *iaid)
 
        /* 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);
+                       loginfo("%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",
+                       loginfo("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,
+               loginfo("%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",
+                               loginfo("%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",
+               loginfo("%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 action, const char *ifname)
                        return -1;
                }
                if (ifp->active) {
-                       syslog(LOG_DEBUG, "%s: interface departed",
-                           ifp->name);
+                       logdebug("%s: interface departed", ifp->name);
                        ifp->options->options |= DHCPCD_DEPARTED;
                        stop_interface(ifp);
                }
@@ -1003,7 +995,7 @@ dhcpcd_handleinterface(void *arg, int action, const char *ifname)
        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 action, const char *ifname)
                iff = if_find(ctx->ifaces, ifp->name);
                if (iff) {
                        if (iff->active)
-                               syslog(LOG_DEBUG, "%s: interface updated",
-                                   iff->name);
+                               logdebug("%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 action, const char *ifname)
                        TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
                        if (!ifp->active)
                                continue;
-                       syslog(LOG_DEBUG, "%s: interface added", ifp->name);
+                       logdebug("%s: interface added", ifp->name);
                        dhcpcd_initstate(ifp, 0);
                        run_preinit(ifp);
                        iff = ifp;
@@ -1072,14 +1063,14 @@ dhcpcd_handlehwaddr(struct dhcpcd_ctx *ctx, const char *ifname,
 
        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,
+       loginfo("%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");
+               loginfo(sigmsg, "SIGINT", "stopping");
                break;
        case SIGTERM:
-               syslog(LOG_INFO, sigmsg, "SIGTERM", "stopping");
+               loginfo(sigmsg, "SIGTERM", "stopping");
                exit_code = EXIT_SUCCESS;
                break;
        case SIGALRM:
-               syslog(LOG_INFO, sigmsg, "SIGALRM", "releasing");
+               loginfo(sigmsg, "SIGALRM", "releasing");
                opts |= DHCPCD_RELEASE;
                exit_code = EXIT_SUCCESS;
                break;
        case SIGHUP:
-               syslog(LOG_INFO, sigmsg, "SIGHUP", "rebinding");
+               loginfo(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");
+               loginfo(sigmsg, "SIGUSR1", "renewing");
                dhcpcd_renew(ctx);
                return;
        case SIGUSR2:
-               closelog();
-               openlog(NULL, ctx->log_opts, LOG_DAEMON);
-               syslog(LOG_INFO, sigmsg, "SIGUSR2", "reopened syslog");
+               loginfo(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, struct fd_list *fd,
                *p++ = ' ';
        }
        *--p = '\0';
-       syslog(LOG_INFO, "control command: %s", tmp);
+       loginfo("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_WLOG;
        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_WLOG;
                        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,12 +1634,12 @@ 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;
        }
 
@@ -1664,7 +1649,7 @@ printpidfile:
        if (sig == 0) {
 #endif
                if (if_opensockets(&ctx) == -1) {
-                       syslog(LOG_ERR, "if_opensockets: %m");
+                       logerr("%s: if_opensockets", __func__);
                        goto exit_failure;
                }
 #ifdef USE_SIGNALS
@@ -1682,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)
@@ -1733,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");
+                       loginfo("sending commands to master dhcpcd process");
                        len = control_send(&ctx, argc, argv);
                        control_close(&ctx);
                        if (len > 0) {
-                               syslog(LOG_DEBUG, "send OK");
+                               logdebug("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
        }
@@ -1756,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);
+                       loginfo("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);
@@ -1774,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);
+                       loginfo("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++) {
@@ -1782,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;
                }
        }
@@ -1790,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;
@@ -1808,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");
+       logdebug(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
@@ -1853,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) {
@@ -1867,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 ?
+                           logdebug : 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;
                }
        }
@@ -1916,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 ?
+                           logdebug : logwarnx;
+                       logfunc("no interfaces have a carrier");
                        if (dhcpcd_daemonise(&ctx))
                                goto exit_success;
                } else if (t > 0 &&
@@ -1941,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;
@@ -1955,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))) {
@@ -1979,8 +1964,8 @@ exit1:
        free(ctx.iov[0].iov_base);
 
        if (ctx.options & DHCPCD_STARTED && !(ctx.options & DHCPCD_FORKED))
-               syslog(LOG_INFO, PACKAGE " exited");
-       closelog();
+               loginfo(PACKAGE " exited");
+       logclose();
 #ifdef USE_SIGNALS
        if (ctx.options & DHCPCD_FORKED)
                _exit(i); /* so atexit won't remove our pidfile */
index 912366e1827711a0eead5fb7336f3c8dd66fbe11..2038296f53045a022f7591baceef85f909b702ae 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 2, 2017
+.Dd April 8, 2017
 .Dt DHCPCD.CONF 5
 .Os
 .Sh NAME
@@ -413,6 +413,18 @@ globally but needs to be enabled for one interface.
 .It Ic leasetime Ar seconds
 Request a leasetime of
 .Ar seconds .
+.It Ic logfile Ar logfile
+Writes to the specified
+.Ar logfile
+rather than
+.Xr syslog 3 .
+The
+.Ar logfile
+is truncated when opened and is reopened when
+.Nm dhcpcd
+receives the
+.Dv SIGUSR2
+signal.
 .It Ic metric Ar metric
 Metrics are used to prefer an interface over another one, lowest wins.
 .Nm dhcpcd
index 8d32fb49847511e09907b8cbb2835d6ed934ed13..55235e641b58603d46c193f77172540f8ee09389 100644 (file)
@@ -119,7 +119,7 @@ struct dhcpcd_ctx {
        char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1];
        const char *cffile;
        unsigned long long options;
-       int log_opts;
+       char *logfile;
        int argc;
        char **argv;
        int ifac;       /* allowed interfaces */
index d50b8a642524ecda7012d57c4644cfa3f92e7883..3e8ed227efecd1ac83a19925d01e54fb3daf81d9 100644 (file)
@@ -42,7 +42,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -53,6 +52,7 @@
 #include "common.h"
 #include "dhcpcd.h"
 #include "duid.h"
+#include "logerr.h"
 
 static size_t
 duid_make(uint8_t *d, const struct interface *ifp, uint16_t type)
@@ -101,13 +101,13 @@ duid_get(uint8_t **d, const struct interface *ifp)
                        *d = data;
                        return len;
                }
-               syslog(LOG_ERR, "DUID too big (max %u): %s", DUID_LEN, DUID);
+               logerrx("DUID too big (max %u): %s", DUID_LEN, DUID);
                /* Keep the buffer, will assign below. */
        } else {
                if (errno != ENOENT)
-                       syslog(LOG_ERR, "error reading DUID: %s: %m", DUID);
+                       logerr("%s", DUID);
                if ((data = malloc(DUID_LEN)) == NULL) {
-                       syslog(LOG_ERR, "%s: malloc: %m", __func__);
+                       logerr(__func__);
                        return 0;
                }
        }
@@ -117,26 +117,24 @@ duid_get(uint8_t **d, const struct interface *ifp)
 
        /* No file? OK, lets make one based on our interface */
        if (ifp->family == ARPHRD_NETROM) {
-               syslog(LOG_WARNING, "%s: is a NET/ROM pseudo interface",
-                   ifp->name);
+               logwarnx("%s: is a NET/ROM pseudo interface", ifp->name);
                TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
                        if (ifp2->family != ARPHRD_NETROM)
                                break;
                }
                if (ifp2) {
                        ifp = ifp2;
-                       syslog(LOG_WARNING,
-                           "picked interface %s to generate a DUID",
+                       logwarnx("picked interface %s to generate a DUID",
                            ifp->name);
                } else {
-                       syslog(LOG_WARNING,
-                           "no interfaces have a fixed hardware address");
+                       logwarnx("no interfaces have a fixed hardware "
+                           "address");
                        return duid_make(data, ifp, DUID_LL);
                }
        }
 
        if (!(fp = fopen(DUID, "w"))) {
-               syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+               logerr("%s", DUID);
                return duid_make(data, ifp, DUID_LL);
        }
        len = duid_make(data, ifp, DUID_LLT);
@@ -145,7 +143,7 @@ duid_get(uint8_t **d, const struct interface *ifp)
                x = -1;
        /* Failed to write the duid? scrub it, we cannot use it */
        if (x < 1) {
-               syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
+               logerr("%s", DUID);
                unlink(DUID);
                return duid_make(data, ifp, DUID_LL);
        }
index f58dd2cbe98e83450a0b27942349cc609712fabb..dbbf4c1e0ecbf880ad9c1e3b692714ca1ea3a189 100644 (file)
@@ -66,7 +66,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #if defined(OpenBSD) && OpenBSD >= 201411
@@ -84,6 +83,7 @@
 #include "ipv4ll.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "route.h"
 #include "sa.h"
 
@@ -155,7 +155,7 @@ if_opensockets_os(struct dhcpcd_ctx *ctx)
 #ifdef ROUTE_MSGFILTER
        if (setsockopt(ctx->link_fd, PF_ROUTE, ROUTE_MSGFILTER,
            &msgfilter, sizeof(msgfilter)) == -1)
-               syslog(LOG_ERR, "ROUTE_MSGFILTER: %m");
+               logerr(__func__);
 #endif
 
        return ctx->link_fd == -1 ? -1 : 0;
@@ -1058,8 +1058,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
                        ifr_sin->sin_family = AF_INET;
                        ifr_sin->sin_addr = addr;
                        if (ioctl(ctx->pf_inet_fd, SIOCGIFADDR, &ifr) == 0) {
-                               syslog(LOG_WARNING,
-                                   "%s: ignored false RTM_DELADDR for %s",
+                               logwarnx("%s: ignored false RTM_DELADDR for %s",
                                    ifp->name, inet_ntoa(addr));
                                break;
                        }
@@ -1070,7 +1069,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
                if (ifam->ifam_type == RTM_DELADDR)
                        addrflags = 0 ;
                else if ((addrflags = if_addrflags(ifp, &addr, NULL)) == -1) {
-                       syslog(LOG_ERR, "%s: if_addrflags: %s: %m",
+                       logerr("%s: if_addrflags: %s",
                            ifp->name, inet_ntoa(addr));
                        break;
                }
@@ -1096,7 +1095,7 @@ if_ifa(struct dhcpcd_ctx *ctx, const struct ifa_msghdr *ifam)
                if (ifam->ifam_type == RTM_DELADDR)
                    addrflags = 0;
                else if ((addrflags = if_addrflags6(ifp, &addr6, NULL)) == -1) {
-                       syslog(LOG_ERR, "%s: if_addrflags6: %m", ifp->name);
+                       logerr("%s: if_addrflags6", ifp->name);
                        break;
                }
 #endif
@@ -1337,8 +1336,8 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                if (!(ctx->options & DHCPCD_TEST) &&
                    flags & ND6_IFF_AUTO_LINKLOCAL)
                {
-                       syslog(LOG_DEBUG,
-                           "%s: disabling Kernel IPv6 auto link-local support",
+                       logdebug("%s: disabling Kernel IPv6 auto "
+                           "link-local support",
                            ifp->name);
                        flags &= ~ND6_IFF_AUTO_LINKLOCAL;
                }
@@ -1355,8 +1354,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                if (!(ctx->options & DHCPCD_TEST) &&
                    flags & ND6_IFF_ACCEPT_RTADV)
                {
-                       syslog(LOG_DEBUG,
-                           "%s: disabling Kernel IPv6 RA support",
+                       logdebug("%s: disabling Kernel IPv6 RA support",
                            ifp->name);
                        flags &= ~ND6_IFF_ACCEPT_RTADV;
                }
@@ -1373,15 +1371,13 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
 
                if (nd.ndi.flags != (uint32_t)flags) {
                        if (ctx->options & DHCPCD_TEST) {
-                               syslog(LOG_WARNING,
-                                   "%s: interface not IPv6 enabled",
+                               logwarnx("%s: interface not IPv6 enabled",
                                    ifp->name);
                                return -1;
                        }
                        nd.ndi.flags = (uint32_t)flags;
                        if (ioctl(s, SIOCSIFINFO_FLAGS, &nd) == -1) {
-                               syslog(LOG_ERR, "%s: SIOCSIFINFO_FLAGS: %m",
-                                   ifp->name);
+                               logerr("%s: SIOCSIFINFO_FLAGS", ifp->name);
                                return -1;
                        }
                }
@@ -1391,14 +1387,14 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                 * LLADDR auto configuration are disabled where applicable. */
 #ifdef SIOCIFAFATTACH
                if (af_attach(s, ifp, AF_INET6) == -1) {
-                       syslog(LOG_ERR, "%s: af_attach: %m", ifp->name);
+                       logerr("%s: af_attach", ifp->name);
                        return -1;
                }
 #endif
 
 #ifdef SIOCGIFXFLAGS
                if (set_ifxflags(s, ifp) == -1) {
-                       syslog(LOG_ERR, "%s: set_ifxflags: %m", ifp->name);
+                       logerr("%s: set_ifxflags", ifp->name);
                        return -1;
                }
 #endif
@@ -1424,14 +1420,14 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
 #ifdef IPV6CTL_ACCEPT_RTADV
        ra = get_inet6_sysctl(IPV6CTL_ACCEPT_RTADV);
        if (ra == -1)
-               /* The sysctl probably doesn't exist, but this isn't an
-                * error as such so just log it and continue */
-               syslog(errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
-                   "IPV6CTL_ACCEPT_RTADV: %m");
+               if (errno == ENOENT)
+                       ra = 0;
+               else
+                       logerr("IPV6CTL_ACCEPT_RTADV");
        else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
-               syslog(LOG_DEBUG, "disabling Kernel IPv6 RA support");
+               logdebug("disabling Kernel IPv6 RA support");
                if (set_inet6_sysctl(IPV6CTL_ACCEPT_RTADV, 0) == -1) {
-                       syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
+                       logerr("IPV6CTL_ACCEPT_RTADV");
                        return ra;
                }
                ra = 0;
@@ -1443,7 +1439,7 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                 * and prefixes so the kernel does not expire prefixes
                 * and default routes we are trying to own. */
                if (if_raflush(s) == -1)
-                       syslog(LOG_WARNING, "if_raflush: %m");
+                       logwarn("if_raflush");
        }
 
        ctx->ra_global = ra;
index 4f70583bf5f7e314119018c24fa5ceb4d8c186f6..9b0a6e7f2b92918e35a875ed568a74820aac3044 100644 (file)
@@ -54,7 +54,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -68,6 +67,7 @@
 #include "ipv4ll.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "route.h"
 #include "sa.h"
 
@@ -1644,8 +1644,8 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
                ifname = "all";
        else if (!(ctx->options & DHCPCD_TEST)) {
                if (if_disable_autolinklocal(ctx, ifp->index) == -1)
-                       syslog(LOG_DEBUG, "%s: if_disable_autolinklocal: %m",
-                           ifp->name);
+                       logdebug("%s: if_disable_autolinklocal: %s",
+                           ifp->name, strerror(errno));
        }
        if (ifp)
                ifname = ifp->name;
@@ -1654,26 +1654,26 @@ if_checkipv6(struct dhcpcd_ctx *ctx, const struct interface *ifp)
        ra = check_proc_int(path);
        if (ra != 1) {
                if (ctx->options & DHCPCD_TEST)
-                       syslog(LOG_WARNING, "%s: IPv6 kernel autoconf disabled",
-                           ifname);
+                       logwarnx("%s: IPv6 kernel autoconf disabled", ifname);
        } else if (ra != -1 && !(ctx->options & DHCPCD_TEST)) {
                if (write_path(path, "0") == -1) {
-                       syslog(LOG_ERR, "write_path: %s: %m", path);
+                       logerr("%s: %s", __func__, path);
                        return -1;
                }
        }
 
        snprintf(path, sizeof(path), "%s/%s/accept_ra", prefix, ifname);
        ra = check_proc_int(path);
-       if (ra == -1)
+       if (ra == -1) {
+               logfunc_t *logfunc = errno == ENOENT? logdebug : logwarnx;
+
                /* The sysctl probably doesn't exist, but this isn't an
                 * error as such so just log it and continue */
-               syslog(errno == ENOENT ? LOG_DEBUG:LOG_WARNING, "%s: %m", path);
-       else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
-               syslog(LOG_DEBUG, "%s: disabling kernel IPv6 RA support",
-                   ifname);
+               logfunc("%s: %s", path, strerror(errno));
+       } else if (ra != 0 && !(ctx->options & DHCPCD_TEST)) {
+               logdebug("%s: disabling kernel IPv6 RA support", ifname);
                if (write_path(path, "0") == -1) {
-                       syslog(LOG_ERR, "write_path: %s: %m", path);
+                       logerr("%s: %s", __func__, path);
                        return ra;
                }
                return 0;
index f8fe541581e185bd8161338d978cdcc24de578cb..9bc2f235f9fb591b194a0c14e708e0c87acd9e8d 100644 (file)
@@ -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",         optional_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, const char *value, int uniq)
 
        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, const char *value, int uniq)
                        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, const char *value, int uniq)
                                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, const char *value, int uniq)
        free(match);
        n = strdup(value);
        if (n == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return NULL;
        }
        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 char *arg)
        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 = 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 in_addr *net, const char *arg)
                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 struct in_addr *net,
     __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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                }
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                    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, const char *ifname, struct if_options *ifo,
                    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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                            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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
                    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, const char *ifname, struct if_options *ifo,
                    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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
 
                        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, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                                        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, const char *ifname, struct if_options *ifo,
                                        {
                                                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, const char *ifname, struct if_options *ifo,
                        }
                        p = strdup(arg);
                        if (p == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                return -1;
                        }
                        nconf = reallocarray(ifo->config, dl+2, sizeof(char *));
                        if (nconf == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                free(p);
                                return -1;
                        }
@@ -1157,7 +1166,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                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;
@@ -1172,7 +1181,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                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;
@@ -1218,7 +1227,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                    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, const char *ifname, struct if_options *ifo,
                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, const char *ifname, struct if_options *ifo,
        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, const char *ifname, struct if_options *ifo,
        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, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                        }
                }
                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 = 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, const char *ifname, struct if_options *ifo,
                                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;
@@ -1396,7 +1403,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                                            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, const char *ifname, struct if_options *ifo,
                                        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, const char *ifname, struct if_options *ifo,
                                        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, const char *ifname, struct if_options *ifo,
                        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, const char *ifname, struct if_options *ifo,
                                    (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, const char *ifname, struct if_options *ifo,
                                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, const char *ifname, struct if_options *ifo,
                                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 {
@@ -1772,7 +1771,7 @@ err_sla:
                if (ndop == NULL) {
                        ndop = reallocarray(*dop, *dop_len + 1, sizeof(**dop));
                        if (ndop == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                free(np);
                                return -1;
                        }
@@ -1815,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);
@@ -1842,7 +1841,7 @@ err_sla:
                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;
@@ -1864,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);
@@ -1884,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;
@@ -1900,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:
@@ -1914,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;
                }
@@ -1947,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,
@@ -1960,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;
@@ -1979,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;
@@ -1994,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;
@@ -2005,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;
@@ -2034,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)) ==
@@ -2042,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;
                        }
@@ -2057,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;
                }
@@ -2071,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;
@@ -2105,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;
@@ -2118,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
@@ -2137,8 +2138,7 @@ parse_config_line(struct dhcpcd_ctx *ctx, const char *ifname,
                        continue;
 
                if (cf_options[i].has_arg == required_argument && !line) {
-                       syslog(LOG_ERR, "option requires an argument -- %s",
-                           opt);
+                       logerrx("option requires an argument -- %s", opt);
                        return -1;
                }
 
@@ -2146,7 +2146,7 @@ parse_config_line(struct dhcpcd_ctx *ctx, const char *ifname,
                    ldop, edop);
        }
 
-       syslog(LOG_ERR, "unknown option: %s", opt);
+       logerrx("unknown option: %s", opt);
        return -1;
 }
 
@@ -2211,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;
@@ -2284,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
@@ -2293,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
@@ -2301,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
@@ -2310,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;
                }
@@ -2330,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;
@@ -2406,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;
        }
@@ -2453,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++;
index b2fac034ca2cb2270c0e4996ac526cfd0a441237..c63fb8c68edcb451fe099693e84dfed458ec9fa9 100644 (file)
@@ -42,7 +42,7 @@
 
 /* Don't set any optional arguments here so we retain POSIX
  * compatibility with getopt */
-#define IF_OPTS "146bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:" \
+#define IF_OPTS "146bc:de:f:gh:i:j:kl:m:no:pqr:s:t:u:v:wxy:z:" \
                "ABC:DEF:HI:JKLMNO:PQ:S:TUVW:X:Z:"
 #define NOERR_IF_OPTS          ":" IF_OPTS
 
index 0e6fb83c7c82fa13c1dfe826ed3ac3ba592b03d9..477f9c28336bfa257647e9d55a9fb92ab5ba674b 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -58,7 +58,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -71,6 +70,7 @@
 #include "ipv4.h"
 #include "ipv4ll.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 
 void
 if_free(struct interface *ifp)
@@ -225,8 +225,7 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
                            ifa->ifa_name);
                        if (addrflags == -1) {
                                if (errno != EEXIST)
-                                       syslog(LOG_ERR,
-                                           "%s: if_addrflags: %s: %m",
+                                       logerr("%s: if_addrflags: %s",
                                            __func__,
                                            inet_ntoa(addr->sin_addr));
                                continue;
@@ -252,8 +251,7 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs,
                            ifa->ifa_name);
                        if (addrflags == -1) {
                                if (errno != EEXIST)
-                                       syslog(LOG_ERR,
-                                           "%s: if_addrflags6:  %m", __func__);
+                                       logerr("%s: if_addrflags6", __func__);
                                continue;
                        }
 #endif
@@ -361,15 +359,20 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                }
 
                if (if_vimaster(ctx, spec.devname) == 1) {
-                       syslog(argc ? LOG_ERR : LOG_DEBUG,
-                           "%s: is a Virtual Interface Master, skipping",
-                           spec.devname);
+                       if (argc)
+                               logerr("%s: is a Virtual Interface Master, "
+                                   "skipping",
+                                   spec.devname);
+                       else
+                               logdebug("%s: is a Virtual Interface Master, "
+                                   "skipping",
+                                   spec.devname);
                        continue;
                }
 
                ifp = calloc(1, sizeof(*ifp));
                if (ifp == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        break;
                }
                ifp->ctx = ctx;
@@ -413,8 +416,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                                    ctx->ifac == 0 && active &&
                                    !if_hasconf(ctx, ifp->name))
                                {
-                                       syslog(LOG_DEBUG,
-                                           "%s: ignoring due to"
+                                       logdebug("%s: ignoring due to"
                                            " interface type and"
                                            " no config",
                                            ifp->name);
@@ -448,8 +450,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                                    !if_hasconf(ctx, ifp->name))
                                        active = IF_INACTIVE;
                                if (active)
-                                       syslog(LOG_WARNING,
-                                           "%s: unsupported"
+                                       logwarnx("%s: unsupported"
                                            " interface type %.2x",
                                            ifp->name, sdl->sdl_type);
                                /* Pretend it's ethernet */
@@ -494,8 +495,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
 #ifndef AF_LINK
                        default:
                                if (active)
-                                       syslog(LOG_WARNING,
-                                           "%s: unsupported"
+                                       logwarnx("%s: unsupported"
                                            " interface family %.2x",
                                            ifp->name, ifp->family);
                                break;
@@ -506,7 +506,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
                        /* Handle any platform init for the interface */
                        if (active != IF_INACTIVE && if_init(ifp) == -1) {
-                               syslog(LOG_ERR, "%s: if_init: %m", ifp->name);
+                               logerr("%s: if_init", ifp->name);
                                if_free(ifp);
                                continue;
                        }
@@ -515,7 +515,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
                        if (if_getmtu(ifp) < MTU_MIN && active &&
                            if_setmtu(ifp, MTU_MIN) == -1)
                        {
-                               syslog(LOG_ERR, "%s: if_setmtu: %m", ifp->name);
+                               logerr("%s: if_setmtu", ifp->name);
                                if_free(ifp);
                                continue;
                        }
index aa1f20c7e05f19fc6ae12d9a5ca054a94e277a6a..6a1aed15cbf3bcde7ea8d94a04007c36dcc05b47 100644 (file)
@@ -40,7 +40,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
@@ -52,6 +51,7 @@
 #include "if-options.h"
 #include "ipv4.h"
 #include "ipv4ll.h"
+#include "logerr.h"
 #include "route.h"
 #include "script.h"
 #include "sa.h"
@@ -382,8 +382,8 @@ inet_routerhostroute(struct rt_head *routes, struct interface *ifp)
                                char buf[INET_MAX_ADDRSTRLEN];
 
                                ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
-                               syslog(LOG_WARNING,
-                                   "%s: forcing router %s through interface",
+                               logwarnx("%s: forcing router %s through "
+                                   "interface",
                                    ifp->name,
                                    sa_addrtop(&rt->rt_gateway,
                                    buf, sizeof(buf)));
@@ -397,8 +397,7 @@ inet_routerhostroute(struct rt_head *routes, struct interface *ifp)
                        char buf[INET_MAX_ADDRSTRLEN];
 
                        ifo->options |= DHCPCD_ROUTER_HOST_ROUTE_WARNED;
-                       syslog(LOG_WARNING,
-                           "%s: router %s requires a host route",
+                       logwarnx("%s: router %s requires a host route",
                            ifp->name,
                            sa_addrtop(&rt->rt_gateway, buf, sizeof(buf)));
                }
@@ -462,14 +461,14 @@ ipv4_deladdr(struct ipv4_addr *addr, int keeparp)
        UNUSED(keeparp);
 #endif
 
-       syslog(LOG_DEBUG, "%s: deleting IP address %s",
+       logdebug("%s: deleting IP address %s",
            addr->iface->name, addr->saddr);
 
        r = if_address(RTM_DELADDR, addr);
        if (r == -1 &&
            errno != EADDRNOTAVAIL && errno != ESRCH &&
            errno != ENXIO && errno != ENODEV)
-               syslog(LOG_ERR, "%s: %s: %m", addr->iface->name, __func__);
+               logerr("%s: %s", addr->iface->name, __func__);
 
 #ifdef ARP
        if (!keeparp && (astate = arp_find(addr->iface, &addr->addr)) != NULL)
@@ -525,7 +524,7 @@ ipv4_getstate(struct interface *ifp)
                ifp->if_data[IF_DATA_IPV4] = malloc(sizeof(*state));
                state = IPV4_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return NULL;
                }
                TAILQ_INIT(&state->addrs);
@@ -593,7 +592,7 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
 #endif
 
        if ((state = ipv4_getstate(ifp)) == NULL) {
-               syslog(LOG_ERR, "%s: ipv4_getstate: %m", __func__);
+               logerr(__func__);
                return NULL;
        }
        if (ifp->options->options & DHCPCD_NOALIAS) {
@@ -606,7 +605,7 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
        }
 
        if ((ia = malloc(sizeof(*ia))) == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return NULL;
        }
 
@@ -623,19 +622,19 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr,
 #ifdef ALIAS_ADDR
        blank = (ia->alias[0] == '\0');
        if ((replaced = ipv4_aliasaddr(ia, &replaced_ia)) == -1) {
-               syslog(LOG_ERR, "%s: ipv4_aliasaddr: %m", ifp->name);
+               logerr("%s: ipv4_aliasaddr", ifp->name);
                free(ia);
                return NULL;
        }
        if (blank)
-               syslog(LOG_DEBUG, "%s: aliased %s", ia->alias, ia->saddr);
+               logdebug("%s: aliased %s", ia->alias, ia->saddr);
 #endif
 
-       syslog(LOG_DEBUG, "%s: adding IP address %s broadcast %s",
+       logdebug("%s: adding IP address %s broadcast %s",
            ifp->name, ia->saddr, inet_ntoa(*bcast));
        if (if_address(RTM_NEWADDR, ia) == -1) {
                if (errno != EEXIST)
-                       syslog(LOG_ERR, "%s: if_addaddress: %m",
+                       logerr("%s: if_addaddress",
                            __func__);
                free(ia);
                return NULL;
@@ -750,14 +749,13 @@ ipv4_applyaddr(void *arg)
                    nstate->addr->addr.s_addr == lease->addr.s_addr)
                {
                        if (r == 0) {
-                               syslog(LOG_INFO,
-                                   "%s: preferring %s on %s",
+                               loginfo("%s: preferring %s on %s",
                                    ifp->name,
                                    inet_ntoa(lease->addr),
                                    ifn->name);
                                return;
                        }
-                       syslog(LOG_INFO, "%s: preferring %s on %s",
+                       loginfo("%s: preferring %s on %s",
                            ifn->name,
                            inet_ntoa(lease->addr),
                            ifp->name);
@@ -782,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)
-               syslog(LOG_DEBUG, "%s: IP address %s already exists",
+               logdebug("%s: IP address %s already exists",
                    ifp->name, ia->saddr);
        else {
 #if __linux__
@@ -799,8 +797,7 @@ ipv4_applyaddr(void *arg)
 
        ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
        if (ia == NULL) {
-               syslog(LOG_ERR, "%s: added address vanished",
-                   ifp->name);
+               logerrx("%s: added address vanished", ifp->name);
                return;
        }
 #if defined(ARP) && defined(IN_IFF_NOTUSEABLE)
@@ -868,7 +865,7 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx,
        case RTM_NEWADDR:
                if (ia == NULL) {
                        if ((ia = malloc(sizeof(*ia))) == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                return;
                        }
                        ia->iface = ifp;
index b5822a2ca370b46d0e60756a30fe9339ee21ed31..e9b50ad85270c26703ea6d58ffb218542236329c 100644 (file)
@@ -33,7 +33,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 6
@@ -45,6 +44,7 @@
 #include "if-options.h"
 #include "ipv4.h"
 #include "ipv4ll.h"
+#include "logerr.h"
 #include "sa.h"
 #include "script.h"
 
@@ -189,7 +189,7 @@ ipv4ll_probed(struct arp_state *astate)
 #ifdef IN_IFF_NOTREADY
        if (ia == NULL || ia->addr_flags & IN_IFF_NOTREADY)
 #endif
-               syslog(LOG_INFO, "%s: using IPv4LL address %s",
+               loginfo("%s: using IPv4LL address %s",
                  ifp->name, inet_ntoa(astate->addr));
        if (ia == NULL) {
                if (ifp->ctx->options & DHCPCD_TEST)
@@ -202,7 +202,7 @@ ipv4ll_probed(struct arp_state *astate)
 #ifdef IN_IFF_NOTREADY
        if (ia->addr_flags & IN_IFF_NOTREADY)
                return;
-       syslog(LOG_DEBUG, "%s: DAD completed for %s",
+       logdebug("%s: DAD completed for %s",
            ifp->name, inet_ntoa(astate->addr));
 #endif
 test:
@@ -274,7 +274,7 @@ ipv4ll_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
            astate->failed.s_addr == state->addr->addr.s_addr)
        {
 #ifdef KERNEL_RFC5227
-               syslog(LOG_WARNING, "%s: IPv4LL defence failed for %s",
+               logwarnx("%s: IPv4LL defence failed for %s",
                    ifp->name, state->addr->saddr);
 #else
                struct timespec now, defend;
@@ -291,14 +291,13 @@ ipv4ll_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
                defend.tv_nsec = state->defend.tv_nsec;
                clock_gettime(CLOCK_MONOTONIC, &now);
                if (timespeccmp(&defend, &now, >))
-                       syslog(LOG_WARNING,
-                           "%s: IPv4LL %d second defence failed for %s",
+                       logwarnx("%s: IPv4LL %d second defence failed for %s",
                            ifp->name, DEFEND_INTERVAL, state->addr->saddr);
                else if (arp_request(ifp,
                    state->addr->addr.s_addr, state->addr->addr.s_addr) == -1)
-                       syslog(LOG_ERR, "%s: arp_request: %m", __func__);
+                       logerr(__func__);
                else {
-                       syslog(LOG_DEBUG, "%s: defended IPv4LL address %s",
+                       logdebug("%s: defended IPv4LL address %s",
                            ifp->name, state->addr->saddr);
                        state->defend = now;
                        return;
@@ -318,7 +317,7 @@ ipv4ll_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
 
        arp_cancel(astate);
        if (++state->conflicts == MAX_CONFLICTS)
-               syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
+               logerr("%s: failed to acquire an IPv4LL address",
                    ifp->name);
        astate->addr.s_addr = ipv4ll_pickaddr(astate);
        eloop_timeout_add_sec(ifp->ctx->eloop,
@@ -350,7 +349,7 @@ ipv4ll_start(void *arg)
        if ((state = IPV4LL_STATE(ifp)) == NULL) {
                ifp->if_data[IF_DATA_IPV4LL] = calloc(1, sizeof(*state));
                if ((state = IPV4LL_STATE(ifp)) == NULL) {
-                       syslog(LOG_ERR, "%s: calloc %m", __func__);
+                       logerr(__func__);
                        return;
                }
        }
@@ -407,19 +406,17 @@ ipv4ll_start(void *arg)
                astate->addr = ia->addr;
 #ifdef IN_IFF_TENTATIVE
                if (ia->addr_flags & (IN_IFF_TENTATIVE | IN_IFF_DETACHED)) {
-                       syslog(LOG_INFO,
-                           "%s: waiting for DAD to complete on %s",
+                       loginfo("%s: waiting for DAD to complete on %s",
                            ifp->name, inet_ntoa(ia->addr));
                        return;
                }
-               syslog(LOG_INFO, "%s: using IPv4LL address %s",
-                   ifp->name, ia->saddr);
+               loginfo("%s: using IPv4LL address %s", ifp->name, ia->saddr);
 #endif
                ipv4ll_probed(astate);
                return;
        }
 
-       syslog(LOG_INFO, "%s: probing for an IPv4LL address", ifp->name);
+       loginfo("%s: probing for an IPv4LL address", ifp->name);
        astate->addr.s_addr = ipv4ll_pickaddr(astate);
 #ifdef IN_IFF_TENTATIVE
        ipv4ll_probed(astate);
index 9befa1ee1b5e7f485345b01e2c744435c38a581d..7acd06de4b6a0ac7059b5edaff8245d7ff18cafa 100644 (file)
@@ -55,7 +55,6 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 7
@@ -66,6 +65,7 @@
 #include "eloop.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "sa.h"
 #include "script.h"
 
@@ -170,7 +170,7 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx)
                return (ssize_t)ctx->secret_len;
 
        if (errno != ENOENT)
-               syslog(LOG_ERR, "error reading secret: %s: %m", SECRET);
+               logerr("%s: %s", __func__, SECRET);
 
        /* Chaining arc4random should be good enough.
         * RFC7217 section 5.1 states the key SHOULD be at least 128 bits.
@@ -178,7 +178,7 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx)
         * 512 bits (64 bytes). */
        if (ctx->secret_len < 64) {
                if ((ctx->secret = malloc(64)) == NULL) {
-                       syslog(LOG_ERR, "%s: malloc: %m", __func__);
+                       logerr(__func__);
                        return -1;
                }
                ctx->secret_len = 64;
@@ -205,7 +205,7 @@ ipv6_readsecret(struct dhcpcd_ctx *ctx)
                return (ssize_t)ctx->secret_len;
 
 eexit:
-       syslog(LOG_ERR, "error writing secret: %s: %m", SECRET);
+       logerr("%s: %s", __func__, SECRET);
        if (fp != NULL)
                fclose(fp);
        unlink(SECRET);
@@ -558,7 +558,7 @@ ipv6_checkaddrflags(void *arg)
        alias = NULL;
 #endif
        if ((flags = if_addrflags6(ia->iface, &ia->addr, alias)) == -1) {
-               syslog(LOG_ERR, "%s: if_addrflags6: %m", ia->iface->name);
+               logerr("%s: if_addrflags6", ia->iface->name);
                return;
        }
 
@@ -584,11 +584,11 @@ ipv6_deleteaddr(struct ipv6_addr *ia)
        struct ipv6_state *state;
        struct ipv6_addr *ap;
 
-       syslog(LOG_INFO, "%s: deleting address %s", ia->iface->name, ia->saddr);
+       loginfo("%s: deleting address %s", ia->iface->name, ia->saddr);
        if (if_address6(RTM_DELADDR, ia) == -1 &&
            errno != EADDRNOTAVAIL && errno != ESRCH &&
            errno != ENXIO && errno != ENODEV)
-               syslog(LOG_ERR, "if_address6: %m");
+               logerr(__func__);
 
        /* NOREJECT is set if we delegated exactly the prefix to another
         * address.
@@ -614,6 +614,7 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now)
        struct ipv6_state *state;
        struct ipv6_addr *nap;
        uint32_t pltime, vltime;
+       __printflike(1, 2) void (*logfunc)(const char *, ...);
 
        /* Ensure no other interface has this address */
        TAILQ_FOREACH(ifp, ap->iface->ctx->ifaces, next) {
@@ -634,8 +635,8 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now)
            ipv6_iffindaddr(ap->iface, &ap->addr, IN6_IFF_NOTUSEABLE))
                ap->flags |= IPV6_AF_DADCOMPLETED;
 
-       syslog(ap->flags & IPV6_AF_NEW ? LOG_INFO : LOG_DEBUG,
-           "%s: adding %saddress %s", ap->iface->name,
+       logfunc = ap->flags & IPV6_AF_NEW ? loginfo : logdebug;
+       logfunc("%s: adding %saddress %s", ap->iface->name,
 #ifdef IPV6_AF_TEMPORARY
            ap->flags & IPV6_AF_TEMPORARY ? "temporary " : "",
 #else
@@ -644,19 +645,17 @@ 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)
-               syslog(LOG_DEBUG, "%s: pltime infinity, vltime infinity",
+               logdebug("%s: pltime infinity, vltime infinity",
                    ap->iface->name);
        else if (ap->prefix_pltime == ND6_INFINITE_LIFETIME)
-               syslog(LOG_DEBUG,
-                   "%s: pltime infinity, vltime %"PRIu32" seconds",
+               logdebug("%s: pltime infinity, vltime %"PRIu32" seconds",
                    ap->iface->name, ap->prefix_vltime);
        else if (ap->prefix_vltime == ND6_INFINITE_LIFETIME)
-               syslog(LOG_DEBUG,
-                   "%s: pltime %"PRIu32"seconds, vltime infinity",
+               logdebug("%s: pltime %"PRIu32"seconds, vltime infinity",
                    ap->iface->name, ap->prefix_pltime);
        else
-               syslog(LOG_DEBUG,
-                   "%s: pltime %"PRIu32" seconds, vltime %"PRIu32" seconds",
+               logdebug("%s: pltime %"PRIu32" seconds, vltime %"PRIu32
+                   " seconds",
                    ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
 
        /* Adjust plftime and vltime based on acquired time */
@@ -684,21 +683,19 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now)
                        ap->prefix_vltime -= (uint32_t)n.tv_sec;
 
 #if 0
-               syslog(LOG_DEBUG,
-                   "%s: acquired %lld.%.9ld, now %lld.%.9ld, diff %lld.%.9ld",
+               logdebug("%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);
-               syslog(LOG_DEBUG,
-                   "%s: adj pltime %"PRIu32" seconds, "
+               logdebug("%s: adj pltime %"PRIu32" seconds, "
                    "vltime %"PRIu32" seconds",
                    ap->iface->name, ap->prefix_pltime, ap->prefix_vltime);
 #endif
        }
 
        if (if_address6(RTM_NEWADDR, ap) == -1) {
-               syslog(LOG_ERR, "if_addaddress6: %m");
+               logerr(__func__);
                /* Restore real pltime and vltime */
                ap->prefix_pltime = pltime;
                ap->prefix_vltime = vltime;
@@ -750,7 +747,7 @@ ipv6_addaddr1(struct ipv6_addr *ap, const struct timespec *now)
        }
        if (nap == NULL) {
                if ((nap = malloc(sizeof(*nap))) == NULL) {
-                       syslog(LOG_ERR, "%s: malloc: %m", __func__);
+                       logerr(__func__);
                        return 0; /* Well, we did add the address */
                }
                memcpy(nap, ap, sizeof(*nap));
@@ -833,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)
-               syslog(LOG_DEBUG, "%s: aliased %s", ia->alias, ia->saddr);
+               logdebug("%s: aliased %s", ia->alias, ia->saddr);
 #endif
 
        if ((r = ipv6_addaddr1(ia, now)) == 0) {
@@ -916,21 +913,19 @@ ipv6_addaddrs(struct ipv6_addrhead *addrs)
                            &ap->addr, IPV6_AF_ADDED);
                        if (apf && apf->iface != ap->iface) {
                                if (apf->iface->metric <= ap->iface->metric) {
-                                       syslog(LOG_INFO,
-                                           "%s: preferring %s on %s",
+                                       loginfo("%s: preferring %s on %s",
                                            ap->iface->name,
                                            ap->saddr,
                                            apf->iface->name);
                                        continue;
                                }
-                               syslog(LOG_INFO,
-                                   "%s: preferring %s on %s",
+                               loginfo("%s: preferring %s on %s",
                                    apf->iface->name,
                                    ap->saddr,
                                    ap->iface->name);
                                if (if_address6(RTM_DELADDR, apf) == -1 &&
                                    errno != EADDRNOTAVAIL && errno != ENXIO)
-                                       syslog(LOG_ERR, "if_address6: %m");
+                                       logerr(__func__);
                                apf->flags &=
                                    ~(IPV6_AF_ADDED | IPV6_AF_DADCOMPLETED);
                        } else if (apf)
@@ -1023,7 +1018,7 @@ ipv6_getstate(struct interface *ifp)
                ifp->if_data[IF_DATA_IPV6] = calloc(1, sizeof(*state));
                state = IPV6_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return NULL;
                }
                TAILQ_INIT(&state->addrs);
@@ -1053,7 +1048,7 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
 
        dbp = inet_ntop(AF_INET6, &addr->s6_addr,
            dbuf, INET6_ADDRSTRLEN);
-       syslog(LOG_INFO, "%s: cmd %d addr %s",
+       loginfo("%s: cmd %d addr %s",
            ifname, cmd, dbp);
 #endif
 
@@ -1084,7 +1079,7 @@ ipv6_handleifa(struct dhcpcd_ctx *ctx,
                        const char *cbp;
 
                        if ((ia = calloc(1, sizeof(*ia))) == NULL) {
-                               syslog(LOG_ERR, "%s: calloc: %m", __func__);
+                               logerr(__func__);
                                break;
                        }
 #ifdef ALIAS_ADDR
@@ -1261,7 +1256,7 @@ ipv6_addlinklocalcallback(struct interface *ifp,
        if (cb == NULL) {
                cb = malloc(sizeof(*cb));
                if (cb == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return -1;
                }
                cb->callback = callback;
@@ -1389,7 +1384,7 @@ nextslaacprivate:
                                return -1;
                        }
 
-                       syslog(LOG_WARNING, "%s: waiting for %s to complete",
+                       logwarnx("%s: waiting for %s to complete",
                            ap2->iface->name, ap2->saddr);
                        free(ap);
                        errno = EEXIST;
@@ -1469,10 +1464,10 @@ ipv6_staticdadcallback(void *arg)
        wascompleted = (ia->flags & IPV6_AF_DADCOMPLETED);
        ia->flags |= IPV6_AF_DADCOMPLETED;
        if (ia->flags & IPV6_AF_DUPLICATED)
-               syslog(LOG_WARNING, "%s: DAD detected %s", ia->iface->name,
+               logwarnx("%s: DAD detected %s", ia->iface->name,
                    ia->saddr);
        else if (!wascompleted) {
-               syslog(LOG_DEBUG, "%s: IPv6 static DAD completed",
+               logdebug("%s: IPv6 static DAD completed",
                    ia->iface->name);
        }
 
@@ -1677,7 +1672,7 @@ ipv6_handleifa_addrs(int cmd,
                switch (cmd) {
                case RTM_DELADDR:
                        if (ia->flags & IPV6_AF_ADDED) {
-                               syslog(LOG_INFO, "%s: deleted address %s",
+                               loginfo("%s: deleted address %s",
                                    ia->iface->name, ia->saddr);
                                ia->flags &= ~IPV6_AF_ADDED;
                        }
@@ -1821,14 +1816,13 @@ ipv6_tempdadcallback(void *arg)
                struct timespec tv;
 
                if (++ia->dadcounter == TEMP_IDGEN_RETRIES) {
-                       syslog(LOG_ERR,
-                           "%s: too many duplicate temporary addresses",
+                       logerrx("%s: too many duplicate temporary addresses",
                            ia->iface->name);
                        return;
                }
                clock_gettime(CLOCK_MONOTONIC, &tv);
                if ((ia1 = ipv6_createtempaddr(ia, &tv)) == NULL)
-                       syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+                       logerr(__func__);
                else
                        ia1->dadcounter = ia->dadcounter;
                ipv6_deleteaddr(ia);
@@ -2047,13 +2041,13 @@ ipv6_regentempaddr(void *arg)
        struct ipv6_addr *ia = arg, *ia1;
        struct timespec tv;
 
-       syslog(LOG_DEBUG, "%s: regen temp addr %s", ia->iface->name, ia->saddr);
+       logdebug("%s: regen temp addr %s", ia->iface->name, ia->saddr);
        clock_gettime(CLOCK_MONOTONIC, &tv);
        ia1 = ipv6_createtempaddr(ia, &tv);
        if (ia1)
                ipv6_addaddr(ia1, &tv);
        else
-               syslog(LOG_ERR, "ipv6_createtempaddr: %m");
+               logerr(__func__);
 }
 
 static void
@@ -2120,8 +2114,8 @@ inet6_makeprefix(struct interface *ifp, const struct ra *rap,
                                break;
                }
                if (lo0 == NULL)
-                       syslog(LOG_WARNING,
-                           "cannot find a loopback interface to reject via");
+                       logwarnx("cannot find a loopback interface "
+                           "to reject via");
                else
                        ifp = lo0;
        }
index d80183dcb50e7a46602ba087fb21fb0ab5cdca90..1fac6446d57339785f0dbdf182d44d9cdf7cab92 100644 (file)
@@ -39,7 +39,6 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #define ELOOP_QUEUE 3
@@ -50,6 +49,7 @@
 #include "if.h"
 #include "ipv6.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "route.h"
 #include "script.h"
 
@@ -268,8 +268,7 @@ ipv6nd_sendrsprobe(void *arg)
        struct in6_pktinfo pi;
 
        if (ipv6_linklocal(ifp) == NULL) {
-               syslog(LOG_DEBUG,
-                   "%s: delaying Router Solicitation for LL address",
+               logdebug("%s: delaying Router Solicitation for LL address",
                    ifp->name);
                ipv6_addlinklocalcallback(ifp, ipv6nd_sendrsprobe, ifp);
                return;
@@ -282,7 +281,7 @@ ipv6nd_sendrsprobe(void *arg)
 #endif
        dst.sin6_scope_id = ifp->index;
        if (inet_pton(AF_INET6, ALLROUTERS, &dst.sin6_addr) != 1) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return;
        }
 
@@ -303,10 +302,9 @@ ipv6nd_sendrsprobe(void *arg)
        pi.ipi6_ifindex = ifp->index;
        memcpy(CMSG_DATA(cm), &pi, sizeof(pi));
 
-       syslog(LOG_DEBUG,
-           "%s: sending Router Solicitation", ifp->name);
+       logdebug("%s: sending Router Solicitation", ifp->name);
        if (sendmsg(ctx->nd_fd, &ctx->sndhdr, 0) == -1) {
-               syslog(LOG_ERR, "%s: %s: sendmsg: %m", ifp->name, __func__);
+               logerr(__func__);
                /* Allow IPv6ND to continue .... at most a few errors
                 * would be logged.
                 * Generally the error is ENOBUFS when struggling to
@@ -317,7 +315,7 @@ ipv6nd_sendrsprobe(void *arg)
                eloop_timeout_add_sec(ifp->ctx->eloop,
                    RTR_SOLICITATION_INTERVAL, ipv6nd_sendrsprobe, ifp);
        else {
-               syslog(LOG_WARNING, "%s: no IPv6 Routers available", ifp->name);
+               logwarnx("%s: no IPv6 Routers available", ifp->name);
                ipv6nd_drop(ifp);
                dhcp6_dropnondelegates(ifp);
        }
@@ -364,7 +362,7 @@ ipv6nd_reachable(struct ra *rap, int flags)
 
        if (flags & IPV6ND_REACHABLE) {
                if (rap->lifetime && rap->expired) {
-                       syslog(LOG_INFO, "%s: %s is reachable again",
+                       loginfo("%s: %s is reachable again",
                            rap->iface->name, rap->sfrom);
                        rap->expired = 0;
                        rt_build(rap->iface->ctx, AF_INET6);
@@ -373,8 +371,7 @@ ipv6nd_reachable(struct ra *rap, int flags)
                }
        } else {
                if (rap->lifetime && !rap->expired) {
-                       syslog(LOG_WARNING,
-                           "%s: %s is unreachable, expiring it",
+                       logwarnx("%s: %s is unreachable, expiring it",
                            rap->iface->name, rap->sfrom);
                        rap->expired = 1;
                        rt_build(rap->iface->ctx, AF_INET6);
@@ -513,7 +510,7 @@ rtpref(struct ra *rap)
        case ND_RA_FLAG_RTPREF_LOW:
                return (RTPREF_LOW);
        default:
-               syslog(LOG_ERR, "rtpref: impossible RA flag %x", rap->flags);
+               logerrx("rtpref: impossible RA flag %x", rap->flags);
                return (RTPREF_INVALID);
        }
        /* NOTREACHED */
@@ -554,8 +551,7 @@ ipv6nd_scriptrun(struct ra *rap)
                            IN6_IFF_TENTATIVE))
                                ap->flags |= IPV6_AF_DADCOMPLETED;
                        if ((ap->flags & IPV6_AF_DADCOMPLETED) == 0) {
-                               syslog(LOG_DEBUG,
-                                   "%s: waiting for Router Advertisement"
+                               logdebug("%s: waiting for Router Advertisement"
                                    " DAD to complete",
                                    rap->iface->name);
                                return 0;
@@ -578,7 +574,7 @@ ipv6nd_scriptrun(struct ra *rap)
 #if 0
        else if (options & DHCPCD_DAEMONISE &&
            !(options & DHCPCD_DAEMONISED) && new_data)
-               syslog(LOG_WARNING, "%s: did not fork due to an absent"
+               logwarnx("%s: did not fork due to an absent"
                    " RDNSS option in the RA",
                    ifp->name);
 }
@@ -630,8 +626,7 @@ ipv6nd_dadcallback(void *arg)
        ap->flags |= IPV6_AF_DADCOMPLETED;
        if (ap->flags & IPV6_AF_DUPLICATED) {
                ap->dadcounter++;
-               syslog(LOG_WARNING, "%s: DAD detected %s",
-                   ifp->name, ap->saddr);
+               logwarnx("%s: DAD detected %s", ifp->name, ap->saddr);
 
                /* Try and make another stable private address.
                 * Because ap->dadcounter is always increamented,
@@ -639,24 +634,22 @@ ipv6nd_dadcallback(void *arg)
                /* XXX Cache DAD counter per prefix/id/ssid? */
                if (ifp->options->options & DHCPCD_SLAACPRIVATE) {
                        if (ap->dadcounter >= IDGEN_RETRIES) {
-                               syslog(LOG_ERR, "%s: unable to obtain a"
+                               logerrx("%s: unable to obtain a"
                                    " stable private address",
                                    ifp->name);
                                goto try_script;
                        }
-                       syslog(LOG_INFO, "%s: deleting address %s",
+                       loginfo("%s: deleting address %s",
                            ifp->name, ap->saddr);
                        if (if_address6(RTM_DELADDR, ap) == -1 &&
                            errno != EADDRNOTAVAIL && errno != ENXIO)
-                               syslog(LOG_ERR, "if_address6: %m");
+                               logerr(__func__);
                        dadcounter = ap->dadcounter;
                        if (ipv6_makestableprivate(&ap->addr,
                            &ap->prefix, ap->prefix_len,
                            ifp, &dadcounter) == -1)
                        {
-                               syslog(LOG_ERR,
-                                   "%s: ipv6_makestableprivate: %m",
-                                   ifp->name);
+                               logerr("ipv6_makestableprivate");
                                return;
                        }
                        ap->dadcounter = dadcounter;
@@ -700,8 +693,8 @@ try_script:
                        }
 
                        if (wascompleted && found) {
-                               syslog(LOG_DEBUG,
-                                   "%s: Router Advertisement DAD completed",
+                               logdebug("%s: Router Advertisement DAD "
+                                   "completed",
                                    rap->iface->name);
                                if (ipv6nd_scriptrun(rap))
                                        return;
@@ -741,38 +734,39 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
        struct ipv6_addr *ap;
        struct dhcp_opt *dho;
        uint8_t new_rap, new_data;
+       __printflike(1, 2) void (*logfunc)(const char *, ...);
 #ifdef IPV6_MANAGETEMPADDR
        uint8_t new_ap;
 #endif
 
        if (ifp == NULL) {
 #ifdef DEBUG_RS
-               syslog(LOG_DEBUG, "RA for unexpected interface from %s",
+               logdebug("RA for unexpected interface from %s",
                    ctx->sfrom);
 #endif
                return;
        }
 
        if (len < sizeof(struct nd_router_advert)) {
-               syslog(LOG_ERR, "IPv6 RA packet too short from %s", ctx->sfrom);
+               logerr("IPv6 RA packet too short from %s", ctx->sfrom);
                return;
        }
 
        /* RFC 4861 7.1.2 */
        if (hoplimit != 255) {
-               syslog(LOG_ERR, "invalid hoplimit(%d) in RA from %s",
+               logerr("invalid hoplimit(%d) in RA from %s",
                    hoplimit, ctx->sfrom);
                return;
        }
 
        if (!IN6_IS_ADDR_LINKLOCAL(&ctx->from.sin6_addr)) {
-               syslog(LOG_ERR, "RA from non local address %s", ctx->sfrom);
+               logerr("RA from non local address %s", ctx->sfrom);
                return;
        }
 
        if (!(ifp->options->options & DHCPCD_IPV6RS)) {
 #ifdef DEBUG_RS
-               syslog(LOG_DEBUG, "%s: unexpected RA from %s",
+               logerr("%s: unexpected RA from %s",
                    ifp->name, ctx->sfrom);
 #endif
                return;
@@ -781,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
-               syslog(LOG_DEBUG, "%s: received RA from %s (no link-local)",
+               logdebug("%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)) {
-               syslog(LOG_DEBUG, "%s: ignoring RA from ourself %s",
+               logdebug("%s: ignoring RA from ourself %s",
                    ifp->name, ctx->sfrom);
                return;
        }
@@ -816,7 +810,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
        if (rap == NULL) {
                rap = calloc(1, sizeof(*rap));
                if (rap == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return;
                }
                rap->iface = ifp;
@@ -829,7 +823,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
        if (rap->data_len == 0) {
                rap->data = malloc(len);
                if (rap->data == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        if (new_rap)
                                free(rap);
                        return;
@@ -842,8 +836,8 @@ 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. */
-       syslog(new_rap ? LOG_INFO : LOG_DEBUG,
-           "%s: Router Advertisement from %s",
+       logfunc = new_rap ? loginfo : logdebug,
+       logfunc("%s: Router Advertisement from %s",
            ifp->name, ctx->sfrom);
 
        clock_gettime(CLOCK_MONOTONIC, &rap->acquired);
@@ -869,17 +863,17 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
        p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
        for (; len > 0; p += olen, len -= olen) {
                if (len < sizeof(ndo)) {
-                       syslog(LOG_ERR, "%s: short option", ifp->name);
+                       logerrx("%s: short option", ifp->name);
                        break;
                }
                memcpy(&ndo, p, sizeof(ndo));
                olen = (size_t)ndo.nd_opt_len * 8;
                if (olen == 0) {
-                       syslog(LOG_ERR, "%s: zero length option", ifp->name);
+                       logerrx("%s: zero length option", ifp->name);
                        break;
                }
                if (olen > len) {
-                       syslog(LOG_ERR, "%s: option length exceeds message",
+                       logerrx("%s: option length exceeds message",
                            ifp->name);
                        break;
                }
@@ -895,12 +889,10 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                                        break;
                        }
                        if (dho != NULL)
-                               syslog(LOG_WARNING,
-                                   "%s: reject RA (option %s) from %s",
+                               logwarnx("%s: reject RA (option %s) from %s",
                                    ifp->name, dho->var, ctx->sfrom);
                        else
-                               syslog(LOG_WARNING,
-                                   "%s: reject RA (option %d) from %s",
+                               logwarnx("%s: reject RA (option %d) from %s",
                                    ifp->name, ndo.nd_opt_type, ctx->sfrom);
                        if (new_rap)
                                ipv6nd_removefreedrop_ra(rap, 0, 0);
@@ -914,17 +906,15 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
 
                switch (ndo.nd_opt_type) {
                case ND_OPT_PREFIX_INFORMATION:
+                       logfunc = new_data ? logerrx : logdebug;
                        if (ndo.nd_opt_len != 4) {
-                               syslog(new_data ? LOG_ERR : LOG_DEBUG,
-                                   "%s: invalid option len for prefix",
+                               logfunc("%s: invalid option len for prefix",
                                    ifp->name);
                                continue;
                        }
                        memcpy(&pi, p, sizeof(pi));
                        if (pi.nd_opt_pi_prefix_len > 128) {
-                               syslog(new_data ? LOG_ERR : LOG_DEBUG,
-                                   "%s: invalid prefix len",
-                                   ifp->name);
+                               logfunc("%s: invalid prefix len", ifp->name);
                                continue;
                        }
                        /* nd_opt_pi_prefix is not aligned. */
@@ -933,15 +923,13 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                        if (IN6_IS_ADDR_MULTICAST(&pi_prefix) ||
                            IN6_IS_ADDR_LINKLOCAL(&pi_prefix))
                        {
-                               syslog(new_data ? LOG_ERR : LOG_DEBUG,
-                                   "%s: invalid prefix in RA", ifp->name);
+                               logfunc("%s: invalid prefix in RA", ifp->name);
                                continue;
                        }
                        if (ntohl(pi.nd_opt_pi_preferred_time) >
                            ntohl(pi.nd_opt_pi_valid_time))
                        {
-                               syslog(new_data ? LOG_ERR : LOG_DEBUG,
-                                   "%s: pltime > vltime", ifp->name);
+                               logfunc("%s: pltime > vltime", ifp->name);
                                continue;
                        }
                        TAILQ_FOREACH(ap, &rap->addrs, next)
@@ -955,8 +943,10 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                                    ND_OPT_PI_FLAG_ONLINK))
                                        continue;
                                ap = calloc(1, sizeof(*ap));
-                               if (ap == NULL)
+                               if (ap == NULL) {
+                                       logerr(__func__);
                                        break;
+                               }
                                ap->iface = rap->iface;
                                ap->flags = IPV6_AF_NEW;
                                ap->prefix_len = pi.nd_opt_pi_prefix_len;
@@ -1034,8 +1024,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                                if (new_ap && ap->prefix_pltime) {
                                        if (ipv6_createtempaddr(ap,
                                            &ap->acquired) == NULL)
-                                               syslog(LOG_ERR,
-                                                   "ipv6_createtempaddr: %m");
+                                               logerr("ipv6_createtempaddr");
                                }
                        }
 #endif
@@ -1045,7 +1034,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                        memcpy(&mtu, p, sizeof(mtu));
                        mtu.nd_opt_mtu_mtu = ntohl(mtu.nd_opt_mtu_mtu);
                        if (mtu.nd_opt_mtu_mtu < IPV6_MMTU) {
-                               syslog(LOG_ERR, "%s: invalid MTU %d",
+                               logerrx("%s: invalid MTU %d",
                                    ifp->name, mtu.nd_opt_mtu_mtu);
                                break;
                        }
@@ -1070,8 +1059,7 @@ ipv6nd_handlera(struct dhcpcd_ctx *ctx, struct interface *ifp,
                if (has_option_mask(ifp->options->requiremasknd,
                    dho->option))
                {
-                       syslog(LOG_WARNING,
-                           "%s: reject RA (no option %s) from %s",
+                       logwarnx("%s: reject RA (no option %s) from %s",
                            ifp->name, dho->var, ctx->sfrom);
                        if (new_rap)
                                ipv6nd_removefreedrop_ra(rap, 0, 0);
@@ -1110,20 +1098,19 @@ handle_flag:
                goto nodhcp6;
 /* Only log a DHCPv6 start error if compiled in or debugging is enabled. */
 #ifdef DHCP6
-#define LOG_DHCP6      LOG_ERR
+#define LOG_DHCP6      logerr
 #else
-#define LOG_DHCP6      LOG_DEBUG
+#define LOG_DHCP6      logdebug
 #endif
        if (rap->flags & ND_RA_FLAG_MANAGED) {
                if (new_data && dhcp6_start(ifp, DH6S_INIT) == -1)
-                       syslog(LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name);
+                       LOG_DHCP6("dhcp6_start: %s", ifp->name);
        } else if (rap->flags & ND_RA_FLAG_OTHER) {
                if (new_data && dhcp6_start(ifp, DH6S_INFORM) == -1)
-                       syslog(LOG_DHCP6, "dhcp6_start: %s: %m", ifp->name);
+                       LOG_DHCP6("dhcp6_start: %s", ifp->name);
        } else {
                if (new_data)
-                       syslog(LOG_DEBUG, "%s: No DHCPv6 instruction in RA",
-                           ifp->name);
+                       logdebug("%s: No DHCPv6 instruction in RA", ifp->name);
 nodhcp6:
                if (ifp->ctx->options & DHCPCD_TEST) {
                        eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
@@ -1354,8 +1341,7 @@ ipv6nd_expirera(void *arg)
                        if (rap->lifetime == 0 || timespeccmp(&now, &expire, >))
                        {
                                if (!rap->expired) {
-                                       syslog(LOG_WARNING,
-                                           "%s: %s: router expired",
+                                       logwarnx("%s: %s: router expired",
                                            ifp->name, rap->sfrom);
                                        rap->expired = expired = 1;
                                        rap->lifetime = 0;
@@ -1381,14 +1367,12 @@ ipv6nd_expirera(void *arg)
                        timespecadd(&ia->acquired, &lt, &expire);
                        if (timespeccmp(&now, &expire, >)) {
                                if (ia->flags & IPV6_AF_ADDED) {
-                                       syslog(LOG_WARNING,
-                                           "%s: expired address %s",
+                                       logwarnx("%s: expired address %s",
                                            ia->iface->name, ia->saddr);
                                        if (if_address6(RTM_DELADDR, ia)== -1 &&
                                            errno != EADDRNOTAVAIL &&
                                            errno != ENXIO)
-                                               syslog(LOG_ERR,
-                                                   "if_address6: %m");
+                                               logerr(__func__);
                                }
                                ia->prefix_vltime = ia->prefix_pltime = 0;
                                ia->flags &=
@@ -1471,21 +1455,21 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp,
 
        if (ifp == NULL) {
 #ifdef DEBUG_NS
-               syslog(LOG_DEBUG, "NA for unexpected interface from %s",
+               logdebug("NA for unexpected interface from %s",
                    ctx->sfrom);
 #endif
                return;
        }
 
        if ((size_t)len < sizeof(struct nd_neighbor_advert)) {
-               syslog(LOG_ERR, "%s: IPv6 NA too short from %s",
+               logerrx("%s: IPv6 NA too short from %s",
                    ifp->name, ctx->sfrom);
                return;
        }
 
        /* RFC 4861 7.1.2 */
        if (hoplimit != 255) {
-               syslog(LOG_ERR, "invalid hoplimit(%d) in NA from %s",
+               logerrx("invalid hoplimit(%d) in NA from %s",
                    hoplimit, ctx->sfrom);
                return;
        }
@@ -1499,7 +1483,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp,
        /* nd_na->nd_na_target is not aligned. */
        memcpy(&nd_na_target, &nd_na->nd_na_target, sizeof(nd_na_target));
        if (IN6_IS_ADDR_MULTICAST(&nd_na_target)) {
-               syslog(LOG_ERR, "%s: NA multicast address %s (%s)",
+               logerrx("%s: NA multicast address %s (%s)",
                    ifp->name, taddr, ctx->sfrom);
                return;
        }
@@ -1511,20 +1495,20 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp,
        }
        if (rap == NULL) {
 #ifdef DEBUG_NS
-               syslog(LOG_DEBUG, "%s: unexpected NA from %s for %s",
+               logdebug("%s: unexpected NA from %s for %s",
                    ifp->name, ctx->sfrom, taddr);
 #endif
                return;
        }
 
 #ifdef DEBUG_NS
-       syslog(LOG_DEBUG, "%s: %sNA for %s from %s",
+       logdebug("%s: %sNA for %s from %s",
            ifp->name, is_solicited ? "solicited " : "", taddr, ctx->sfrom);
 #endif
 
        /* Node is no longer a router, so remove it from consideration */
        if (!is_router && !rap->expired) {
-               syslog(LOG_INFO, "%s: %s not a router (%s)",
+               loginfo("%s: %s not a router (%s)",
                    ifp->name, taddr, ctx->sfrom);
                rap->expired = 1;
                rt_build(ifp->ctx,  AF_INET6);
@@ -1535,7 +1519,7 @@ ipv6nd_handlena(struct dhcpcd_ctx *ctx, struct interface *ifp,
        if (is_solicited && is_router && rap->lifetime) {
                if (rap->expired) {
                        rap->expired = 0;
-                       syslog(LOG_INFO, "%s: %s reachable (%s)",
+                       loginfo("%s: %s reachable (%s)",
                            ifp->name, taddr, ctx->sfrom);
                        rt_build(ifp->ctx, AF_INET6);
                        script_runreason(rap->iface, "ROUTERADVERT"); /* XXX */
@@ -1559,7 +1543,7 @@ ipv6nd_handledata(void *arg)
            CMSG_SPACE(sizeof(int));
        len = recvmsg_realloc(ctx->nd_fd, &ctx->rcvhdr, 0);
        if (len == -1) {
-               syslog(LOG_ERR, "recvmsg: %m");
+               logerr(__func__);
                eloop_event_delete(ctx->eloop, ctx->nd_fd);
                close(ctx->nd_fd);
                ctx->nd_fd = -1;
@@ -1568,8 +1552,7 @@ ipv6nd_handledata(void *arg)
        ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
            ctx->ntopbuf, INET6_ADDRSTRLEN);
        if ((size_t)len < sizeof(struct icmp6_hdr)) {
-               syslog(LOG_ERR, "IPv6 ICMP packet too short from %s",
-                   ctx->sfrom);
+               logerrx("IPv6 ICMP packet too short from %s", ctx->sfrom);
                return;
        }
 
@@ -1594,8 +1577,7 @@ ipv6nd_handledata(void *arg)
        }
 
        if (pkt.ipi6_ifindex == 0) {
-               syslog(LOG_ERR, "IPv6 RA/NA did not contain index from %s",
-                   ctx->sfrom);
+               logerrx("IPv6 RA/NA did not contain index from %s", ctx->sfrom);
                return;
        }
 
@@ -1622,7 +1604,7 @@ ipv6nd_handledata(void *arg)
                }
        }
 
-       syslog(LOG_ERR, "invalid IPv6 type %d or code %d from %s",
+       logerrx("invalid IPv6 type %d or code %d from %s",
            icp->icmp6_type, icp->icmp6_code, ctx->sfrom);
 }
 
@@ -1632,9 +1614,9 @@ ipv6nd_startrs1(void *arg)
        struct interface *ifp = arg;
        struct rs_state *state;
 
-       syslog(LOG_INFO, "%s: soliciting an IPv6 router", ifp->name);
+       loginfo("%s: soliciting an IPv6 router", ifp->name);
        if (ipv6nd_open(ifp->ctx) == -1) {
-               syslog(LOG_ERR, "%s: ipv6nd_open: %m", __func__);
+               logerr(__func__);
                return;
        }
 
@@ -1643,7 +1625,7 @@ ipv6nd_startrs1(void *arg)
                ifp->if_data[IF_DATA_IPV6ND] = calloc(1, sizeof(*state));
                state = RS_STATE(ifp);
                if (state == NULL) {
-                       syslog(LOG_ERR, "%s: %m", __func__);
+                       logerr(__func__);
                        return;
                }
        }
@@ -1652,7 +1634,7 @@ ipv6nd_startrs1(void *arg)
         * address could have changed. */
        ipv6nd_makersprobe(ifp);
        if (state->rs == NULL) {
-               syslog(LOG_ERR, "%s: ipv6ns_makersprobe: %m", __func__);
+               logerr(__func__);
                return;
        }
 
@@ -1675,8 +1657,7 @@ ipv6nd_startrs(struct interface *ifp)
        tv.tv_nsec = (suseconds_t)arc4random_uniform(
            MAX_RTR_SOLICITATION_DELAY * NSEC_PER_SEC);
        timespecnorm(&tv);
-       syslog(LOG_DEBUG,
-           "%s: delaying IPv6 router solicitation for %0.1f seconds",
+       logdebug("%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
new file mode 100644 (file)
index 0000000..06f07a9
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * logerr: errx with logging
+ * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/time.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <syslog.h>
+
+#include "logerr.h"
+
+#ifndef        LOGERR_FACILITY
+#define        LOGERR_FACILITY LOG_DAEMON
+#endif
+#ifndef        LOGERR_OPTS
+#define        LOGERR_OPTS     LOG_PID
+#endif
+
+struct logctx {
+       unsigned int     log_opts;
+       FILE            *log_file;
+};
+
+static struct logctx _logctx = {
+       .log_opts = LOGERR_WLOG,
+       .log_file = NULL,
+};
+
+__printflike(2, 0) static void
+vlogprintf(FILE *stream, const char *fmt, va_list args)
+{
+       va_list a;
+
+       va_copy(a, args);
+       vfprintf(stream, fmt, a);
+       fputc('\n', stream);
+       va_end(a);
+}
+
+/*
+ * NetBSD's gcc has been modified to check for the non standard %m in printf
+ * like functions and warn noisily about it that they should be marked as
+ * syslog like instead.
+ * This is all well and good, but our logger also goes via vfprintf and
+ * when marked as a sysloglike funcion, gcc will then warn us that the
+ * function should be printflike instead!
+ * This creates an infinte loop of gcc warnings.
+ * Until NetBSD solves this issue, we have to disable a gcc diagnostic
+ * for our fully standards compliant code in the logger function.
+ */
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
+#endif
+__printflike(2, 0) static void
+vlogmessage(int pri, const char *fmt, va_list args)
+{
+
+       if (pri <= LOG_ERR ||
+           (!(_logctx.log_opts & LOGERR_QUIET) && pri <= LOG_INFO) ||
+           (_logctx.log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG))
+               vlogprintf(stderr, fmt, args);
+
+       if (!(_logctx.log_opts & LOGERR_WLOG))
+               return;
+
+       if (_logctx.log_file != NULL) {
+               struct timeval tv;
+
+               if (pri == LOG_DEBUG && !(_logctx.log_opts & LOGERR_DEBUG))
+                       return;
+
+               /* Write the time, syslog style. month day time - */
+               if (gettimeofday(&tv, NULL) != -1) {
+                       time_t now;
+                       struct tm tmnow;
+                       char buf[32];
+
+                       now = tv.tv_sec;
+                       tzset();
+                       localtime_r(&now, &tmnow);
+                       strftime(buf, sizeof(buf), "%b %d %T ", &tmnow);
+                       fprintf(_logctx.log_file, "%s", buf);
+               }
+
+               vlogprintf(_logctx.log_file, fmt, args);
+       } else
+               vsyslog(pri, fmt, args);
+}
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5))
+#pragma GCC diagnostic pop
+#endif
+
+__printflike(2, 3) static void
+logmessage(int pri, const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogmessage(pri, fmt, args);
+       va_end(args);
+}
+
+__printflike(2, 0) static void
+vlogerrmessage(int pri, const char *fmt, va_list args)
+{
+       int _errno = errno;
+       char buf[1024];
+
+       vsnprintf(buf, sizeof(buf), fmt, args);
+       logmessage(pri, "%s: %s", buf, strerror(_errno));
+}
+
+void
+logdebug(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogmessage(LOG_DEBUG, fmt, args);
+       va_end(args);
+}
+
+void
+loginfo(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogmessage(LOG_INFO, fmt, args);
+       va_end(args);
+}
+
+void
+logwarn(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogerrmessage(LOG_WARNING, fmt, args);
+       va_end(args);
+}
+
+void
+logwarnx(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogmessage(LOG_WARNING, fmt, args);
+       va_end(args);
+}
+
+void
+logerr(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogerrmessage(LOG_ERR, fmt, args);
+       va_end(args);
+}
+
+void
+logerrx(const char *fmt, ...)
+{
+       va_list args;
+
+       va_start(args, fmt);
+       vlogerrmessage(LOG_ERR, fmt, args);
+       va_end(args);
+}
+
+void
+logsetopts(unsigned int opts)
+{
+
+       _logctx.log_opts = opts;
+       setlogmask(LOG_UPTO(opts & LOGERR_DEBUG ? LOG_DEBUG : LOG_INFO));
+}
+
+int
+logopen(const char *path)
+{
+
+       if (path == NULL) {
+               openlog(NULL, LOGERR_OPTS, LOGERR_FACILITY);
+               return 1;
+       }
+
+       if ((_logctx.log_file = fopen(path, "w")) == NULL)
+               return -1;
+       setlinebuf(_logctx.log_file);
+       return fileno(_logctx.log_file);
+}
+
+void
+logclose()
+{
+
+       closelog();
+       if (_logctx.log_file == NULL)
+               return;
+       fclose(_logctx.log_file);
+       _logctx.log_file = NULL;
+}
diff --git a/src/logerr.h b/src/logerr.h
new file mode 100644 (file)
index 0000000..c195b56
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * logerr: errx with logging
+ * Copyright (c) 2006-2017 Roy Marples <roy@marples.name>
+ * All rights reserved
+
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef LOGERR_H
+#define LOERRG_H
+
+#include <sys/param.h>
+
+#ifndef __printflike
+#if __GNUC__ > 2 || defined(__INTEL_COMPILER)
+#define        __printflike(a, b) __attribute__((format(printf, a, b)))
+#else
+#define        __printflike
+#endif
+#endif /* !__printflike */
+
+__printflike(1, 2) typedef void logfunc_t(const char *, ...);
+
+__printflike(1, 2) void logdebug(const char *, ...);
+__printflike(1, 2) void loginfo(const char *, ...);
+__printflike(1, 2) void logwarn(const char *, ...);
+__printflike(1, 2) void logwarnx(const char *, ...);
+__printflike(1, 2) void logerr(const char *, ...);
+#define        LOGERROR        logerr("%s: %d", __FILE__, __LINE__)
+__printflike(1, 2) void logerrx(const char *, ...);
+
+void logsetopts(unsigned int);
+#define        LOGERR_WLOG     (1U << 1)
+#define        LOGERR_DEBUG    (1U << 2)
+#define        LOGERR_QUIET    (1U << 3)
+
+int logopen(const char *);
+void logclose(void);
+int logreopen(void);
+
+#endif
index 13ef0d6dab18a89a979adc3f13b2ca28cc76da84..e3e82cee9a82e4435d8ffe7dd18caee9cdba67f7 100644 (file)
@@ -31,7 +31,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
@@ -41,6 +40,7 @@
 #include "ipv4.h"
 #include "ipv4ll.h"
 #include "ipv6.h"
+#include "logerr.h"
 #include "route.h"
 #include "sa.h"
 
@@ -74,27 +74,27 @@ rt_desc(const char *cmd, const struct rt *rt)
 
        if (rt->rt_flags & RTF_HOST) {
                if (gateway_unspec)
-                       syslog(LOG_INFO, "%s: %s host route to %s",
+                       loginfo("%s: %s host route to %s",
                            ifname, cmd, dest);
                else
-                       syslog(LOG_INFO, "%s: %s host route to %s via %s",
+                       loginfo("%s: %s host route to %s via %s",
                            ifname, cmd, dest, gateway);
        } else if (sa_is_unspecified(&rt->rt_dest) &&
                   sa_is_unspecified(&rt->rt_netmask))
        {
                if (gateway_unspec)
-                       syslog(LOG_INFO, "%s: %s default route",
+                       loginfo("%s: %s default route",
                            ifname, cmd);
                else
-                       syslog(LOG_INFO, "%s: %s default route via %s",
+                       loginfo("%s: %s default route via %s",
                            ifname, cmd, gateway);
        } else if (gateway_unspec)
-               syslog(LOG_INFO, "%s: %s%s route to %s/%d",
+               loginfo("%s: %s%s route to %s/%d",
                    ifname, cmd,
                    rt->rt_flags & RTF_REJECT ? " reject" : "",
                    dest, prefix);
        else
-               syslog(LOG_INFO, "%s: %s%s route to %s/%d via %s",
+               loginfo("%s: %s%s route to %s/%d via %s",
                    ifname, cmd,
                    rt->rt_flags & RTF_REJECT ? " reject" : "",
                    dest, prefix, gateway);
@@ -156,7 +156,7 @@ rt_new(struct interface *ifp)
        if ((rt = TAILQ_FIRST(&ctx->froutes)) != NULL)
                TAILQ_REMOVE(&ctx->froutes, rt, rt_next);
        else if ((rt = malloc(sizeof(*rt))) == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return NULL;
        }
        memset(rt, 0, sizeof(*rt));
@@ -327,7 +327,7 @@ rt_add(struct rt *nrt, struct rt *ort)
                if (if_route(RTM_CHANGE, nrt) != -1)
                        return true;
                if (errno != ESRCH)
-                       syslog(LOG_ERR, "if_route (CHG): %m");
+                       logerr("if_route (CHG)");
        }
 
 #ifdef HAVE_ROUTE_METRIC
@@ -336,7 +336,7 @@ rt_add(struct rt *nrt, struct rt *ort)
        if (if_route(RTM_ADD, nrt) != -1) {
                if (ort != NULL) {
                        if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
-                               syslog(LOG_ERR, "if_route (DEL): %m");
+                               logerr("if_route (DEL)");
                        rt_kfree(ort);
                }
                return true;
@@ -355,7 +355,7 @@ rt_add(struct rt *nrt, struct rt *ort)
 #endif
        if (ort != NULL) {
                if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH)
-                       syslog(LOG_ERR, "if_route (DEL): %m");
+                       logerr("if_route (DEL)");
                else
                        rt_kfree(ort);
        }
@@ -375,7 +375,7 @@ rt_add(struct rt *nrt, struct rt *ort)
 #ifdef HAVE_ROUTE_METRIC
 logerr:
 #endif
-       syslog(LOG_ERR, "if_route (ADD): %m");
+       logerr("if_route (ADD)");
        return false;
 }
 
@@ -387,7 +387,7 @@ rt_delete(struct rt *rt)
        rt_desc("deleting", rt);
        retval = if_route(RTM_DELETE, rt) == -1 ? false : true;
        if (!retval && errno != ENOENT && errno != ESRCH)
-               syslog(LOG_ERR, "%s: if_delroute: %m", rt->rt_ifp->name);
+               logerr(__func__);
        /* Remove the route from our kernel table so we can add a
         * IPv4LL default route if possible. */
        else
index d5fd43e630d2557426f04cb23d3a4e826ecdfb58..ca93b5e2eaa1608f568d8a3230b7d8e4552d7394 100644 (file)
@@ -38,7 +38,6 @@
 #include <spawn.h>
 #include <stdlib.h>
 #include <string.h>
-#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
@@ -49,6 +48,7 @@
 #include "if-options.h"
 #include "ipv4ll.h"
 #include "ipv6nd.h"
+#include "logerr.h"
 #include "script.h"
 
 /* Allow the OS to define another script env var name */
@@ -127,7 +127,7 @@ make_var(const char *prefix, const char *var)
 
        len = strlen(prefix) + strlen(var) + 2;
        if ((v = malloc(len)) == NULL) {
-               syslog(LOG_ERR, "%s: %m", __func__);
+               logerr(__func__);
                return NULL;
        }
        snprintf(v, len, "%s_%s", prefix, var);
@@ -176,7 +176,7 @@ append_config(char ***env, size_t *len,
                        }
                        nep = realloc(ne, sizeof(char *) * (j + 1));
                        if (nep == NULL) {
-                               syslog(LOG_ERR, "%s: %m", __func__);
+                               logerr(__func__);
                                free(p);
                                ret = -1;
                                break;
@@ -573,7 +573,7 @@ dumplease:
        return (ssize_t)elen;
 
 eexit:
-       syslog(LOG_ERR, "%s: %m", __func__);
+       logerr(__func__);
        if (env) {
                nenv = env;
                while (*nenv)
@@ -685,7 +685,7 @@ script_runreason(const struct interface *ifp, const char *reason)
        /* Make our env */
        elen = (size_t)make_env(ifp, reason, &env);
        if (elen == (size_t)-1) {
-               syslog(LOG_ERR, "%s: make_env: %m", ifp->name);
+               logerr(__func__);
                return -1;
        }
 
@@ -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;
-       syslog(LOG_DEBUG, "%s: executing `%s' %s", ifp->name, argv[0], reason);
+       logdebug("%s: executing `%s' %s", ifp->name, argv[0], reason);
 
        /* Resize for PATH and RC_SVCNAME */
        svcname = getenv(RC_SVCNAME);
@@ -736,22 +736,22 @@ script_runreason(const struct interface *ifp, const char *reason)
 
        pid = exec_script(ifp->ctx, argv, env);
        if (pid == -1)
-               syslog(LOG_ERR, "%s: %s: %m", __func__, argv[0]);
+               logerr("%s: %s", __func__, argv[0]);
        else if (pid != 0) {
                /* Wait for the script to finish */
                while (waitpid(pid, &status, 0) == -1) {
                        if (errno != EINTR) {
-                               syslog(LOG_ERR, "waitpid: %m");
+                               logerr("%s: waitpid", __func__);
                                status = 0;
                                break;
                        }
                }
                if (WIFEXITED(status)) {
                        if (WEXITSTATUS(status))
-                               syslog(LOG_ERR, "%s: %s: WEXITSTATUS %d",
+                               logerrx("%s: %s: WEXITSTATUS %d",
                                    __func__, argv[0], WEXITSTATUS(status));
                } else if (WIFSIGNALED(status))
-                       syslog(LOG_ERR, "%s: %s: %s",
+                       logerrx("%s: %s: %s",
                            __func__, argv[0], strsignal(WTERMSIG(status)));
        }
 
@@ -766,13 +766,12 @@ send_listeners:
                        elen = (size_t)arraytostr((const char *const *)env,
                            &bigenv);
                        if ((ssize_t)elen == -1) {
-                               syslog(LOG_ERR, "%s: arraytostr: %m",
-                                   ifp->name);
+                               logerr("%s: arraytostr", ifp->name);
                                    break;
                        }
                }
                if (control_queue(fd, bigenv, elen, 1) == -1)
-                       syslog(LOG_ERR, "%s: control_queue: %m", __func__);
+                       logerr("%s: control_queue", __func__);
                else
                        status = 1;
        }
@@ -786,7 +785,7 @@ out:
                free(*ep++);
        free(env);
        if (elen == 0) {
-               syslog(LOG_ERR, "%s: malloc: %m", __func__);
+               logerr(__func__);
                return -1;
        }
        return WEXITSTATUS(status);