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}
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
+#include <syslog.h>
#include <unistd.h>
#include "arp.h"
#include "eloop.h"
#include "if-options.h"
#include "ipv4ll.h"
-#include "logger.h"
#include "net.h"
#define ARP_LEN \
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),
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;
}
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;
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");
}
-
#include <signal.h>
#include <stdlib.h>
+#include <syslog.h>
#include <unistd.h>
#include "arp.h"
#include "dhcpf.h"
#include "eloop.h"
#include "if-options.h"
-#include "logger.h"
#include "net.h"
#include "signals.h"
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:
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";
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";
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);
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);
}
#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"
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;
}
#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"
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;
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;
/* 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);
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 */
}
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 */
}
if ((value = strdup(str)))
return value;
- logger(LOG_ERR, "memory exhausted (xstrdup)");
+ syslog(LOG_ERR, "memory exhausted (xstrdup)");
exit(EXIT_FAILURE);
/* NOTREACHED */
}
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
+#include <syslog.h>
#include <unistd.h>
#include "config.h"
#include "configure.h"
#include "dhcpf.h"
#include "if-options.h"
-#include "logger.h"
#include "net.h"
#include "signals.h"
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 */
}
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 */
/* 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;
}
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;
}
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);
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;
}
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;
/* 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;
}
}
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;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <unistd.h>
#include <time.h>
#include "eloop.h"
#include "if-options.h"
#include "ipv4ll.h"
-#include "logger.h"
#include "net.h"
#include "signals.h"
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);
_noreturn void
handle_exit_timeout(_unused void *arg)
{
- logger(LOG_ERR, "timed out");
+ syslog(LOG_ERR, "timed out");
exit(EXIT_FAILURE);
}
{
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);
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)
}
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));
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) {
{
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);
{
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;
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;
}
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);
}
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;
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;
}
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);
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;
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);
}
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);
}
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;
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);
}
{
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;
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);
}
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);
}
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);
}
handle_carrier,
handle_new_interface,
handle_remove_interface) == -1)
- logger(LOG_ERR, "manage_link: %m");
+ syslog(LOG_ERR, "manage_link: %m");
}
static void
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;
/* 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;
}
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);
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 */
options |= DHCPCD_BACKGROUND;
break;
case 'd':
- setloglevel(LOG_DEBUG);
+ setlogmask(LOG_UPTO(LOG_DEBUG));
break;
case 'f':
cffile = optarg;
sig = SIGALRM;
break;
case 'q':
- setloglevel(LOG_WARNING);
+ setlogmask(LOG_UPTO(LOG_WARNING));
options |= DHCPCD_QUIET;
break;
case 'x':
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++) {
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);
}
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);
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)
writepid(pidfd, getpid());
}
- logger(LOG_INFO, PACKAGE " " VERSION " starting");
+ syslog(LOG_INFO, "version " VERSION " starting");
if ((signal_fd =signal_init()) == -1)
exit(EXIT_FAILURE);
if (options & DHCPCD_MASTER) {
if (start_control() == -1) {
- logger(LOG_ERR, "start_control: %m");
+ syslog(LOG_ERR, "start_control: %m");
exit(EXIT_FAILURE);
}
}
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);
}
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)
*/
#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};
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) {
get_monotonic(&now);
continue;
}
- logger(LOG_ERR, "poll: %m");
+ syslog(LOG_ERR, "poll: %m");
exit(EXIT_FAILURE);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <syslog.h>
#include <unistd.h>
#include <time.h>
#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
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;
}
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;
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;
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;
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;
}
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;
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) {
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;
}
s, arg);
}
if (s == -1) {
- logger(LOG_ERR, "vendor: %m");
+ syslog(LOG_ERR, "vendor: %m");
return -1;
}
if (s != 0) {
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;
else
s = 0;
if (s == -1) {
- logger(LOG_ERR, "clientid: %m");
+ syslog(LOG_ERR, "clientid: %m");
return -1;
}
ifo->clientid[0] = (uint8_t)s;
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;
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;
}
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
+#include <syslog.h>
#include <unistd.h>
#include "arp.h"
#include "eloop.h"
#include "if-options.h"
#include "ipv4ll.h"
-#include "logger.h"
#include "net.h"
static struct dhcp_message*
}
}
- 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);
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);
+++ /dev/null
-/*
- * 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);
-}
+++ /dev/null
-/*
- * 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
#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"
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);