]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Remove logger and exclusively uses syslog instead. This saves almost 2K on NetBSD...
authorRoy Marples <roy@marples.name>
Fri, 5 Sep 2008 18:24:34 +0000 (18:24 +0000)
committerRoy Marples <roy@marples.name>
Fri, 5 Sep 2008 18:24:34 +0000 (18:24 +0000)
13 files changed:
Makefile
arp.c
bind.c
bpf.c
common.c
configure.c
dhcpcd.c
eloop.c
if-options.c
ipv4ll.c
logger.c [deleted file]
logger.h [deleted file]
net.c

index 691f6b923922082cee7689fb3647280659cce858..6db1cf79c86fe33f243683cc1737e866b2a8f93e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 
 PROG=          dhcpcd
 SRCS=          arp.c bind.c common.c control.c dhcp.c dhcpcd.c duid.c eloop.c
-SRCS+=         if-options.c ipv4ll.c logger.c net.c signals.c
+SRCS+=         if-options.c ipv4ll.c net.c signals.c
 SRCS+=         configure.c
 SRCS+=         ${SRC_IF} ${SRC_PF}
 
diff --git a/arp.c b/arp.c
index 849131e513292fae5451cc4d1e53e1f238616861..f21bac0d4989690065623bb12fa03b2fbe724fa0 100644 (file)
--- a/arp.c
+++ b/arp.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "arp.h"
@@ -37,7 +38,6 @@
 #include "eloop.h"
 #include "if-options.h"
 #include "ipv4ll.h"
-#include "logger.h"
 #include "net.h"
 
 #define ARP_LEN \
@@ -145,7 +145,7 @@ handle_arp_packet(void *arg)
                        state->fail.s_addr = iface->addr.s_addr;
 
                if (state->fail.s_addr) {
-                       logger(LOG_ERR, "%s: hardware address %s claims %s",
+                       syslog(LOG_ERR, "%s: hardware address %s claims %s",
                               iface->name,
                               hwaddr_ntoa((unsigned char *)hw_s,
                                           (size_t)ar.ar_hln),
@@ -169,17 +169,17 @@ send_arp_announce(void *arg)
                add_event(iface->arp_fd, handle_arp_packet, iface);
        }
        if (++state->claims < ANNOUNCE_NUM)     
-               logger(LOG_DEBUG,
+               syslog(LOG_DEBUG,
                       "%s: sending ARP announce (%d of %d), "
                       "next in %d.00 seconds",
                       iface->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
        else
-               logger(LOG_DEBUG,
+               syslog(LOG_DEBUG,
                       "%s: sending ARP announce (%d of %d)",
                       iface->name, state->claims, ANNOUNCE_NUM);
        if (send_arp(iface, ARPOP_REQUEST,
                     state->new->yiaddr, state->new->yiaddr) == -1)
-               logger(LOG_ERR, "send_arp: %m");
+               syslog(LOG_ERR, "send_arp: %m");
        if (state->claims < ANNOUNCE_NUM) {
                add_timeout_sec(ANNOUNCE_WAIT, send_arp_announce, iface);
                return;
@@ -216,9 +216,9 @@ send_arp_probe(void *arg)
        }
        if (state->probes == 0) {
                addr.s_addr = state->offer->yiaddr;
-               logger(LOG_INFO, "%s: checking %s is available"
-                               " on attached networks",
-                               iface->name, inet_ntoa(addr));
+               syslog(LOG_INFO, "%s: checking %s is available"
+                      " on attached networks",
+                      iface->name, inet_ntoa(addr));
        }
        if (++state->probes < PROBE_NUM) {
                tv.tv_sec = PROBE_MIN;
@@ -233,10 +233,9 @@ send_arp_probe(void *arg)
                else
                        add_timeout_tv(&tv, send_request, iface);
        }
-       logger(LOG_DEBUG,
-               "%s: sending ARP probe (%d of %d), next in %0.2f seconds",
-               iface->name, state->probes, PROBE_NUM,  timeval_to_double(&tv));
+       syslog(LOG_DEBUG,
+              "%s: sending ARP probe (%d of %d), next in %0.2f seconds",
+              iface->name, state->probes, PROBE_NUM,  timeval_to_double(&tv));
        if (send_arp(iface, ARPOP_REQUEST, 0, state->offer->yiaddr) == -1)
-               logger(LOG_ERR, "send_arp: %m");
+               syslog(LOG_ERR, "send_arp: %m");
 }
-
diff --git a/bind.c b/bind.c
index a5d225920178e154253445cc451a55b1da613d18..ab10e671539bf4a26ffb143e5d7a96e3cbe42731 100644 (file)
--- a/bind.c
+++ b/bind.c
@@ -27,6 +27,7 @@
 
 #include <signal.h>
 #include <stdlib.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "arp.h"
@@ -37,7 +38,6 @@
 #include "dhcpf.h"
 #include "eloop.h"
 #include "if-options.h"
-#include "logger.h"
 #include "net.h"
 #include "signals.h"
 
@@ -57,13 +57,13 @@ daemonise(void)
        sigprocmask(SIG_SETMASK, &full, &old);
        /* Setup a signal pipe so parent knows when to exit. */
        if (pipe(sidpipe) == -1) {
-               logger(LOG_ERR, "pipe: %m");
+               syslog(LOG_ERR, "pipe: %m");
                return -1;
        }
-       logger(LOG_INFO, "forking to background");
+       syslog(LOG_INFO, "forking to background");
        switch (pid = fork()) {
                case -1:
-                       logger(LOG_ERR, "fork: %m");
+                       syslog(LOG_ERR, "fork: %m");
                        exit(EXIT_FAILURE);
                        /* NOTREACHED */
                case 0:
@@ -116,7 +116,7 @@ bind_interface(void *arg)
        state->offer = NULL;
        get_lease(lease, state->new);
        if (IN_LINKLOCAL(htonl(state->new->yiaddr))) {
-               logger(LOG_INFO, "%s: using IPv4LL address %s",
+               syslog(LOG_INFO, "%s: using IPv4LL address %s",
                       iface->name, inet_ntoa(lease->addr));
                lease->leasetime = ~0U;
                reason = "IPV4LL";
@@ -125,7 +125,7 @@ bind_interface(void *arg)
                        lease->addr.s_addr = ifo->request_address.s_addr;
                else
                        lease->addr.s_addr = iface->addr.s_addr;
-               logger(LOG_INFO, "%s: received approval for %s", iface->name,
+               syslog(LOG_INFO, "%s: received approval for %s", iface->name,
                       inet_ntoa(lease->addr));
                lease->leasetime = ~0U;
                reason = "INFORM";
@@ -136,19 +136,19 @@ bind_interface(void *arg)
                        reason = "TIMEOUT";
                if (lease->leasetime == ~0U) {
                        lease->renewaltime = lease->rebindtime = lease->leasetime;
-                       logger(LOG_INFO, "%s: leased %s for infinity",
+                       syslog(LOG_INFO, "%s: leased %s for infinity",
                               iface->name, inet_ntoa(lease->addr));
                } else {
                        if (lease->rebindtime >= lease->leasetime) {
                                lease->rebindtime = lease->leasetime * T2;
-                               logger(LOG_ERR,
+                               syslog(LOG_ERR,
                                       "%s: rebind time greater than lease "
                                       "time, forcing to %u seconds",
                                       iface->name, lease->rebindtime);
                        }
                        if (lease->renewaltime > lease->rebindtime) {
                                lease->renewaltime = lease->leasetime * T1;
-                               logger(LOG_ERR,
+                               syslog(LOG_ERR,
                                       "%s: renewal time greater than rebind "
                                       "time, forcing to %u seconds",
                                       iface->name, lease->renewaltime);
@@ -157,7 +157,7 @@ bind_interface(void *arg)
                                lease->renewaltime = lease->leasetime * T1;
                        if (!lease->rebindtime)
                                lease->rebindtime = lease->leasetime * T2;
-                       logger(LOG_INFO,
+                       syslog(LOG_INFO,
                               "%s: leased %s for %u seconds", iface->name,
                               inet_ntoa(lease->addr), lease->leasetime);
                }
diff --git a/bpf.c b/bpf.c
index 96e53a16408932de515ba5d6faccdb7187d59901..948a72ca82f866825fe3c455a2d4af4cc83906f3 100644 (file)
--- a/bpf.c
+++ b/bpf.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
 #include "common.h"
 #include "dhcp.h"
-#include "logger.h"
 #include "net.h"
 #include "bpf-filter.h"
 
@@ -81,7 +81,7 @@ open_socket(struct interface *iface, int protocol)
                goto eexit;
        if (pv.bv_major != BPF_MAJOR_VERSION ||
            pv.bv_minor < BPF_MINOR_VERSION) {
-               logger(LOG_ERR, "BPF version mismatch - recompile " PACKAGE);
+               syslog(LOG_ERR, "BPF version mismatch - recompile");
                goto eexit;
        }
 
index 2daba9f40796502d0febde1f96f27869c3e6ec7e..47082cbbb7b61c66c51314fef61297c50d3fd63e 100644 (file)
--- a/common.c
+++ b/common.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <time.h>
 #include <unistd.h>
 
 #include "common.h"
-#include "logger.h"
 
 #ifndef _PATH_DEVNULL
 #  define _PATH_DEVNULL "/dev/null"
@@ -163,7 +163,7 @@ set_cloexec(int fd)
        if ((flags = fcntl(fd, F_GETFD, 0)) == -1
            || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
        {
-               logger(LOG_ERR, "fcntl: %m");
+               syslog(LOG_ERR, "fcntl: %m");
                return -1;
        }
        return 0;
@@ -177,7 +177,7 @@ set_nonblock(int fd)
        if ((flags = fcntl(fd, F_GETFL, 0)) == -1
            || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
        {
-               logger(LOG_ERR, "fcntl: %m");
+               syslog(LOG_ERR, "fcntl: %m");
                return -1;
        }
        return 0;
@@ -245,7 +245,7 @@ get_monotonic(struct timeval *tp)
 
        /* Something above failed, so fall back to gettimeofday */
        if (!posix_clock_set) {
-               logger(LOG_WARNING, NO_MONOTONIC);
+               syslog(LOG_WARNING, NO_MONOTONIC);
                posix_clock_set = 1;
        }
        return gettimeofday(tp, NULL);
@@ -283,7 +283,7 @@ xmalloc(size_t s)
 
        if (value)
                return value;
-       logger(LOG_ERR, "memory exhausted (xalloc %zu bytes)", s);
+       syslog(LOG_ERR, "memory exhausted (xalloc %zu bytes)", s);
        exit (EXIT_FAILURE);
        /* NOTREACHED */
 }
@@ -304,7 +304,7 @@ xrealloc(void *ptr, size_t s)
 
        if (value)
                return (value);
-       logger(LOG_ERR, "memory exhausted (xrealloc %zu bytes)", s);
+       syslog(LOG_ERR, "memory exhausted (xrealloc %zu bytes)", s);
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 }
@@ -320,7 +320,7 @@ xstrdup(const char *str)
        if ((value = strdup(str)))
                return value;
 
-       logger(LOG_ERR, "memory exhausted (xstrdup)");
+       syslog(LOG_ERR, "memory exhausted (xstrdup)");
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 }
index 27a7e501d17e0b38a44bca0ffd944f7352e36588..07502eff33175573f34ec283fffd94ceaee81c6b 100644 (file)
@@ -35,6 +35,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
@@ -42,7 +43,6 @@
 #include "configure.h"
 #include "dhcpf.h"
 #include "if-options.h"
-#include "logger.h"
 #include "net.h"
 #include "signals.h"
 
@@ -62,12 +62,12 @@ exec_script(char *const *argv, char *const *env)
 
        switch (pid = vfork()) {
        case -1:
-               logger(LOG_ERR, "vfork: %m");
+               syslog(LOG_ERR, "vfork: %m");
                break;
        case 0:
                sigprocmask(SIG_SETMASK, &old, NULL);
                execve(argv[0], argv, env);
-               logger(LOG_ERR, "%s: %m", argv[0]);
+               syslog(LOG_ERR, "%s: %m", argv[0]);
                _exit(127);
                /* NOTREACHED */
        }
@@ -89,7 +89,7 @@ run_script(const struct interface *iface, const char *reason)
        int status = 0;
        const struct if_options *ifo = iface->state->options;
 
-       logger(LOG_DEBUG, "%s: executing `%s', reason %s",
+       syslog(LOG_DEBUG, "%s: executing `%s', reason %s",
               iface->name, argv[0], reason);
 
        /* Make our env */
@@ -151,7 +151,7 @@ run_script(const struct interface *iface, const char *reason)
                /* Wait for the script to finish */
                while (waitpid(pid, &status, 0) == -1) {
                        if (errno != EINTR) {
-                               logger(LOG_ERR, "waitpid: %m");
+                               syslog(LOG_ERR, "waitpid: %m");
                                status = -1;
                                break;
                        }
@@ -173,12 +173,12 @@ delete_route(const struct interface *iface, struct rt *rt, int metric)
        int retval;
 
        addr = xstrdup(inet_ntoa(rt->dest));
-       logger(LOG_DEBUG, "%s: deleting route %s/%d via %s", iface->name,
+       syslog(LOG_DEBUG, "%s: deleting route %s/%d via %s", iface->name,
               addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate));
        free(addr);
        retval = del_route(iface, &rt->dest, &rt->net, &rt->gate, metric);
        if (retval != 0 && errno != ENOENT && errno != ESRCH)
-               logger(LOG_ERR," del_route: %m");
+               syslog(LOG_ERR," del_route: %m");
        return retval;
 }
 
@@ -266,7 +266,7 @@ configure_routes(struct interface *iface, const struct dhcp_message *dhcp)
                        continue;
 
                addr = xstrdup(inet_ntoa(rt->dest));
-               logger(LOG_DEBUG, "%s: adding route to %s/%d via %s",
+               syslog(LOG_DEBUG, "%s: adding route to %s/%d via %s",
                       iface->name, addr,
                       inet_ntocidr(rt->net), inet_ntoa(rt->gate));
                free(addr);
@@ -278,7 +278,7 @@ configure_routes(struct interface *iface, const struct dhcp_message *dhcp)
                   ourselves. If so, remember it again. */
                if (remember < 0) {
                        if (errno != EEXIST)
-                               logger(LOG_ERR, "add_route: %m");
+                               syslog(LOG_ERR, "add_route: %m");
                        if (in_routes(iface->routes, rt) == 0)
                                remember = 1;
                }
@@ -301,13 +301,13 @@ static int
 delete_address(struct interface *iface)
 {
        int retval;
-       logger(LOG_DEBUG, "%s: deleting IP address %s/%d",
+       syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
               iface->name,
               inet_ntoa(iface->addr),
               inet_ntocidr(iface->net));
        retval = del_address(iface, &iface->addr, &iface->net);
        if (retval == -1 && errno != EADDRNOTAVAIL) 
-               logger(LOG_ERR, "del_address: %m");
+               syslog(LOG_ERR, "del_address: %m");
        iface->addr.s_addr = 0;
        iface->net.s_addr = 0;
        return retval;
@@ -350,12 +350,12 @@ configure(struct interface *iface, const char *reason)
        /* This also changes netmask */
        if (!(iface->state->options->options & DHCPCD_INFORM) ||
            !has_address(iface->name, &addr, &net)) {
-               logger(LOG_DEBUG, "%s: adding IP address %s/%d",
+               syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
                       iface->name, inet_ntoa(addr), inet_ntocidr(net));
                if (add_address(iface, &addr, &net, &brd) == -1 &&
                    errno != EEXIST)
                {
-                       logger(LOG_ERR, "add_address: %m");
+                       syslog(LOG_ERR, "add_address: %m");
                        return -1;
                }
        }
@@ -395,7 +395,7 @@ configure(struct interface *iface, const char *reason)
 
        if (!iface->state->lease.frominfo)
                if (write_lease(iface, dhcp) == -1)
-                       logger(LOG_ERR, "write_lease: %m");
+                       syslog(LOG_ERR, "write_lease: %m");
 
        run_script(iface, reason);
        return 0;
index 1b3719e8910f65f935013b40906822b8616cc0cc..de01713a73df11d29e217b06f8ce7f7ab409781f 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -42,6 +42,7 @@ const char copyright[] = "Copyright (c) 2006-2008 Roy Marples";
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
 #include <time.h>
 
@@ -57,7 +58,6 @@ const char copyright[] = "Copyright (c) 2006-2008 Roy Marples";
 #include "eloop.h"
 #include "if-options.h"
 #include "ipv4ll.h"
-#include "logger.h"
 #include "net.h"
 #include "signals.h"
 
@@ -145,7 +145,7 @@ cleanup(void)
        if (pidfd > -1) {
                if (options & DHCPCD_MASTER) {
                        if (stop_control() == -1)
-                               logger(LOG_ERR, "stop_control: %m");
+                               syslog(LOG_ERR, "stop_control: %m");
                }
                close(pidfd);
                unlink(pidfile);
@@ -158,7 +158,7 @@ cleanup(void)
 _noreturn void
 handle_exit_timeout(_unused void *arg)
 {
-       logger(LOG_ERR, "timed out");
+       syslog(LOG_ERR, "timed out");
        exit(EXIT_FAILURE);
 }
 
@@ -199,7 +199,7 @@ stop_interface(struct interface *iface)
 {
        struct interface *ifp, *ifl = NULL;
 
-       logger(LOG_INFO, "%s: removing interface", iface->name);
+       syslog(LOG_INFO, "%s: removing interface", iface->name);
        drop_config(iface, "STOP");
        close_sockets(iface);
        delete_timeout(NULL, iface);
@@ -230,7 +230,7 @@ send_message(struct interface *iface, int type,
        struct timeval tv;
 
        if (!callback)
-               logger(LOG_DEBUG, "%s: sending %s with xid 0x%x",
+               syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
                       iface->name, get_dhcp_op(type), state->xid);
        else {
                if (state->interval == 0)
@@ -242,7 +242,7 @@ send_message(struct interface *iface, int type,
                }
                tv.tv_sec = state->interval + DHCP_RAND_MIN;
                tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U);
-               logger(LOG_DEBUG,
+               syslog(LOG_DEBUG,
                       "%s: sending %s with xid 0x%x, next in %0.2f seconds",
                       iface->name, get_dhcp_op(type), state->xid,
                       timeval_to_double(&tv));
@@ -265,13 +265,13 @@ send_message(struct interface *iface, int type,
        if (to.s_addr && to.s_addr != INADDR_BROADCAST) {
                r = send_packet(iface, to, (uint8_t *)dhcp, len);
                if (r == -1)
-                       logger(LOG_ERR, "%s: send_packet: %m", iface->name);
+                       syslog(LOG_ERR, "%s: send_packet: %m", iface->name);
        } else {
                len = make_udp_packet(&udp, (uint8_t *)dhcp, len, from, to);
                r = send_raw_packet(iface, ETHERTYPE_IP, udp, len);
                free(udp);
                if (r == -1)
-                       logger(LOG_ERR, "%s: send_raw_packet: %m", iface->name);
+                       syslog(LOG_ERR, "%s: send_raw_packet: %m", iface->name);
        }
        free(dhcp);
        if (r == -1) {
@@ -305,8 +305,8 @@ start_renew(void *arg)
 {
        struct interface *iface = arg;
 
-       logger(LOG_INFO, "%s: renewing lease of %s",
-                       iface->name, inet_ntoa(iface->state->lease.addr));
+       syslog(LOG_INFO, "%s: renewing lease of %s",
+              iface->name, inet_ntoa(iface->state->lease.addr));
        iface->state->state = DHS_RENEWING;
        iface->state->xid = arc4random();
        send_renew(iface);
@@ -323,8 +323,8 @@ start_rebind(void *arg)
 {
        struct interface *iface = arg;
 
-       logger(LOG_ERR, "%s: failed to renew, attmepting to rebind",
-                       iface->name);
+       syslog(LOG_ERR, "%s: failed to renew, attmepting to rebind",
+              iface->name);
        iface->state->state = DHS_REBINDING;
        delete_timeout(send_renew, iface);
        iface->state->lease.server.s_addr = 0;
@@ -337,7 +337,7 @@ start_expire(void *arg)
        struct interface *iface = arg;
        int ll = IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr));
 
-       logger(LOG_ERR, "%s: lease expired", iface->name);
+       syslog(LOG_ERR, "%s: lease expired", iface->name);
        delete_timeout(NULL, iface);
        drop_config(iface, "EXPIRE");
        iface->state->interval = 0;
@@ -371,13 +371,13 @@ log_dhcp(int lvl, const char *msg,
        }
        r = get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID);
        if (dhcp->servername[0] && r == 0)
-               logger(lvl, "%s: %s %s from %s `%s'", iface->name, msg, a,
+               syslog(lvl, "%s: %s %s from %s `%s'", iface->name, msg, a,
                       inet_ntoa(addr), dhcp->servername);
        else if (r == 0)
-               logger(lvl, "%s: %s %s from %s",
+               syslog(lvl, "%s: %s %s from %s",
                       iface->name, msg, a, inet_ntoa(addr));
        else
-               logger(lvl, "%s: %s %s", iface->name, msg, a);
+               syslog(lvl, "%s: %s %s", iface->name, msg, a);
        free(a);
 }
 
@@ -411,12 +411,12 @@ handle_dhcp(struct interface *iface, struct dhcp_message **dhcpp)
                        if (ifo->blacklist[i] != addr.s_addr)
                                continue;
                        if (dhcp->servername[0])
-                               logger(LOG_WARNING,
+                               syslog(LOG_WARNING,
                                       "%s: ignoring blacklisted server %s `%s'",
-                                       iface->name,
-                                       inet_ntoa(addr), dhcp->servername);
+                                      iface->name,
+                                      inet_ntoa(addr), dhcp->servername);
                        else
-                               logger(LOG_WARNING,
+                               syslog(LOG_WARNING,
                                       "%s: ignoring blacklisted server %s",
                                       iface->name, inet_ntoa(addr));
                        return;
@@ -534,7 +534,7 @@ handle_dhcp_packet(void *arg)
                        continue;
                bytes = get_udp_data(&pp, packet);
                if ((size_t)bytes > sizeof(*dhcp)) {
-                       logger(LOG_ERR, "%s: packet greater than DHCP size",
+                       syslog(LOG_ERR, "%s: packet greater than DHCP size",
                               iface->name);
                        continue;
                }
@@ -542,13 +542,13 @@ handle_dhcp_packet(void *arg)
                        dhcp = xmalloc(sizeof(*dhcp));
                memcpy(dhcp, pp, bytes);
                if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
-                       logger(LOG_DEBUG, "%s: bogus cookie, ignoring",
+                       syslog(LOG_DEBUG, "%s: bogus cookie, ignoring",
                               iface->name);
                        continue;
                }
                /* Ensure it's the right transaction */
                if (iface->state->xid != dhcp->xid) {
-                       logger(LOG_DEBUG,
+                       syslog(LOG_DEBUG,
                               "%s: ignoring packet with xid 0x%x as"
                               " it's not ours (0x%x)",
                               iface->name, dhcp->xid, iface->state->xid);
@@ -558,7 +558,7 @@ handle_dhcp_packet(void *arg)
                if (iface->hwlen <= sizeof(dhcp->chaddr) &&
                    memcmp(dhcp->chaddr, iface->hwaddr, iface->hwlen))
                {
-                       logger(LOG_DEBUG, "%s: xid 0x%x is not for our hwaddr %s",
+                       syslog(LOG_DEBUG, "%s: xid 0x%x is not for our hwaddr %s",
                               iface->name, dhcp->xid,
                               hwaddr_ntoa(dhcp->chaddr, sizeof(dhcp->chaddr)));
                        continue;
@@ -587,11 +587,11 @@ open_sockets(struct interface *iface)
                close(iface->udp_fd);
        if (open_udp_socket(iface) == -1 &&
            (errno != EADDRINUSE || iface->addr.s_addr != 0))
-               logger(LOG_ERR, "%s: open_udp_socket: %m", iface->name);
+               syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name);
        if (iface->raw_fd != -1)
                delete_event(iface->raw_fd);
        if (open_socket(iface, ETHERTYPE_IP) == -1)
-               logger(LOG_ERR, "%s: open_socket: %m", iface->name);
+               syslog(LOG_ERR, "%s: open_socket: %m", iface->name);
        if (iface->raw_fd != -1)
                add_event(iface->raw_fd, handle_dhcp_packet, iface);
 }
@@ -608,12 +608,12 @@ handle_carrier(const char *ifname)
                return;
        switch (carrier_status(iface->name)) {
        case -1:
-               logger(LOG_ERR, "carrier_status: %m");
+               syslog(LOG_ERR, "carrier_status: %m");
                break;
        case 0:
                if (iface->state->carrier != LINK_DOWN) {
                        iface->state->carrier = LINK_DOWN;
-                       logger(LOG_INFO, "%s: carrier lost", iface->name);
+                       syslog(LOG_INFO, "%s: carrier lost", iface->name);
                        close_sockets(iface);
                        delete_timeouts(iface, start_expire, NULL);
                }
@@ -621,7 +621,7 @@ handle_carrier(const char *ifname)
        default:
                if (iface->state->carrier != LINK_UP) {
                        iface->state->carrier = LINK_UP;
-                       logger(LOG_INFO, "%s: carrier acquired", iface->name);
+                       syslog(LOG_INFO, "%s: carrier acquired", iface->name);
                        start_interface(iface);
                }
                break;
@@ -646,7 +646,7 @@ start_discover(void *arg)
                else
                        add_timeout_sec(ifo->timeout, start_ipv4ll, iface);
        }
-       logger(LOG_INFO, "%s: broadcasting for a lease", iface->name);
+       syslog(LOG_INFO, "%s: broadcasting for a lease", iface->name);
        send_discover(iface);
 }
 
@@ -656,8 +656,8 @@ start_reboot(struct interface *iface)
 {
        struct if_options *ifo = iface->state->options;
 
-       logger(LOG_INFO, "%s: rebinding lease of %s",
-                       iface->name, inet_ntoa(iface->state->lease.addr));
+       syslog(LOG_INFO, "%s: rebinding lease of %s",
+              iface->name, inet_ntoa(iface->state->lease.addr));
        iface->state->state = DHS_REBINDING;
        iface->state->xid = arc4random();
        iface->state->lease.server.s_addr = 0;
@@ -673,8 +673,8 @@ send_release(struct interface *iface)
        if (iface->state->lease.addr.s_addr &&
            !IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr)))
        {
-               logger(LOG_INFO, "%s: releasing lease of %s",
-                               iface->name, inet_ntoa(iface->state->lease.addr));
+               syslog(LOG_INFO, "%s: releasing lease of %s",
+                      iface->name, inet_ntoa(iface->state->lease.addr));
                open_sockets(iface);
                send_message(iface, DHCP_RELEASE, NULL);
        }
@@ -717,7 +717,7 @@ configure_interface(struct interface *iface, int argc, char **argv)
                if (ifo->options & DHCPCD_DUID) {
                        duid = xmalloc(DUID_LEN);
                        if ((len = get_duid(duid, iface)) == 0)
-                               logger(LOG_ERR, "get_duid: %m");
+                               syslog(LOG_ERR, "get_duid: %m");
                }
                if (len > 0) {
                        iface->clientid = xmalloc(len + 6);
@@ -775,7 +775,7 @@ init_state(struct interface *iface, int argc, char **argv)
        }
 
        if (ifs->carrier == LINK_DOWN)
-               logger(LOG_INFO, "%s: waiting for carrier", iface->name);
+               syslog(LOG_INFO, "%s: waiting for carrier", iface->name);
        else
                start_interface(iface);
 }
@@ -834,7 +834,7 @@ handle_link(_unused void *arg)
                        handle_carrier,
                        handle_new_interface,
                        handle_remove_interface) == -1)
-               logger(LOG_ERR, "manage_link: %m");
+               syslog(LOG_ERR, "manage_link: %m");
 }
 
 static void
@@ -846,21 +846,21 @@ handle_signal(_unused void *arg)
 
        switch (sig) {
        case SIGINT:
-               logger(LOG_INFO, "received SIGINT, stopping");
+               syslog(LOG_INFO, "received SIGINT, stopping");
                break;
        case SIGTERM:
-               logger(LOG_INFO, "received SIGTERM, stopping");
+               syslog(LOG_INFO, "received SIGTERM, stopping");
                break;
        case SIGALRM:
-               logger(LOG_INFO, "received SIGALRM, rebinding lease");
+               syslog(LOG_INFO, "received SIGALRM, rebinding lease");
                do_reboot = 1;
                break;
        case SIGHUP:
-               logger(LOG_INFO, "received SIGHUP, releasing lease");
+               syslog(LOG_INFO, "received SIGHUP, releasing lease");
                do_release = 1;
                break;
        default:
-               logger (LOG_ERR,
+               syslog (LOG_ERR,
                        "received signal %d, but don't know what to do with it",
                        sig);
                return;
@@ -905,7 +905,7 @@ handle_args(int argc, char **argv)
 
        /* We only deal with one interface here */
        if (optind == argc) {
-               logger(LOG_ERR, "handle_args: no interface");
+               syslog(LOG_ERR, "handle_args: no interface");
                return -1;
        }
 
@@ -921,7 +921,7 @@ handle_args(int argc, char **argv)
                        if (do_release)
                                send_release(ifp);
                        if (do_exit || do_release) {
-                               logger(LOG_INFO, "%s: removing interface", ifp->name);
+                               syslog(LOG_INFO, "%s: removing interface", ifp->name);
                                drop_config(ifp, do_release ? "RELEASE" : "STOP");
                                close_sockets(ifp);
                                delete_timeout(NULL, ifp);
@@ -970,9 +970,8 @@ main(int argc, char **argv)
        struct timespec ts;
 
        closefrom(3);
-       /* Saves calling fflush(stream) in the logger */
-       setlinebuf(stdout);
-       openlog(PACKAGE, LOG_PID, LOG_LOCAL0);
+       openlog(PACKAGE, LOG_PERROR, LOG_LOCAL0);
+       setlogmask(LOG_UPTO(LOG_INFO));
        options = DHCPCD_DAEMONISE;
 
        /* Test for --help and --version */
@@ -993,7 +992,7 @@ main(int argc, char **argv)
                        options |= DHCPCD_BACKGROUND;
                        break;
                case 'd':
-                       setloglevel(LOG_DEBUG);
+                       setlogmask(LOG_UPTO(LOG_DEBUG));
                        break;
                case 'f':
                        cffile = optarg;
@@ -1005,7 +1004,7 @@ main(int argc, char **argv)
                        sig = SIGALRM;
                        break;
                case 'q':
-                       setloglevel(LOG_WARNING);
+                       setlogmask(LOG_UPTO(LOG_WARNING));
                        options |= DHCPCD_QUIET;
                        break;
                case 'x':
@@ -1056,40 +1055,40 @@ main(int argc, char **argv)
        if (!(options & DHCPCD_MASTER)) {
                control_fd = open_control();
                if (control_fd != -1) {
-                       logger(LOG_INFO, "sending commands to master dhcpcd process");
+                       syslog(LOG_INFO, "sending commands to master dhcpcd process");
                        i = send_control(argc, argv);
                        if (i > 0) {
-                               logger(LOG_DEBUG, "send OK");
+                               syslog(LOG_DEBUG, "send OK");
                                exit(EXIT_SUCCESS);
                        } else {
-                               logger(LOG_ERR, "failed to send commands");
+                               syslog(LOG_ERR, "failed to send commands");
                                exit(EXIT_FAILURE);
                        }
                } else {
                        if (errno != ENOENT)
-                               logger(LOG_ERR, "open_control: %m");
+                               syslog(LOG_ERR, "open_control: %m");
                }
        }
 
        if (geteuid())
-               logger(LOG_WARNING, PACKAGE " will not work correctly unless"
+               syslog(LOG_WARNING, PACKAGE " will not work correctly unless"
                       " run as root");
 
        if (sig != 0) {
                i = -1;
                pid = read_pid();
                if (pid != 0)
-                       logger(LOG_INFO, "sending signal %d to pid %d",
+                       syslog(LOG_INFO, "sending signal %d to pid %d",
                               sig, pid);
 
                if (!pid || (i = kill(pid, sig))) {
                        if (sig != SIGALRM)
-                               logger(LOG_ERR, ""PACKAGE" not running");
+                               syslog(LOG_ERR, ""PACKAGE" not running");
                        unlink(pidfile);
                        exit(EXIT_FAILURE);
                }
                /* Spin until it exits */
-               logger(LOG_INFO, "waiting for pid %d to exit", pid);
+               syslog(LOG_INFO, "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++) {
@@ -1097,7 +1096,7 @@ main(int argc, char **argv)
                        if (read_pid() == 0)
                                exit(EXIT_SUCCESS);
                }
-               logger(LOG_ERR, "pid %d failed to exit", pid);
+               syslog(LOG_ERR, "pid %d failed to exit", pid);
                exit(EXIT_FAILURE);
        }
 
@@ -1105,7 +1104,7 @@ main(int argc, char **argv)
                if ((pid = read_pid()) > 0 &&
                    kill(pid, 0) == 0)
                {
-                       logger(LOG_ERR, ""PACKAGE
+                       syslog(LOG_ERR, ""PACKAGE
                               " already running on pid %d (%s)",
                               pid, pidfile);
                        exit(EXIT_FAILURE);
@@ -1113,13 +1112,13 @@ main(int argc, char **argv)
 
                pidfd = open(pidfile, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
                if (pidfd == -1) {
-                       logger(LOG_ERR, "open `%s': %m", pidfile);
+                       syslog(LOG_ERR, "open `%s': %m", pidfile);
                        exit(EXIT_FAILURE);
                }
                /* Lock the file so that only one instance of dhcpcd runs
                 * on an interface */
                if (flock(pidfd, LOCK_EX | LOCK_NB) == -1) {
-                       logger(LOG_ERR, "flock `%s': %m", pidfile);
+                       syslog(LOG_ERR, "flock `%s': %m", pidfile);
                        exit(EXIT_FAILURE);
                }
                if (set_cloexec(pidfd) == -1)
@@ -1127,7 +1126,7 @@ main(int argc, char **argv)
                writepid(pidfd, getpid());
        }
 
-       logger(LOG_INFO, PACKAGE " " VERSION " starting");
+       syslog(LOG_INFO, "version " VERSION " starting");
 
        if ((signal_fd =signal_init()) == -1)
                exit(EXIT_FAILURE);
@@ -1137,7 +1136,7 @@ main(int argc, char **argv)
 
        if (options & DHCPCD_MASTER) {
                if (start_control() == -1) {
-                       logger(LOG_ERR, "start_control: %m");
+                       syslog(LOG_ERR, "start_control: %m");
                        exit(EXIT_FAILURE);
                }
        }
@@ -1145,7 +1144,7 @@ main(int argc, char **argv)
        if (ifo->options & DHCPCD_LINK) {
                linkfd = open_link_socket();
                if (linkfd == -1)
-                       logger(LOG_ERR, "open_link_socket: %m");
+                       syslog(LOG_ERR, "open_link_socket: %m");
                else
                        add_event(linkfd, handle_link, NULL);
        }
@@ -1164,7 +1163,7 @@ main(int argc, char **argv)
        for (iface = ifaces; iface; iface = iface->next)
                init_state(iface, argc, argv);
        if (!ifaces && ifc == 1) {
-               logger(LOG_ERR, "interface `%s' does not exist", ifv[0]);
+               syslog(LOG_ERR, "interface `%s' does not exist", ifv[0]);
                exit(EXIT_FAILURE);
        }
        if (options & DHCPCD_BACKGROUND)
diff --git a/eloop.c b/eloop.c
index 7655f5a78e391aec9b9431ce280412323633477d..227ed4c784a93c457419721a505113644b6f0b90 100644 (file)
--- a/eloop.c
+++ b/eloop.c
  */
 
 #include <sys/time.h>
+
 #include <errno.h>
 #include <limits.h>
 #include <poll.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <syslog.h>
 
 #include "common.h"
 #include "eloop.h"
-#include "logger.h"
-#include "net.h"
 
 static struct timeval now = {0, 0};
 
@@ -305,7 +305,7 @@ start_eloop(void)
                for (e = events; e; e = e->next)
                        nfds++;
                if (msecs == -1 && nfds == 0) {
-                       logger(LOG_ERR, "nothing to do");
+                       syslog(LOG_ERR, "nothing to do");
                        exit(EXIT_FAILURE);
                }
                if (nfds > fds_len) {
@@ -326,7 +326,7 @@ start_eloop(void)
                                get_monotonic(&now);
                                continue;
                        }
-                       logger(LOG_ERR, "poll: %m");
+                       syslog(LOG_ERR, "poll: %m");
                        exit(EXIT_FAILURE);
                }
 
index 848c86601e2c04bebf4c503cacc0664071683e07..1f8ff8f12bab10b84f70d5bbfb58698481b47f7e 100644 (file)
@@ -36,6 +36,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
 #include <time.h>
 
@@ -43,7 +44,6 @@
 #include "common.h"
 #include "dhcpf.h"
 #include "if-options.h"
-#include "logger.h"
 #include "net.h"
 
 /* Don't set any optional arguments here so we retain POSIX
@@ -99,7 +99,7 @@ atoint(const char *s)
        if ((errno != 0 && n == 0) || s == t ||
            (errno == ERANGE && (n == LONG_MAX || n == LONG_MIN)))
        {
-               logger(LOG_ERR, "`%s' out of range", s);
+               syslog(LOG_ERR, "`%s' out of range", s);
                return -1;
        }
 
@@ -276,11 +276,11 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                else
                        s = 0;
                if (s == -1) {
-                       logger(LOG_ERR, "hostname: %m");
+                       syslog(LOG_ERR, "hostname: %m");
                        return -1;
                }
                if (s != 0 && ifo->hostname[1] == '.') {
-                       logger(LOG_ERR, "hostname cannot begin with a .");
+                       syslog(LOG_ERR, "hostname cannot begin with a .");
                        return -1;
                }
                ifo->hostname[0] = (uint8_t)s;
@@ -292,34 +292,34 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                else
                        s = 0;
                if (s == -1) {
-                       logger(LOG_ERR, "vendorclassid: %m");
+                       syslog(LOG_ERR, "vendorclassid: %m");
                        return -1;
                }
                *ifo->vendorclassid = (uint8_t)s;
                break;
        case 'l':
                if (*arg == '-') {
-                       logger(LOG_ERR,
+                       syslog(LOG_ERR,
                               "leasetime must be a positive value");
                        return -1;
                }
                errno = 0;
                ifo->leasetime = (uint32_t)strtol(arg, NULL, 0);
                if (errno == EINVAL || errno == ERANGE) {
-                       logger(LOG_ERR, "`%s' out of range", arg);
+                       syslog(LOG_ERR, "`%s' out of range", arg);
                        return -1;
                }
                break;
        case 'm':
                ifo->metric = atoint(arg);
                if (ifo->metric < 0) {
-                       logger(LOG_ERR, "metric must be a positive value");
+                       syslog(LOG_ERR, "metric must be a positive value");
                        return -1;
                }
                break;
        case 'o':
                if (make_option_mask(ifo->requestmask, arg, 1) != 0) {
-                       logger(LOG_ERR, "unknown option `%s'", arg);
+                       syslog(LOG_ERR, "unknown option `%s'", arg);
                        return -1;
                }
                break;
@@ -341,7 +341,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                                if (sscanf(p, "%d", &i) != 1 ||
                                    inet_cidrtoaddr(i, &ifo->request_netmask) != 0)
                                {
-                                       logger(LOG_ERR,
+                                       syslog(LOG_ERR,
                                               "`%s' is not a valid CIDR",
                                               p);
                                        return -1;
@@ -353,7 +353,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                if (!(ifo->options & DHCPCD_INFORM))
                        ifo->options |= DHCPCD_REQUEST;
                if (arg && !inet_aton(arg, &ifo->request_address)) {
-                       logger(LOG_ERR, "`%s' is not a valid IP address",
+                       syslog(LOG_ERR, "`%s' is not a valid IP address",
                               arg);
                        return -1;
                }
@@ -361,7 +361,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
        case 't':
                ifo->timeout = atoint(arg);
                if (ifo->timeout < 0) {
-                       logger (LOG_ERR, "timeout must be a positive value");
+                       syslog (LOG_ERR, "timeout must be a positive value");
                        return -1;
                }
                break;
@@ -370,7 +370,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                s = parse_string((char *)ifo->userclass + ifo->userclass[0] + 2,
                                 s, arg);
                if (s == -1) {
-                       logger(LOG_ERR, "userclass: %m");
+                       syslog(LOG_ERR, "userclass: %m");
                        return -1;
                }
                if (s != 0) {
@@ -381,14 +381,14 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
        case 'v':
                p = strchr(arg, ',');
                if (!p || !p[1]) {
-                       logger(LOG_ERR, "invalid vendor format");
+                       syslog(LOG_ERR, "invalid vendor format");
                        return -1;
                }
                *p = '\0';
                i = atoint(arg);
                arg = p + 1;
                if (i < 1 || i > 254) {
-                       logger(LOG_ERR, "vendor option should be between"
+                       syslog(LOG_ERR, "vendor option should be between"
                                        " 1 and 254 inclusive");
                        return -1;
                }
@@ -405,7 +405,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                                         s, arg);
                }
                if (s == -1) {
-                       logger(LOG_ERR, "vendor: %m");
+                       syslog(LOG_ERR, "vendor: %m");
                        return -1;
                }
                if (s != 0) {
@@ -449,7 +449,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                else if (strcmp(arg, "disable") == 0)
                        ifo->fqdn = FQDN_DISABLE;
                else {
-                       logger(LOG_ERR, "invalid value `%s' for FQDN", arg);
+                       syslog(LOG_ERR, "invalid value `%s' for FQDN", arg);
                        return -1;
                }
                break;
@@ -465,7 +465,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                else
                        s = 0;
                if (s == -1) {
-                       logger(LOG_ERR, "clientid: %m");
+                       syslog(LOG_ERR, "clientid: %m");
                        return -1;
                }
                ifo->clientid[0] = (uint8_t)s;
@@ -485,7 +485,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                    make_option_mask(ifo->requiremask, arg, -1) != 0 ||
                    make_option_mask(ifo->nomask, arg, 1) != 0)
                {
-                       logger(LOG_ERR, "unknown option `%s'", arg);
+                       syslog(LOG_ERR, "unknown option `%s'", arg);
                        return -1;
                }
                break;
@@ -493,13 +493,13 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
                if (make_option_mask(ifo->requiremask, arg, 1) != 0 ||
                    make_option_mask(ifo->requestmask, arg, 1) != 0)
                {
-                       logger(LOG_ERR, "unknown option `%s'", arg);
+                       syslog(LOG_ERR, "unknown option `%s'", arg);
                        return -1;
                }
                break;
        case 'X':
                if (!inet_aton(arg, &addr)) {
-                       logger(LOG_ERR, "`%s' is not a valid IP address",
+                       syslog(LOG_ERR, "`%s' is not a valid IP address",
                               arg);
                        return -1;
                }
index c7b0586acd8b213cef4cd00727e925c0916d4349..0ae91005e51a7eed48808a4bc1fbb9a2cebd3986 100644 (file)
--- a/ipv4ll.c
+++ b/ipv4ll.c
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "arp.h"
@@ -36,7 +37,6 @@
 #include "eloop.h"
 #include "if-options.h"
 #include "ipv4ll.h"
-#include "logger.h"
 #include "net.h"
 
 static struct dhcp_message*
@@ -87,7 +87,7 @@ start_ipv4ll(void *arg)
                }
        }
 
-       logger(LOG_INFO, "%s: probing for an IPv4LL address", iface->name);
+       syslog(LOG_INFO, "%s: probing for an IPv4LL address", iface->name);
        delete_timeout(NULL, iface);
        iface->state->state = DHS_PROBING;
        free(iface->state->offer);
@@ -118,7 +118,7 @@ handle_ipv4ll_failure(void *arg)
 
        close_sockets(iface);
        if (++iface->state->conflicts > MAX_CONFLICTS) {
-               logger(LOG_ERR, "%s: failed to acquire an IPv4LL address",
+               syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
                                iface->name);
                iface->state->interval = RATE_LIMIT_INTERVAL / 2;
                start_discover(iface);
diff --git a/logger.c b/logger.c
deleted file mode 100644 (file)
index fbd71fb..0000000
--- a/logger.c
+++ /dev/null
@@ -1,117 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright 2006-2008 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 <ctype.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-
-#include "common.h"
-#include "dhcpcd.h"
-#include "if-options.h"
-#include "logger.h"
-
-/* For printf implementation that lack %m conversion in printf.
- * uClibc does support it, but it's not enabled by default. */
-#ifndef HAVE_PRINTF_M
-# ifdef __GLIBC__
-#  define HAVE_PRINTF_M 1
-# endif
-# ifndef HAVE_PRINTF_M
-#  define HAVE_PRINTF_M 0
-# endif
-#endif
-
-/* Mac length of format string when we don't have printf with %m */
-#define FMT_LEN 1024
-
-static int loglevel = LOG_INFO;
-
-void
-setloglevel(int level)
-{
-       loglevel = level;
-}
-
-void
-logger(int level, const char *fmt, ...)
-{
-       va_list va1, va2;
-       FILE *f = stderr;
-#if HAVE_PRINTF_M
-#else
-       char fm[FMT_LEN];
-       char *fp, *e = NULL, *ep;
-       const char *p;
-       size_t el = 0, fl = sizeof(fm);
-#endif
-
-       va_start(va1, fmt);
-       va_copy(va2, va1);
-       if (!(options & DHCPCD_DAEMONISED) &&
-           (level <= LOG_ERR || level <= loglevel))
-       {
-#if HAVE_PRINTF_M
-               vfprintf(f, fmt, va1);
-#else
-               for (p = fmt, fp = fm; *p; p++) {
-                       if (*p == '%' && p[1] == 'm') {
-                               if (!e) {
-                                       e = strerror(errno);
-                                       el = strlen(e);
-                               }
-                               ep = e;
-                               while (fl && *ep) {
-                                       *fp++ = *ep++;
-                                       fl--;
-                               }
-                               p++;
-                       } else if (*p == '%' && p[1] == '%' && fl > 2) {
-                               *fp++ = '%';
-                               *fp++ = '%';
-                               p++;
-                               fl -= 2;
-                       } else {
-                               if (fl > 1) {
-                                       *fp++ = *p;
-                                       fl--;
-                               }
-                       }
-               }
-               *fp = '\0';
-               vfprintf(f, fm, va1);
-#endif
-               fputc('\n', f);
-       }
-       if (level < LOG_DEBUG || level <= loglevel)
-               vsyslog(level, fmt, va2);
-       va_end(va2);
-       va_end(va1);
-}
diff --git a/logger.h b/logger.h
deleted file mode 100644 (file)
index 20d3588..0000000
--- a/logger.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* 
- * dhcpcd - DHCP client daemon
- * Copyright 2006-2008 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 LOGGER_H
-#define LOGGER_H
-
-/* We use %m in our logger strings to signal error message.
- * POSIX allows this in the syslog function.
- * We also use this GCC attribute to ensure parameters match the format.
- * However, printf POSIX does not define %m (only glibc does).
- * This state of affairs will give you a big warning about this if
- * you use the -pedantic GCC option. It is safe to ignore it. */
-#if defined(__GNUC__)
-#  define _printf_like(_one, _two) __attribute__((__format__(__printf__, _one, _two)))
-#else
-#  define _printf_like(_one, _two)
-#endif
-
-#include <syslog.h>
-
-void setloglevel(int);
-void logger(int, const char *, ...) _printf_like(2, 3);
-
-#endif
diff --git a/net.c b/net.c
index d67d64687207179e87102a919e3d98332a00da4a..55155d894178c3aaedf41f3eb5e8bf60551b93d0 100644 (file)
--- a/net.c
+++ b/net.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 #include <unistd.h>
 
 #include "config.h"
 #include "common.h"
 #include "dhcp.h"
-#include "logger.h"
 #include "if-options.h"
 #include "net.h"
 #include "signals.h"
@@ -238,7 +238,7 @@ init_interface(const char *ifname)
                if (!(options & DHCPCD_MASTER &&
                    !(options & DHCPCD_DAEMONISED) &&
                    options & DHCPCD_QUIET))
-                       logger(LOG_ERR, "%s: unsupported media family", iface->name);
+                       syslog(LOG_ERR, "%s: unsupported media family", iface->name);
                goto eexit;
        }
        memcpy(iface->hwaddr, ifr.ifr_hwaddr.sa_data, iface->hwlen);