Date: Sun, 17 Feb 2002 10:43:09 -0700 From: "Todd C. Miller" <Todd.Miller@courtesan.com> To: David Malone <dwmalone@maths.tcd.ie> Cc: audit@FreeBSD.ORG, Chris Johnson <cjohnson@palomine.net>, Brian McDonald <brian@lustygrapes.net> Subject: Re: Syslog hangong on console. Message-ID: <200202171743.g1HHhATG025320@xerxes.courtesan.com> In-Reply-To: Your message of "Sun, 17 Feb 2002 17:37:13 GMT." <200202171737.aa59770@salmon.maths.tcd.ie> References: <200202171737.aa59770@salmon.maths.tcd.ie>
next in thread | previous in thread | raw e-mail | index | archive | help
Below is the diff I committed to OpenBSD some time ago. It goes a
bit farther and opens all files with O_NONBLOCK and then changes
to blocking writes for real files.
- todd
----------------------------
revision 1.43
date: 2001/08/03 20:24:16; author: millert; state: Exp; lines: +26 -11
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.
----------------------------
Index: syslogd.c
===================================================================
RCS file: /cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- syslogd.c 3 Aug 2001 19:09:26 -0000 1.42
+++ syslogd.c 3 Aug 2001 20:24:16 -0000 1.43
@@ -589,7 +589,7 @@
/* 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 @@
/*
* 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 @@
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 '*':
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202171743.g1HHhATG025320>
