-/* $OpenBSD: syslogd.c,v 1.237 2017/04/05 19:34:49 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.238 2017/04/05 21:30:04 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
/*
- * Flags to logmsg().
+ * Flags to logline().
*/
#define IGN_CONS 0x001 /* don't print on console */
void fprintlog(struct filed *, int, char *);
void init(void);
void logevent(int, const char *);
-void logmsg(int, char *, char *, int);
+void logline(int, int, char *, char *);
struct filed *find_dup(struct filed *);
size_t parsepriority(const char *, int *);
void printline(char *, char *);
to.tv_usec = 0;
evtimer_add(ev_mark, &to);
- logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: start", LocalHostName, ADDDATE);
+ log_info(LOG_INFO, "start");
log_debug("syslogd: started");
sigemptyset(&sigmask);
struct sockaddr *sa, socklen_t *salen, int flags)
{
struct timeval to = { 1, 0 };
- char ebuf[ERRBUFSIZE];
int afd;
if (event & EV_TIMEOUT) {
afd = accept4(lfd, sa, salen, flags);
if (afd == -1 && (errno == ENFILE || errno == EMFILE)) {
- snprintf(ebuf, sizeof(ebuf), "syslogd: accept deferred: %s",
- strerror(errno));
- logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE);
+ log_info(LOG_WARNING, "accept deferred: %s", strerror(errno));
/*
* Disable the listen event and convert it to a timeout.
* Pass the listen file descriptor to the callback.
struct sockaddr_storage ss;
socklen_t sslen;
char hostname[NI_MAXHOST], servname[NI_MAXSERV];
- char *peername, ebuf[ERRBUFSIZE];
+ char *peername;
int fd;
sslen = sizeof(ss);
p->p_peername = peername;
bufferevent_enable(p->p_bufev, EV_READ);
- snprintf(ebuf, sizeof(ebuf), "syslogd: %s logger \"%s\" accepted",
+ log_info(LOG_INFO, "%s logger \"%s\" accepted",
p->p_ctx ? "tls" : "tcp", peername);
- logmsg(LOG_SYSLOG|LOG_INFO, ebuf, LocalHostName, ADDDATE);
}
/*
tcp_closecb(struct bufferevent *bufev, short event, void *arg)
{
struct peer *p = arg;
- char ebuf[ERRBUFSIZE];
if (event & EVBUFFER_EOF) {
- snprintf(ebuf, sizeof(ebuf), "syslogd: %s logger \"%s\" "
- "connection close", p->p_ctx ? "tls" : "tcp",
- p->p_peername);
- logmsg(LOG_SYSLOG|LOG_INFO, ebuf, LocalHostName, ADDDATE);
+ log_info(LOG_INFO, "%s logger \"%s\" connection close",
+ p->p_ctx ? "tls" : "tcp", p->p_peername);
} else {
- snprintf(ebuf, sizeof(ebuf), "syslogd: %s logger \"%s\" "
- "connection error: %s", p->p_ctx ? "tls" : "tcp",
- p->p_peername,
+ log_info(LOG_NOTICE, "%s logger \"%s\" connection error: %s",
+ p->p_ctx ? "tls" : "tcp", p->p_peername,
p->p_ctx ? tls_error(p->p_ctx) : strerror(errno));
- logmsg(LOG_SYSLOG|LOG_NOTICE, ebuf, LocalHostName, ADDDATE);
}
if (p->p_peername != hostname_unknown)
tcp_writecb(struct bufferevent *bufev, void *arg)
{
struct filed *f = arg;
- char ebuf[ERRBUFSIZE];
/*
* Successful write, connection to server is good, reset wait time.
if (f->f_un.f_forw.f_dropped > 0 &&
EVBUFFER_LENGTH(f->f_un.f_forw.f_bufev->output) < MAX_TCPBUF) {
- snprintf(ebuf, sizeof(ebuf),
- "syslogd: dropped %d message%s to loghost \"%s\"",
+ log_info(LOG_WARNING, "dropped %d message%s to loghost \"%s\"",
f->f_un.f_forw.f_dropped,
f->f_un.f_forw.f_dropped == 1 ? "" : "s",
f->f_un.f_forw.f_loghost);
f->f_un.f_forw.f_dropped = 0;
- logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE);
}
}
char ebuf[ERRBUFSIZE];
if (event & EVBUFFER_EOF)
- snprintf(ebuf, sizeof(ebuf),
- "syslogd: loghost \"%s\" connection close",
+ snprintf(ebuf, sizeof(ebuf), "loghost \"%s\" connection close",
f->f_un.f_forw.f_loghost);
else
snprintf(ebuf, sizeof(ebuf),
- "syslogd: loghost \"%s\" connection error: %s",
+ "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));
log_debug("%s", ebuf);
tcp_connect_retry(bufev, f);
/* Log the connection error to the fresh buffer after reconnecting. */
- logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE);
+ log_info(LOG_WARNING, "%s", ebuf);
}
void
}
line[MAXLINE] = *q = '\0';
- logmsg(pri, line, hname, 0);
+ logline(pri, 0, hname, line);
}
/*
while (*p && (c = *p++) != '\n' && q < &line[sizeof(line) - 4])
q = vis(q, c, 0, 0);
- logmsg(pri, line, LocalHostName, flags);
+ logline(pri, flags, LocalHostName, line);
}
}
l = snprintf(msg, sizeof(msg), "%s[%d]: ", proc, getpid());
if (l < sizeof(msg))
vsnprintf(msg + l, sizeof(msg) - l, fmt, ap);
- logmsg(pri, msg, LocalHostName, ADDDATE);
+ logline(pri, ADDDATE, LocalHostName, msg);
}
struct timeval now;
* the priority.
*/
void
-logmsg(int pri, char *msg, char *from, int flags)
+logline(int pri, int flags, char *from, char *msg)
{
struct filed *f;
int fac, msglen, prilev, i;
char timestamp[33];
char prog[NAME_MAX+1];
- log_debug("logmsg: pri 0%o, flags 0x%x, from %s, msg %s",
+ log_debug("logline: pri 0%o, flags 0x%x, from %s, msg %s",
pri, flags, from, msg);
/*
void
init_signalcb(int signum, short event, void *arg)
{
- char ebuf[ERRBUFSIZE];
-
init();
- logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart",
- LocalHostName, ADDDATE);
+ log_info(LOG_INFO, "restart");
log_debug("syslogd: restarted");
if (tcpbuf_dropped > 0) {
- snprintf(ebuf, sizeof(ebuf),
- "syslogd: dropped %d message%s to remote loghost",
+ log_info(LOG_WARNING, "dropped %d message%s to remote loghost",
tcpbuf_dropped, tcpbuf_dropped == 1 ? "" : "s");
tcpbuf_dropped = 0;
- logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE);
}
}
{
struct filed *f;
int was_initialized = Initialized;
- char ebuf[ERRBUFSIZE];
Initialized = 0; /* Don't log SIGCHLDs */
SIMPLEQ_FOREACH(f, &Files, f_next) {
Initialized = was_initialized;
if (tcpbuf_dropped > 0) {
- snprintf(ebuf, sizeof(ebuf),
- "syslogd: dropped %d message%s to remote loghost",
+ log_info(LOG_WARNING, "dropped %d message%s to remote loghost",
tcpbuf_dropped, tcpbuf_dropped == 1 ? "" : "s");
tcpbuf_dropped = 0;
- logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE);
}
if (signo)
(void)gettimeofday(&now, NULL);
MarkSeq += TIMERINTVL;
if (MarkSeq >= MarkInterval) {
- logmsg(LOG_INFO, "-- MARK --",
- LocalHostName, ADDDATE|MARK);
+ logline(LOG_INFO, ADDDATE|MARK, LocalHostName, "-- MARK --");
MarkSeq = 0;
}