-/* $OpenBSD: syslogd.c,v 1.197 2015/10/11 23:51:26 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.198 2015/10/15 20:26:47 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
if (path_ctlsock != NULL) {
fd_ctlsock = unix_socket(path_ctlsock, SOCK_STREAM, 0600);
if (fd_ctlsock == -1) {
- dprintf("can't open %s (%d)\n", path_ctlsock, errno);
+ logdebug("can't open %s (%d)\n", path_ctlsock, errno);
if (!Debug)
die(0);
} else {
fd_klog = open(_PATH_KLOG, O_RDONLY, 0);
if (fd_klog == -1) {
- dprintf("can't open %s (%d)\n", _PATH_KLOG, errno);
+ logdebug("can't open %s (%d)\n", _PATH_KLOG, errno);
} else {
if (ioctl(fd_klog, LIOCSFD, &pair[1]) == -1)
- dprintf("LIOCSFD errno %d\n", errno);
+ logdebug("LIOCSFD errno %d\n", errno);
}
close(pair[1]);
sb.st_size) == -1) {
logerrorx("tls_config_set_ca_mem");
} else {
- dprintf("CAfile %s, size %lld\n",
+ logdebug("CAfile %s, size %lld\n",
CAfile, sb.st_size);
}
free(p);
sb.st_size) == -1) {
logerrorx("tls_config_set_key_mem");
} else {
- dprintf("Keyfile %s, size %lld\n", path, sb.st_size);
+ logdebug("Keyfile %s, size %lld\n", path, sb.st_size);
}
free(p);
close(fd);
sb.st_size) == -1) {
logerrorx("tls_config_set_cert_mem");
} else {
- dprintf("Certfile %s, size %lld\n",
+ logdebug("Certfile %s, size %lld\n",
path, sb.st_size);
}
free(p);
}
}
- dprintf("off & running....\n");
+ logdebug("off & running....\n");
chdir("/");
evtimer_add(ev_mark, &to);
logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: start", LocalHostName, ADDDATE);
- dprintf("syslogd: started\n");
+ logdebug("syslogd: started\n");
event_dispatch();
/* NOTREACHED */
sizeof(hostname), servname, sizeof(servname),
NI_NUMERICHOST | NI_NUMERICSERV |
(res->ai_socktype == SOCK_DGRAM ? NI_DGRAM : 0)) != 0) {
- dprintf("Malformed bind address\n");
+ logdebug("Malformed bind address\n");
hostname[0] = servname[0] = '\0';
}
if (shutread && shutdown(*fdp, SHUT_RD) == -1) {
linebuf[n] = '\0';
cvthname((struct sockaddr *)&sa, resolve, sizeof(resolve));
- dprintf("cvthname res: %s\n", resolve);
+ logdebug("cvthname res: %s\n", resolve);
printline(resolve, linebuf);
} else if (n < 0 && errno != EINTR && errno != EWOULDBLOCK)
logerror("recvfrom udp");
int afd;
if (event & EV_TIMEOUT) {
- dprintf("Listen again\n");
+ logdebug("Listen again\n");
/* Enable the listen event, there is no timeout anymore. */
event_set(ev, lfd, EV_READ|EV_PERSIST, cb, ev);
event_add(ev, NULL);
logerror("accept tcp socket");
return;
}
- dprintf("Accepting tcp connection\n");
+ logdebug("Accepting tcp connection\n");
if (getnameinfo((struct sockaddr *)&ss, sslen, hostname,
sizeof(hostname), servname, sizeof(servname),
NI_NUMERICHOST | NI_NUMERICSERV) != 0 ||
asprintf(&peername, ss.ss_family == AF_INET6 ?
"[%s]:%s" : "%s:%s", hostname, servname) == -1) {
- dprintf("Malformed accept address\n");
+ logdebug("Malformed accept address\n");
peername = hostname_unknown;
}
- dprintf("Peer addresss and port %s\n", peername);
+ logdebug("Peer addresss and port %s\n", peername);
if ((p = malloc(sizeof(*p))) == NULL) {
snprintf(ebuf, sizeof(ebuf), "malloc \"%s\"", peername);
logerror(ebuf);
}
buffertls_set(&p->p_buftls, p->p_bufev, p->p_ctx, fd);
buffertls_accept(&p->p_buftls, fd);
- dprintf("tcp accept callback: tls context success\n");
+ logdebug("tcp accept callback: tls context success\n");
}
if (!NoDNS && peername != hostname_unknown &&
priv_getnameinfo((struct sockaddr *)&ss, ss.ss_len, hostname,
sizeof(hostname)) != 0) {
- dprintf("Host name for accept address (%s) unknown\n",
+ logdebug("Host name for accept address (%s) unknown\n",
hostname);
}
if (peername == hostname_unknown ||
(p->p_hostname = strdup(hostname)) == NULL)
p->p_hostname = hostname_unknown;
- dprintf("Peer hostname %s\n", hostname);
+ logdebug("Peer hostname %s\n", hostname);
p->p_peername = peername;
bufferevent_enable(p->p_bufev, EV_READ);
/* Using atoi() is safe as buf starts with 1 to 5 digits and a space. */
len = atoi(buf);
if (drain)
- dprintf(" octet counting %d", len);
+ logdebug(" octet counting %d", len);
if (p + len > end)
return (0);
if (drain)
}
if (p + 1 - buf >= INT_MAX)
return (-1);
- dprintf(" non transparent framing");
+ logdebug(" non transparent framing");
if (p >= end)
return (0);
/*
int len;
while (EVBUFFER_LENGTH(bufev->input) > 0) {
- dprintf("%s logger \"%s\"", p->p_ctx ? "tls" : "tcp",
+ logdebug("%s logger \"%s\"", p->p_ctx ? "tls" : "tcp",
p->p_peername);
msg = NULL;
len = octet_counting(bufev->input, &msg, 1);
if (len < 0)
len = non_transparent_framing(bufev->input, &msg);
if (len < 0)
- dprintf("unknown method");
+ logdebug("unknown method");
if (msg == NULL) {
- dprintf(", incomplete frame");
+ logdebug(", incomplete frame");
break;
}
- dprintf(", use %d bytes\n", len);
+ logdebug(", use %d bytes\n", len);
if (len > 0 && msg[len-1] == '\n')
msg[len-1] = '\0';
if (len == 0 || msg[len-1] != '\0') {
}
/* Maximum frame has 5 digits, 1 space, MAXLINE chars, 1 new line. */
if (EVBUFFER_LENGTH(bufev->input) >= 5 + 1 + MAXLINE + 1) {
- dprintf(", use %zu bytes\n", EVBUFFER_LENGTH(bufev->input));
+ logdebug(", use %zu bytes\n", EVBUFFER_LENGTH(bufev->input));
printline(p->p_hostname, EVBUFFER_DATA(bufev->input));
evbuffer_drain(bufev->input, -1);
} else if (EVBUFFER_LENGTH(bufev->input) > 0)
- dprintf(", buffer %zu bytes\n", EVBUFFER_LENGTH(bufev->input));
+ logdebug(", buffer %zu bytes\n", EVBUFFER_LENGTH(bufev->input));
}
void
/*
* Drop data received from the forward log server.
*/
- dprintf("loghost \"%s\" did send %zu bytes back\n",
+ logdebug("loghost \"%s\" did send %zu bytes back\n",
f->f_un.f_forw.f_loghost, EVBUFFER_LENGTH(bufev->input));
evbuffer_drain(bufev->input, -1);
}
/*
* Successful write, connection to server is good, reset wait time.
*/
- dprintf("loghost \"%s\" successful write\n", f->f_un.f_forw.f_loghost);
+ logdebug("loghost \"%s\" successful write\n", f->f_un.f_forw.f_loghost);
f->f_un.f_forw.f_reconnectwait = 0;
if (f->f_un.f_forw.f_dropped > 0 &&
"syslogd: loghost \"%s\" connection error: %s",
f->f_un.f_forw.f_loghost, f->f_un.f_forw.f_ctx ?
tls_error(f->f_un.f_forw.f_ctx) : strerror(errno));
- dprintf("%s\n", ebuf);
+ logdebug("%s\n", ebuf);
/* The SIGHUP handler may also close the socket, so invalidate it. */
if (f->f_un.f_forw.f_ctx) {
/* Without '\n' discard everything. */
if (p == end)
evbuffer_drain(bufev->output, -1);
- dprintf("loghost \"%s\" dropped partial message\n",
+ logdebug("loghost \"%s\" dropped partial message\n",
f->f_un.f_forw.f_loghost);
f->f_un.f_forw.f_dropped++;
}
tcp_connect_retry(bufev, f);
return;
}
- dprintf("tcp connect callback: socket success, event %#x\n", event);
+ logdebug("tcp connect callback: socket success, event %#x\n", event);
f->f_file = s;
bufferevent_setfd(bufev, s);
logerrorctx(ebuf, f->f_un.f_forw.f_ctx);
goto error;
}
- dprintf("tcp connect callback: tls context success\n");
+ logdebug("tcp connect callback: tls context success\n");
buffertls_set(&f->f_un.f_forw.f_buftls, bufev,
f->f_un.f_forw.f_ctx, s);
to.tv_sec = f->f_un.f_forw.f_reconnectwait;
to.tv_usec = 0;
- dprintf("tcp connect retry: wait %d\n", f->f_un.f_forw.f_reconnectwait);
+ logdebug("tcp connect retry: wait %d\n",
+ f->f_un.f_forw.f_reconnectwait);
bufferevent_setfd(bufev, -1);
/* We can reuse the write event as bufferevent is disabled. */
evtimer_set(&bufev->ev_write, tcp_connectcb, f);
char *timestamp;
char prog[NAME_MAX+1];
- dprintf("logmsg: pri 0%o, flags 0x%x, from %s, msg %s\n",
+ logdebug("logmsg: pri 0%o, flags 0x%x, from %s, msg %s\n",
pri, flags, from, msg);
/*
!strcmp(from, f->f_prevhost)) {
strlcpy(f->f_lasttime, timestamp, 16);
f->f_prevcount++;
- dprintf("msg repeated %d times, %ld sec of %d\n",
+ logdebug("msg repeated %d times, %ld sec of %d\n",
f->f_prevcount, (long)(now - f->f_time),
repeatinterval[f->f_repeatcount]);
/*
}
v++;
- dprintf("Logging to %s", TypeNames[f->f_type]);
+ logdebug("Logging to %s", TypeNames[f->f_type]);
f->f_time = now;
switch (f->f_type) {
case F_UNUSED:
- dprintf("\n");
+ logdebug("\n");
break;
case F_FORWUDP:
- dprintf(" %s\n", f->f_un.f_forw.f_loghost);
+ logdebug(" %s\n", f->f_un.f_forw.f_loghost);
l = snprintf(line, MINIMUM(MAX_UDPMSG + 1, sizeof(line)),
"<%d>%.15s %s%s%s", f->f_prevpri, (char *)iov[0].iov_base,
IncludeHostname ? LocalHostName : "",
case F_FORWTCP:
case F_FORWTLS:
- dprintf(" %s", f->f_un.f_forw.f_loghost);
+ logdebug(" %s", f->f_un.f_forw.f_loghost);
if (EVBUFFER_LENGTH(f->f_un.f_forw.f_bufev->output) >=
MAX_TCPBUF) {
- dprintf(" (dropped)\n");
+ logdebug(" (dropped)\n");
f->f_un.f_forw.f_dropped++;
break;
}
IncludeHostname ? LocalHostName : "",
IncludeHostname ? " " : "");
if (l < 0) {
- dprintf(" (dropped snprintf)\n");
+ logdebug(" (dropped snprintf)\n");
f->f_un.f_forw.f_dropped++;
break;
}
IncludeHostname ? " " : "",
(char *)iov[4].iov_base);
if (l < 0) {
- dprintf(" (dropped evbuffer_add_printf)\n");
+ logdebug(" (dropped evbuffer_add_printf)\n");
f->f_un.f_forw.f_dropped++;
break;
}
bufferevent_enable(f->f_un.f_forw.f_bufev, EV_WRITE);
- dprintf("\n");
+ logdebug("\n");
break;
case F_CONSOLE:
if (flags & IGN_CONS) {
- dprintf(" (ignored)\n");
+ logdebug(" (ignored)\n");
break;
}
/* FALLTHROUGH */
case F_TTY:
case F_FILE:
case F_PIPE:
- dprintf(" %s\n", f->f_un.f_fname);
+ logdebug(" %s\n", f->f_un.f_fname);
if (f->f_type != F_FILE && f->f_type != F_PIPE) {
v->iov_base = "\r\n";
v->iov_len = 2;
case F_USERS:
case F_WALL:
- dprintf("\n");
+ logdebug("\n");
v->iov_base = "\r\n";
v->iov_len = 2;
wallmsg(f, iov);
break;
case F_MEMBUF:
- dprintf("\n");
+ logdebug("\n");
snprintf(line, sizeof(line), "%.15s %s %s",
(char *)iov[0].iov_base, (char *)iov[2].iov_base,
(char *)iov[4].iov_base);
{
if (getnameinfo(f, f->sa_len, result, res_len, NULL, 0,
NI_NUMERICHOST|NI_NUMERICSERV|NI_DGRAM) != 0) {
- dprintf("Malformed from address\n");
+ logdebug("Malformed from address\n");
strlcpy(result, hostname_unknown, res_len);
return;
}
- dprintf("cvthname(%s)\n", result);
+ logdebug("cvthname(%s)\n", result);
if (NoDNS)
return;
if (priv_getnameinfo(f, f->sa_len, result, res_len) != 0)
- dprintf("Host name for from address (%s) unknown\n", result);
+ logdebug("Host name for from address (%s) unknown\n", result);
}
void
logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart",
LocalHostName, ADDDATE);
- dprintf("syslogd: restarted\n");
+ logdebug("syslogd: restarted\n");
if (tcpbuf_dropped > 0) {
snprintf(ebuf, sizeof(ebuf),
}
}
-/*
- * Print syslogd errors some place.
- */
+void
+logdebug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (Debug) {
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ }
+}
+
void
logerror(const char *message)
{
else
(void)snprintf(ebuf, sizeof(ebuf), "syslogd: %s", message);
errno = 0;
- dprintf("%s\n", ebuf);
+ logdebug("%s\n", ebuf);
if (Startup)
fprintf(stderr, "%s\n", ebuf);
else
}
if (signo) {
- dprintf("syslogd: exiting on signal %d\n", signo);
+ logdebug("syslogd: exiting on signal %d\n", signo);
(void)snprintf(ebuf, sizeof(ebuf), "exiting on signal %d",
signo);
logerrorx(ebuf);
}
- dprintf("[unpriv] syslogd child about to exit\n");
+ logdebug("[unpriv] syslogd child about to exit\n");
exit(0);
}
int i;
size_t s;
- dprintf("init\n");
+ logdebug("init\n");
/* If config file has been modified, then just die to restart */
if (priv_config_modified()) {
- dprintf("config file changed: dying\n");
+ logdebug("config file changed: dying\n");
die(0);
}
if (f->f_type == F_MEMBUF) {
f->f_program = NULL;
f->f_hostname = NULL;
- dprintf("add %p to mb\n", f);
+ logdebug("add %p to mb\n", f);
SIMPLEQ_INSERT_HEAD(&mb, f, f_next);
} else
free(f);
/* open the configuration file */
if ((cf = priv_open_config()) == NULL) {
- dprintf("cannot open %s\n", ConfFile);
+ logdebug("cannot open %s\n", ConfFile);
SIMPLEQ_INSERT_TAIL(&Files,
cfline("*.ERR\t/dev/console", "*", "*"), f_next);
SIMPLEQ_INSERT_TAIL(&Files,
SIMPLEQ_FOREACH(f, &Files, f_next) {
if (f->f_type != F_MEMBUF)
continue;
- dprintf("Initialize membuf %s at %p\n", f->f_un.f_mb.f_mname, f);
+ logdebug("Initialize membuf %s at %p\n",
+ f->f_un.f_mb.f_mname, f);
SIMPLEQ_FOREACH(m, &mb, f_next) {
if (m->f_un.f_mb.f_rb == NULL)
break;
}
if (m == NULL) {
- dprintf("Membuf no match\n");
+ logdebug("Membuf no match\n");
f->f_un.f_mb.f_rb = ringbuf_init(f->f_un.f_mb.f_len);
if (f->f_un.f_mb.f_rb == NULL) {
f->f_type = F_UNUSED;
logerror("Failed to allocate membuf");
}
} else {
- dprintf("Membuf match f:%p, m:%p\n", f, m);
+ logdebug("Membuf match f:%p, m:%p\n", f, m);
f->f_un = m->f_un;
m->f_un.f_mb.f_rb = NULL;
}
logerrorx("Mismatched membuf");
ringbuf_free(m->f_un.f_mb.f_rb);
}
- dprintf("Freeing membuf %p\n", m);
+ logdebug("Freeing membuf %p\n", m);
free(m);
}
if (strcmp(list->f_un.f_fname, f->f_un.f_fname) == 0 &&
progmatches(list->f_program, f->f_program) &&
progmatches(list->f_hostname, f->f_hostname)) {
- dprintf("duplicate %s\n", f->f_un.f_fname);
+ logdebug("duplicate %s\n", f->f_un.f_fname);
return (list);
}
break;
f->f_un.f_mb.f_mname) == 0 &&
progmatches(list->f_program, f->f_program) &&
progmatches(list->f_hostname, f->f_hostname)) {
- dprintf("duplicate membuf %s\n",
+ logdebug("duplicate membuf %s\n",
f->f_un.f_mb.f_mname);
return (list);
}
struct filed *xf, *f, *d;
struct timeval to;
- dprintf("cfline(\"%s\", f, \"%s\", \"%s\")\n",
+ logdebug("cfline(\"%s\", f, \"%s\", \"%s\")\n",
line, progblock, hostblock);
if ((f = calloc(1, sizeof(*f))) == NULL) {
mib[1] = KERN_MSGBUFSIZE;
size = sizeof msgbufsize;
if (sysctl(mib, 2, &msgbufsize, &size, NULL, 0) == -1) {
- dprintf("couldn't get kern.msgbufsize\n");
+ logdebug("couldn't get kern.msgbufsize\n");
return (0);
}
return (msgbufsize);
SIMPLEQ_FOREACH(f, &Files, f_next) {
if (f->f_prevcount && now >= REPEATTIME(f)) {
- dprintf("flush %s: repeated %d times, %d sec.\n",
+ logdebug("flush %s: repeated %d times, %d sec.\n",
TypeNames[f->f_type], f->f_prevcount,
repeatinterval[f->f_repeatcount]);
fprintlog(f, 0, (char *)NULL);
logerror("accept ctlsock");
return;
}
- dprintf("Accepting control connection\n");
+ logdebug("Accepting control connection\n");
if (fd_ctlconn != -1)
ctlconn_cleanup();
memset(reply_hdr, '\0', sizeof(*reply_hdr));
ctl_cmd.cmd = ntohl(ctl_cmd.cmd);
- dprintf("ctlcmd %x logname \"%s\"\n", ctl_cmd.cmd, ctl_cmd.logname);
+ logdebug("ctlcmd %x logname \"%s\"\n", ctl_cmd.cmd, ctl_cmd.logname);
switch (ctl_cmd.cmd) {
case CMD_READ:
reply_hdr->flags = htonl(flags);
ctl_reply_size = CTL_REPLY_SIZE;
- dprintf("ctlcmd reply length %lu\n", (u_long)ctl_reply_size);
+ logdebug("ctlcmd reply length %lu\n", (u_long)ctl_reply_size);
/* Otherwise, set up to write out reply */
ctl_state = (ctl_cmd.cmd == CMD_READ_CONT) ?