summaryrefslogtreecommitdiffstats
path: root/usr.sbin/syslogd
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2017-09-17 23:49:14 +0000
committerbluhm <bluhm@openbsd.org>2017-09-17 23:49:14 +0000
commitc16a763f6d1ab989b3f3377a8d0e47007feb8353 (patch)
tree9351130b94527006ab82362058976849d89e29c3 /usr.sbin/syslogd
parentvmd: send/recv pci config space instead of recreating pci devices on receive (diff)
downloadwireguard-openbsd-c16a763f6d1ab989b3f3377a8d0e47007feb8353.tar.xz
wireguard-openbsd-c16a763f6d1ab989b3f3377a8d0e47007feb8353.zip
syslogd has special code to report errors before it has been
initialized. For every message it did reopen the console with file descriptor passing from the privsep parent. Now preopen the console, so writing the message out works in more cases. If the console has been revoked, a reopen via privsep and write again is tried anyway. OK brynet@ deraadt@ jca@
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r--usr.sbin/syslogd/syslogd.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 47cebbd2645..2716b4455d0 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.c,v 1.247 2017/09/17 22:25:21 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.248 2017/09/17 23:49:14 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@@ -483,6 +483,10 @@ main(int argc, char *argv[])
consfile.f_type = F_CONSOLE;
(void)strlcpy(consfile.f_un.f_fname, ctty,
sizeof(consfile.f_un.f_fname));
+ consfile.f_file = open(consfile.f_un.f_fname, O_WRONLY|O_NONBLOCK, 0);
+ if (consfile.f_file == -1)
+ log_warn("open %s", consfile.f_un.f_fname);
+
(void)gethostname(LocalHostName, sizeof(LocalHostName));
if ((p = strchr(LocalHostName, '.')) != NULL) {
*p++ = '\0';
@@ -1780,16 +1784,14 @@ logline(int pri, int flags, char *from, char *msg)
/* log the message to the particular outputs */
if (!Initialized) {
f = &consfile;
- f->f_file = priv_open_tty(ctty);
-
- if (f->f_file >= 0) {
+ if (f->f_type == F_CONSOLE) {
strlcpy(f->f_lasttime, timestamp,
sizeof(f->f_lasttime));
strlcpy(f->f_prevhost, from,
sizeof(f->f_prevhost));
fprintlog(f, flags, msg);
- (void)close(f->f_file);
- f->f_file = -1;
+ /* May be set to F_UNUSED, try again next time. */
+ f->f_type = F_CONSOLE;
}
return;
}