summaryrefslogtreecommitdiff
path: root/usr.sbin/syslogd
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-08-03 20:24:17 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-08-03 20:24:17 +0000
commit539d8546102ef6f0f706173d76469592e0c7038e (patch)
tree85f1a50b8921d01a65dff3726de0d0f458e80efe /usr.sbin/syslogd
parent5afd0d401f7874b33a1973e2751d0db42bbaa32c (diff)
Open files with O_NONBLOCK but turn off non-blocking mode for
non-ttys. If write(2) returns EAGAIN just ignore the error and move on. This prevents a locked terminal from causing syslogd grief. If we ever want to support logging to a fifo this will probably have to be revisited.
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r--usr.sbin/syslogd/syslogd.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index a612719b3c7..55c0f0bba57 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.c,v 1.42 2001/08/03 19:09:26 deraadt Exp $ */
+/* $OpenBSD: syslogd.c,v 1.43 2001/08/03 20:24:16 millert Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
#else
-static char rcsid[] = "$OpenBSD: syslogd.c,v 1.42 2001/08/03 19:09:26 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: syslogd.c,v 1.43 2001/08/03 20:24:16 millert Exp $";
#endif
#endif /* not lint */
@@ -589,7 +589,7 @@ logmsg(pri, msg, from, flags)
/* log the message to the particular outputs */
if (!Initialized) {
f = &consfile;
- f->f_file = open(ctty, O_WRONLY, 0);
+ f->f_file = open(ctty, O_WRONLY|O_NONBLOCK, 0);
if (f->f_file >= 0) {
fprintlog(f, flags, msg);
@@ -758,9 +758,16 @@ fprintlog(f, flags, msg)
/*
* Check for errors on TTY's due to loss of tty
*/
- if ((e == EIO || e == EBADF) && f->f_type != F_FILE) {
+ if (e == EAGAIN) {
+ /*
+ * Silently drop messages on blocked write.
+ * This can happen when logging to a locked tty.
+ */
+ break;
+ } else if ((e == EIO || e == EBADF) &&
+ f->f_type != F_FILE) {
f->f_file = open(f->f_un.f_fname,
- O_WRONLY|O_APPEND, 0);
+ O_WRONLY|O_APPEND|O_NONBLOCK, 0);
if (f->f_file < 0) {
f->f_type = F_UNUSED;
logerror(f->f_un.f_fname);
@@ -1213,17 +1220,25 @@ cfline(line, f, prog)
case '/':
(void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
- if ((f->f_file = open(p, O_WRONLY|O_APPEND, 0)) < 0) {
+ f->f_file = open(p, O_WRONLY|O_APPEND|O_NONBLOCK, 0);
+ if (f->f_file < 0) {
f->f_type = F_UNUSED;
logerror(p);
break;
}
- if (isatty(f->f_file))
- f->f_type = F_TTY;
- else
+ if (isatty(f->f_file)) {
+ if (strcmp(p, ctty) == 0)
+ f->f_type = F_CONSOLE;
+ else
+ f->f_type = F_TTY;
+ } else {
f->f_type = F_FILE;
- if (strcmp(p, ctty) == 0)
- f->f_type = F_CONSOLE;
+ /* Clear O_NONBLOCK flag on f->f_file */
+ if ((i = fcntl(f->f_file, F_GETFL, 0)) != -1) {
+ i &= ~O_NONBLOCK;
+ fcntl(f->f_file, F_SETFL, i);
+ }
+ }
break;
case '*':