diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2017-04-05 19:34:50 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2017-04-05 19:34:50 +0000 |
commit | c22a1165d44cd0f239379cc3fe855a5a20ff5d37 (patch) | |
tree | 4ddbd2487eefd99eadb0b094f2f7c7291e2f0caa /usr.sbin | |
parent | d44e6b45ccf0e79cbf0f1e3f55b8bc47cc8950e2 (diff) |
Replace logerror() functions with generic log_warn() from log.c.
Make messages a bit more consistent. Note that the new function
supports format strings. Replace some log_debug() with log_warn().
OK millert@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 313 |
1 files changed, 116 insertions, 197 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 09cfa61c88e..d8557b30094 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: syslogd.c,v 1.236 2017/04/05 15:16:12 bluhm Exp $ */ +/* $OpenBSD: syslogd.c,v 1.237 2017/04/05 19:34:49 bluhm Exp $ */ /* * Copyright (c) 1983, 1988, 1993, 1994 @@ -321,11 +321,6 @@ void markit(void); void fprintlog(struct filed *, int, char *); void init(void); void logevent(int, const char *); -void logerror(const char *); -void logerrorx(const char *); -void logerrorctx(const char *, struct tls *); -void logerrortlsconf(const char *, struct tls_config *); -void logerror_reason(const char *, const char *); void logmsg(int, char *, char *, int); struct filed *find_dup(struct filed *); size_t parsepriority(const char *, int *); @@ -501,13 +496,13 @@ main(int argc, char *argv[]) if (socket_bind("udp", NULL, "syslog", SecureMode, &fd_udp, &fd_udp6) == -1) - logerrorx("socket bind *"); + log_warnx("socket bind * failed"); if ((fd_bind = reallocarray(NULL, nbind, sizeof(*fd_bind))) == NULL) fatal("allocate bind fd"); for (i = 0; i < nbind; i++) { if (socket_bind("udp", bind_host[i], bind_port[i], 0, &fd_bind[i], &fd_bind[i]) == -1) - logerrorx("socket bind udp"); + log_warnx("socket bind udp failed"); } if ((fd_listen = reallocarray(NULL, nlisten, sizeof(*fd_listen))) == NULL) @@ -515,12 +510,12 @@ main(int argc, char *argv[]) for (i = 0; i < nlisten; i++) { if (socket_bind("tcp", listen_host[i], listen_port[i], 0, &fd_listen[i], &fd_listen[i]) == -1) - logerrorx("socket listen tcp"); + log_warnx("socket listen tcp failed"); } fd_tls = -1; if (tls_host && socket_bind("tls", tls_host, tls_port, 0, &fd_tls, &fd_tls) == -1) - logerrorx("socket listen tls"); + log_warnx("socket listen tls failed"); if ((fd_unix = reallocarray(NULL, nunix, sizeof(*fd_unix))) == NULL) fatal("allocate unix fd"); @@ -528,14 +523,14 @@ main(int argc, char *argv[]) fd_unix[i] = unix_socket(path_unix[i], SOCK_DGRAM, 0666); if (fd_unix[i] == -1) { if (i == 0) - logerrorx("log socket failed"); + log_warnx("log socket %s failed", path_unix[i]); continue; } double_sockbuf(fd_unix[i], SO_RCVBUF); } if (socketpair(AF_UNIX, SOCK_DGRAM, PF_UNSPEC, pair) == -1) { - logerror("socketpair"); + log_warn("socketpair sendsyslog"); fd_sendsys = -1; } else { double_sockbuf(pair[0], SO_RCVBUF); @@ -547,10 +542,10 @@ main(int argc, char *argv[]) if (path_ctlsock != NULL) { fd_ctlsock = unix_socket(path_ctlsock, SOCK_STREAM, 0600); if (fd_ctlsock == -1) { - log_debug("can't open %s (%d)", path_ctlsock, errno); + log_warnx("control socket %s failed", path_ctlsock); } else { if (listen(fd_ctlsock, 5) == -1) { - logerror("ctlsock listen"); + log_warn("listen control socket"); close(fd_ctlsock); fd_ctlsock = -1; } @@ -558,24 +553,24 @@ main(int argc, char *argv[]) } if ((fd_klog = open(_PATH_KLOG, O_RDONLY, 0)) == -1) { - log_debug("can't open %s (%d)", _PATH_KLOG, errno); + log_warn("open %s", _PATH_KLOG); } else if (fd_sendsys != -1) { if (ioctl(fd_klog, LIOCSFD, &pair[1]) == -1) - log_debug("LIOCSFD errno %d", errno); + log_warn("ioctl klog LIOCSFD sendsyslog"); } if (fd_sendsys != -1) close(pair[1]); if (tls_init() == -1) { - logerrorx("tls_init"); + log_warn("tls_init"); } else { if ((client_config = tls_config_new()) == NULL) - logerror("tls_config_new client"); + log_warn("tls_config_new client"); if (tls_hostport) { if ((server_config = tls_config_new()) == NULL) - logerror("tls_config_new server"); + log_warn("tls_config_new server"); if ((server_ctx = tls_server()) == NULL) { - logerror("tls_server"); + log_warn("tls_server"); close(fd_tls); fd_tls = -1; } @@ -588,8 +583,8 @@ main(int argc, char *argv[]) } else { if (tls_config_set_ca_file(client_config, CAfile) == -1) { - logerrortlsconf("Load client TLS CA failed", - client_config); + log_warnx("load client TLS CA: %s", + tls_config_error(client_config)); /* avoid reading default certs in chroot */ tls_config_set_ca_mem(client_config, "", 0); } else @@ -598,27 +593,27 @@ main(int argc, char *argv[]) if (ClientCertfile && ClientKeyfile) { if (tls_config_set_cert_file(client_config, ClientCertfile) == -1) - logerrortlsconf("Load client TLS cert failed", - client_config); + log_warnx("load client TLS cert: %s", + tls_config_error(client_config)); else log_debug("ClientCertfile %s", ClientCertfile); if (tls_config_set_key_file(client_config, ClientKeyfile) == -1) - logerrortlsconf("Load client TLS key failed", - client_config); + log_warnx("load client TLS key: %s", + tls_config_error(client_config)); else log_debug("ClientKeyfile %s", ClientKeyfile); } else if (ClientCertfile || ClientKeyfile) { - logerrorx("options -c and -k must be used together"); + log_warnx("options -c and -k must be used together"); } if (tls_config_set_protocols(client_config, TLS_PROTOCOLS_ALL) != 0) - logerrortlsconf("Set client TLS protocols failed", - client_config); + log_warnx("set client TLS protocols: %s", + tls_config_error(client_config)); if (tls_config_set_ciphers(client_config, "all") != 0) - logerrortlsconf("Set client TLS ciphers failed", - client_config); + log_warnx("set client TLS ciphers: %s", + tls_config_error(client_config)); } if (server_config && server_ctx) { const char *names[2]; @@ -631,8 +626,8 @@ main(int argc, char *argv[]) == -1) continue; if (tls_config_set_key_file(server_config, p) == -1) { - logerrortlsconf("Load server TLS key failed", - server_config); + log_warnx("load server TLS key: %s", + tls_config_error(server_config)); free(p); continue; } @@ -641,8 +636,8 @@ main(int argc, char *argv[]) if (asprintf(&p, "/etc/ssl/%s.crt", names[i]) == -1) continue; if (tls_config_set_cert_file(server_config, p) == -1) { - logerrortlsconf("Load server TLS cert failed", - server_config); + log_warnx("load server TLS cert: %s", + tls_config_error(server_config)); free(p); continue; } @@ -654,8 +649,8 @@ main(int argc, char *argv[]) if (ServerCAfile) { if (tls_config_set_ca_file(server_config, ServerCAfile) == -1) { - logerrortlsconf("Load server TLS CA failed", - server_config); + log_warnx("load server TLS CA: %s", + tls_config_error(server_config)); /* avoid reading default certs in chroot */ tls_config_set_ca_mem(server_config, "", 0); } else @@ -664,13 +659,14 @@ main(int argc, char *argv[]) } if (tls_config_set_protocols(server_config, TLS_PROTOCOLS_ALL) != 0) - logerrortlsconf("Set server TLS protocols failed", - server_config); + log_warnx("set server TLS protocols: %s", + tls_config_error(server_config)); if (tls_config_set_ciphers(server_config, "compat") != 0) - logerrortlsconf("Set server TLS ciphers failed", - server_config); + log_warnx("Set server TLS ciphers: %s", + tls_config_error(server_config)); if (tls_configure(server_ctx, server_config) != 0) { - logerrorctx("tls_configure server", server_ctx); + log_warnx("tls_configure server: %s", + tls_error(server_ctx)); tls_free(server_ctx); server_ctx = NULL; close(fd_tls); @@ -871,7 +867,6 @@ socket_bind(const char *proto, const char *host, const char *port, { struct addrinfo hints, *res, *res0; char hostname[NI_MAXHOST], servname[NI_MAXSERV]; - char ebuf[ERRBUFSIZE]; int *fdp, error, reuseaddr; *fd = *fd6 = -1; @@ -892,10 +887,8 @@ socket_bind(const char *proto, const char *host, const char *port, hints.ai_flags = AI_PASSIVE; if ((error = getaddrinfo(host, port, &hints, &res0))) { - snprintf(ebuf, sizeof(ebuf), "getaddrinfo " - "proto %s, host %s, port %s: %s", + log_warnx("getaddrinfo proto %s, host %s, port %s: %s", proto, host ? host : "*", port, gai_strerror(error)); - logerrorx(ebuf); return (-1); } @@ -925,10 +918,9 @@ socket_bind(const char *proto, const char *host, const char *port, hostname[0] = servname[0] = '\0'; } if (shutread && shutdown(*fdp, SHUT_RD) == -1) { - snprintf(ebuf, sizeof(ebuf), "shutdown SHUT_RD " + log_warn("shutdown SHUT_RD " "protocol %d, address %s, portnum %s", res->ai_protocol, hostname, servname); - logerror(ebuf); close(*fdp); *fdp = -1; continue; @@ -940,29 +932,24 @@ socket_bind(const char *proto, const char *host, const char *port, reuseaddr = 1; if (setsockopt(*fdp, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr)) == -1) { - snprintf(ebuf, sizeof(ebuf), "setsockopt SO_REUSEADDR " + log_warn("setsockopt SO_REUSEADDR " "protocol %d, address %s, portnum %s", res->ai_protocol, hostname, servname); - logerror(ebuf); close(*fdp); *fdp = -1; continue; } if (bind(*fdp, res->ai_addr, res->ai_addrlen) == -1) { - snprintf(ebuf, sizeof(ebuf), "bind " - "protocol %d, address %s, portnum %s", + log_warn("bind protocol %d, address %s, portnum %s", res->ai_protocol, hostname, servname); - logerror(ebuf); close(*fdp); *fdp = -1; continue; } if (!shutread && res->ai_protocol == IPPROTO_TCP && listen(*fdp, 10) == -1) { - snprintf(ebuf, sizeof(ebuf), "listen " - "protocol %d, address %s, portnum %s", + log_warn("listen protocol %d, address %s, portnum %s", res->ai_protocol, hostname, servname); - logerror(ebuf); close(*fdp); *fdp = -1; continue; @@ -987,7 +974,7 @@ klog_readcb(int fd, short event, void *arg) linebuf[n] = '\0'; printsys(linebuf); } else if (n < 0 && errno != EINTR) { - logerror("klog"); + log_warn("read klog"); event_del(ev); } } @@ -1009,7 +996,7 @@ udp_readcb(int fd, short event, void *arg) log_debug("cvthname res: %s", resolve); printline(resolve, linebuf); } else if (n < 0 && errno != EINTR && errno != EWOULDBLOCK) - logerror("recvfrom udp"); + log_warn("recvfrom udp"); } void @@ -1025,7 +1012,7 @@ unix_readcb(int fd, short event, void *arg) linebuf[n] = '\0'; printline(LocalHostName, linebuf); } else if (n < 0 && errno != EINTR && errno != EWOULDBLOCK) - logerror("recvfrom unix"); + log_warn("recvfrom unix"); } int @@ -1098,7 +1085,7 @@ acceptcb(int lfd, short event, void *arg, int usetls) if (errno != ENFILE && errno != EMFILE && errno != EINTR && errno != EWOULDBLOCK && errno != ECONNABORTED) - logerror("accept tcp socket"); + log_warn("accept tcp socket"); return; } log_debug("Accepting tcp connection"); @@ -1113,16 +1100,14 @@ acceptcb(int lfd, short event, void *arg, int usetls) } log_debug("Peer addresss and port %s", peername); if ((p = malloc(sizeof(*p))) == NULL) { - snprintf(ebuf, sizeof(ebuf), "malloc \"%s\"", peername); - logerror(ebuf); + log_warn("allocate \"%s\"", peername); close(fd); return; } p->p_fd = fd; if ((p->p_bufev = bufferevent_new(fd, tcp_readcb, NULL, tcp_closecb, p)) == NULL) { - snprintf(ebuf, sizeof(ebuf), "bufferevent \"%s\"", peername); - logerror(ebuf); + log_warn("bufferevent \"%s\"", peername); free(p); close(fd); return; @@ -1130,9 +1115,8 @@ acceptcb(int lfd, short event, void *arg, int usetls) p->p_ctx = NULL; if (usetls) { if (tls_accept_socket(server_ctx, &p->p_ctx, fd) < 0) { - snprintf(ebuf, sizeof(ebuf), "tls_accept_socket \"%s\"", - peername); - logerrorctx(ebuf, server_ctx); + log_warnx("tls_accept_socket \"%s\": %s", + peername, tls_error(server_ctx)); bufferevent_free(p->p_bufev); free(p); close(fd); @@ -1309,21 +1293,16 @@ int tcp_socket(struct filed *f) { int s; - char ebuf[ERRBUFSIZE]; if ((s = socket(f->f_un.f_forw.f_addr.ss_family, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP)) == -1) { - snprintf(ebuf, sizeof(ebuf), "socket \"%s\"", - f->f_un.f_forw.f_loghost); - logerror(ebuf); + log_warn("socket \"%s\"", f->f_un.f_forw.f_loghost); return (-1); } set_sockbuf(s); if (connect(s, (struct sockaddr *)&f->f_un.f_forw.f_addr, f->f_un.f_forw.f_addr.ss_len) == -1 && errno != EINPROGRESS) { - snprintf(ebuf, sizeof(ebuf), "connect \"%s\"", - f->f_un.f_forw.f_loghost); - logerror(ebuf); + log_warn("connect \"%s\"", f->f_un.f_forw.f_loghost); close(s); return (-1); } @@ -1429,7 +1408,6 @@ tcp_connectcb(int fd, short event, void *arg) { struct filed *f = arg; struct bufferevent *bufev = f->f_un.f_forw.f_bufev; - char ebuf[ERRBUFSIZE]; int s; if ((s = tcp_socket(f)) == -1) { @@ -1449,23 +1427,21 @@ tcp_connectcb(int fd, short event, void *arg) if (f->f_type == F_FORWTLS) { if ((f->f_un.f_forw.f_ctx = tls_client()) == NULL) { - snprintf(ebuf, sizeof(ebuf), "tls_client \"%s\"", - f->f_un.f_forw.f_loghost); - logerror(ebuf); + log_warn("tls_client \"%s\"", f->f_un.f_forw.f_loghost); goto error; } if (client_config && tls_configure(f->f_un.f_forw.f_ctx, client_config) == -1) { - snprintf(ebuf, sizeof(ebuf), "tls_configure \"%s\"", - f->f_un.f_forw.f_loghost); - logerrorctx(ebuf, f->f_un.f_forw.f_ctx); + log_warnx("tls_configure \"%s\": %s", + f->f_un.f_forw.f_loghost, + tls_error(f->f_un.f_forw.f_ctx)); goto error; } if (tls_connect_socket(f->f_un.f_forw.f_ctx, s, f->f_un.f_forw.f_host) == -1) { - snprintf(ebuf, sizeof(ebuf), "tls_connect_socket " - "\"%s\"", f->f_un.f_forw.f_loghost); - logerrorctx(ebuf, f->f_un.f_forw.f_ctx); + log_warnx("tls_connect_socket \"%s\": %s", + f->f_un.f_forw.f_loghost, + tls_error(f->f_un.f_forw.f_ctx)); goto error; } log_debug("tcp connect callback: tls context success"); @@ -1950,7 +1926,8 @@ fprintlog(struct filed *f, int flags, char *msg) break; default: f->f_type = F_UNUSED; - logerror("sendto"); + log_warn("sendto \"%s\"", + f->f_un.f_forw.f_loghost); break; } } @@ -2024,7 +2001,8 @@ fprintlog(struct filed *f, int flags, char *msg) if (e == EAGAIN && f->f_type == F_PIPE) { if (now.tv_sec - f->f_lasterrtime > 120) { f->f_lasterrtime = now.tv_sec; - logerror(f->f_un.f_fname); + log_warn("writev \"%s\"", + f->f_un.f_fname); } break; } @@ -2047,7 +2025,8 @@ fprintlog(struct filed *f, int flags, char *msg) retryonce = 1; if (f->f_file < 0) { f->f_type = F_UNUSED; - logerror(f->f_un.f_fname); + log_warn("priv_open_tty \"%s\"", + f->f_un.f_fname); } else goto again; } else if ((e == EPIPE || e == EBADF) && @@ -2056,14 +2035,15 @@ fprintlog(struct filed *f, int flags, char *msg) retryonce = 1; if (f->f_file < 0) { f->f_type = F_UNUSED; - logerror(f->f_un.f_fname); + log_warn("priv_open_log \"%s\"", + f->f_un.f_fname); } else goto again; } else { f->f_type = F_UNUSED; f->f_file = -1; errno = e; - logerror(f->f_un.f_fname); + log_warn("writev \"%s\"", f->f_un.f_fname); } } else if (flags & SYNC_FILE) (void)fsync(f->f_file); @@ -2109,7 +2089,7 @@ wallmsg(struct filed *f, struct iovec *iov) if (reenter++) return; if ((uf = priv_open_utmp()) == NULL) { - logerror(_PATH_UTMP); + log_warn("priv_open_utmp"); reenter = 0; return; } @@ -2121,7 +2101,7 @@ wallmsg(struct filed *f, struct iovec *iov) utline[sizeof(utline) - 1] = '\0'; if (f->f_type == F_WALL) { if ((p = ttymsg(iov, 6, utline)) != NULL) - logerrorx(p); + log_warnx("%s", p); continue; } /* should we send the message to this user? */ @@ -2131,7 +2111,7 @@ wallmsg(struct filed *f, struct iovec *iov) if (!strncmp(f->f_un.f_uname[i], ut.ut_name, UT_NAMESIZE)) { if ((p = ttymsg(iov, 6, utline)) != NULL) - logerrorx(p); + log_warnx("%s", p); break; } } @@ -2205,48 +2185,6 @@ logevent(int severity, const char *msg) log_debug("libevent: [%d] %s", severity, msg); } -void -logerror(const char *message) -{ - logerror_reason(message, errno ? strerror(errno) : NULL); -} - -void -logerrorx(const char *message) -{ - logerror_reason(message, NULL); -} - -void -logerrorctx(const char *message, struct tls *ctx) -{ - logerror_reason(message, ctx ? tls_error(ctx) : NULL); -} - -void -logerrortlsconf(const char *message, struct tls_config *config) -{ - logerror_reason(message, config ? tls_config_error(config) : NULL); -} - -void -logerror_reason(const char *message, const char *reason) -{ - char ebuf[ERRBUFSIZE]; - - if (reason) - (void)snprintf(ebuf, sizeof(ebuf), "syslogd: %s: %s", - message, reason); - else - (void)snprintf(ebuf, sizeof(ebuf), "syslogd: %s", message); - errno = 0; - log_debug("%s", ebuf); - if (Startup) - fprintf(stderr, "%s\n", ebuf); - else - logmsg(LOG_SYSLOG|LOG_ERR, ebuf, LocalHostName, ADDDATE); -} - __dead void die(int signo) { @@ -2275,13 +2213,9 @@ die(int signo) logmsg(LOG_SYSLOG|LOG_WARNING, ebuf, LocalHostName, ADDDATE); } - if (signo) { - log_debug("syslogd: exiting on signal %d", signo); - (void)snprintf(ebuf, sizeof(ebuf), "exiting on signal %d", - signo); - logerrorx(ebuf); - } - log_debug("[unpriv] syslogd child about to exit"); + if (signo) + log_warnx("exiting on signal %d", signo); + log_debug("syslogd: exited"); exit(0); } @@ -2432,7 +2366,7 @@ init(void) 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"); + log_warn("allocate membuf"); } } else { log_debug("Membuf match f:%p, m:%p", f, m); @@ -2446,7 +2380,7 @@ init(void) m = SIMPLEQ_FIRST(&mb); SIMPLEQ_REMOVE_HEAD(&mb, f_next); if (m->f_un.f_mb.f_rb != NULL) { - logerrorx("Mismatched membuf"); + log_warnx("mismatched membuf"); ringbuf_free(m->f_un.f_mb.f_rb); } log_debug("Freeing membuf %p", m); @@ -2551,7 +2485,7 @@ cfline(char *line, char *progblock, char *hostblock) int i, pri; size_t rb_len; char *bp, *p, *q, *proto, *host, *port, *ipproto; - char buf[MAXLINE], ebuf[ERRBUFSIZE]; + char buf[MAXLINE]; struct filed *xf, *f, *d; struct timeval to; @@ -2605,9 +2539,7 @@ cfline(char *line, char *progblock, char *hostblock) pri = decode(buf, prioritynames); if (pri < 0) { - (void)snprintf(ebuf, sizeof ebuf, - "unknown priority name \"%s\"", buf); - logerrorx(ebuf); + log_warnx("unknown priority name \"%s\"", buf); free(f); return (NULL); } @@ -2624,10 +2556,8 @@ cfline(char *line, char *progblock, char *hostblock) else { i = decode(buf, facilitynames); if (i < 0) { - (void)snprintf(ebuf, sizeof(ebuf), - "unknown facility name \"%s\"", - buf); - logerrorx(ebuf); + log_warnx("unknown facility name " + "\"%s\"", buf); free(f); return (NULL); } @@ -2649,15 +2579,12 @@ cfline(char *line, char *progblock, char *hostblock) if ((strlcpy(f->f_un.f_forw.f_loghost, p, sizeof(f->f_un.f_forw.f_loghost)) >= sizeof(f->f_un.f_forw.f_loghost))) { - snprintf(ebuf, sizeof(ebuf), "loghost too long \"%s\"", - p); - logerrorx(ebuf); + log_warnx("loghost too long \"%s\"", p); break; } if (loghost_parse(++p, &proto, &host, &port) == -1) { - snprintf(ebuf, sizeof(ebuf), "bad loghost \"%s\"", + log_warnx("bad loghost \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } if (proto == NULL) @@ -2671,16 +2598,14 @@ cfline(char *line, char *progblock, char *hostblock) ipproto = proto; } else if (strcmp(proto, "udp4") == 0) { if (fd_udp == -1) { - snprintf(ebuf, sizeof(ebuf), "no udp4 \"%s\"", + log_warnx("no udp4 \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } } else if (strcmp(proto, "udp6") == 0) { if (fd_udp6 == -1) { - snprintf(ebuf, sizeof(ebuf), "no udp6 \"%s\"", + log_warnx("no udp6 \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } } else if (strcmp(proto, "tcp") == 0 || @@ -2693,32 +2618,28 @@ cfline(char *line, char *progblock, char *hostblock) } else if (strcmp(proto, "tls6") == 0) { ipproto = "tcp6"; } else { - snprintf(ebuf, sizeof(ebuf), "bad protocol \"%s\"", + log_warnx("bad protocol \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } if (strlen(host) >= NI_MAXHOST) { - snprintf(ebuf, sizeof(ebuf), "host too long \"%s\"", + log_warnx("host too long \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } if (port == NULL) port = strncmp(proto, "tls", 3) == 0 ? "syslog-tls" : "syslog"; if (strlen(port) >= NI_MAXSERV) { - snprintf(ebuf, sizeof(ebuf), "port too long \"%s\"", + log_warnx("port too long \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } if (priv_getaddrinfo(ipproto, host, port, (struct sockaddr*)&f->f_un.f_forw.f_addr, sizeof(f->f_un.f_forw.f_addr)) != 0) { - snprintf(ebuf, sizeof(ebuf), "bad hostname \"%s\"", + log_warnx("bad hostname \"%s\"", f->f_un.f_forw.f_loghost); - logerrorx(ebuf); break; } f->f_file = -1; @@ -2735,10 +2656,8 @@ cfline(char *line, char *progblock, char *hostblock) } else if (strncmp(ipproto, "tcp", 3) == 0) { if ((f->f_un.f_forw.f_bufev = bufferevent_new(-1, tcp_dropcb, tcp_writecb, tcp_errorcb, f)) == NULL) { - snprintf(ebuf, sizeof(ebuf), - "bufferevent \"%s\"", + log_warn("bufferevent \"%s\"", f->f_un.f_forw.f_loghost); - logerror(ebuf); break; } if (strncmp(proto, "tls", 3) == 0) { @@ -2773,13 +2692,17 @@ cfline(char *line, char *progblock, char *hostblock) free(f); return (NULL); } - if (strcmp(p, ctty) == 0) + if (strcmp(p, ctty) == 0) { f->f_file = priv_open_tty(p); - else + if (f->f_file < 0) + log_warn("priv_open_tty \"%s\"", p); + } else { f->f_file = priv_open_log(p); + if (f->f_file < 0) + log_warn("priv_open_log \"%s\"", p); + } if (f->f_file < 0) { f->f_type = F_UNUSED; - logerror(p); break; } if (isatty(f->f_file)) { @@ -2815,7 +2738,7 @@ cfline(char *line, char *progblock, char *hostblock) if (*p == '\0' || (errno == ERANGE && rb_len == ULONG_MAX) || *q != ':' || rb_len == 0) { f->f_type = F_UNUSED; - logerror(p); + log_warnx("strtoul \"%s\"", p); break; } q++; @@ -2834,7 +2757,7 @@ cfline(char *line, char *progblock, char *hostblock) /* Error on missing or non-unique name, or bad buffer length */ if (i == 0 || rb_len > MAX_MEMBUF || xf != NULL) { f->f_type = F_UNUSED; - logerrorx(p); + log_warnx("find_dup \"%s\"", p); break; } @@ -2968,7 +2891,6 @@ int unix_socket(char *path, int type, mode_t mode) { struct sockaddr_un s_un; - char ebuf[512]; int fd, optval; mode_t old_umask; @@ -2976,13 +2898,12 @@ unix_socket(char *path, int type, mode_t mode) s_un.sun_family = AF_UNIX; if (strlcpy(s_un.sun_path, path, sizeof(s_un.sun_path)) >= sizeof(s_un.sun_path)) { - snprintf(ebuf, sizeof(ebuf), "socket path too long: %s", path); - logerrorx(ebuf); + log_warnx("socket path too long \"%s\"", path); return (-1); } if ((fd = socket(AF_UNIX, type, 0)) == -1) { - logerror("socket"); + log_warn("socket unix \"%s\"", path); return (-1); } @@ -2991,7 +2912,7 @@ unix_socket(char *path, int type, mode_t mode) errno == EPROTOTYPE) { close(fd); errno = EISCONN; - logerror("connect"); + log_warn("connect unix \"%s\"", path); return (-1); } } @@ -3000,8 +2921,7 @@ unix_socket(char *path, int type, mode_t mode) unlink(path); if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) { - snprintf(ebuf, sizeof(ebuf), "cannot bind %s", path); - logerror(ebuf); + log_warn("bind unix \"%s\"", path); umask(old_umask); close(fd); return (-1); @@ -3010,8 +2930,7 @@ unix_socket(char *path, int type, mode_t mode) umask(old_umask); if (chmod(path, mode) == -1) { - snprintf(ebuf, sizeof(ebuf), "cannot chmod %s", path); - logerror(ebuf); + log_warn("chmod unix \"%s\"", path); close(fd); unlink(path); return (-1); @@ -3020,7 +2939,7 @@ unix_socket(char *path, int type, mode_t mode) optval = MAXLINE + PATH_MAX; if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &optval, sizeof(optval)) == -1) - logerror("setsockopt unix"); + log_warn("setsockopt unix \"%s\"", path); return (fd); } @@ -3033,7 +2952,7 @@ double_sockbuf(int fd, int optname) len = sizeof(oldsize); if (getsockopt(fd, SOL_SOCKET, optname, &oldsize, &len) == -1) - logerror("getsockopt bufsize"); + log_warn("getsockopt bufsize"); len = sizeof(newsize); newsize = MAXLINE + 128; /* data + control */ /* allow 8 full length messages */ @@ -3041,7 +2960,7 @@ double_sockbuf(int fd, int optname) if (newsize <= oldsize) continue; if (setsockopt(fd, SOL_SOCKET, optname, &newsize, len) == -1) - logerror("setsockopt bufsize"); + log_warn("setsockopt bufsize %d", newsize); } } @@ -3051,9 +2970,9 @@ set_sockbuf(int fd) int size = 65536; if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) == -1) - logerror("setsockopt sndbufsize"); + log_warn("setsockopt sndbufsize %d", size); if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) == -1) - logerror("setsockopt rcvbufsize"); + log_warn("setsockopt rcvbufsize %d", size); } void @@ -3085,7 +3004,7 @@ ctlsock_acceptcb(int fd, short event, void *arg) if (errno != ENFILE && errno != EMFILE && errno != EINTR && errno != EWOULDBLOCK && errno != ECONNABORTED) - logerror("accept ctlsock"); + log_warn("accept control socket"); return; } log_debug("Accepting control connection"); @@ -3144,7 +3063,7 @@ ctlconn_readcb(int fd, short event, void *arg) goto retry; if (errno == EWOULDBLOCK) return; - logerror("ctlconn read"); + log_warn("read control socket"); /* FALLTHROUGH */ case 0: ctlconn_cleanup(); @@ -3156,14 +3075,14 @@ ctlconn_readcb(int fd, short event, void *arg) return; if (ntohl(ctl_cmd.version) != CTL_VERSION) { - logerrorx("Unknown client protocol version"); + log_warnx("unknown client protocol version"); ctlconn_cleanup(); return; } /* Ensure that logname is \0 terminated */ if (memchr(ctl_cmd.logname, '\0', sizeof(ctl_cmd.logname)) == NULL) { - logerrorx("Corrupt ctlsock command"); + log_warnx("corrupt control socket command"); ctlconn_cleanup(); return; } @@ -3231,7 +3150,7 @@ ctlconn_readcb(int fd, short event, void *arg) strlcat(reply_text, "\n", MAX_MEMBUF); break; default: - logerrorx("Unsupported ctlsock command"); + log_warnx("unsupported control socket command"); ctlconn_cleanup(); return; } @@ -3261,7 +3180,7 @@ ctlconn_writecb(int fd, short event, void *arg) if (!(ctl_state == CTL_WRITING_REPLY || ctl_state == CTL_WRITING_CONT_REPLY)) { /* Shouldn't be here! */ - logerrorx("ctlconn_write with bad ctl_state"); + log_warnx("control socket write with bad state"); ctlconn_cleanup(); return; } @@ -3276,7 +3195,7 @@ ctlconn_writecb(int fd, short event, void *arg) if (errno == EWOULDBLOCK) return; if (errno != EPIPE) - logerror("ctlconn write"); + log_warn("write control socket"); /* FALLTHROUGH */ case 0: ctlconn_cleanup(); |