syslogd(8): timed out waiting for child
Martin Blapp
mb at imp.ch
Tue May 25 14:57:53 PDT 2004
and here is the patch adapted for current ...
--- syslogd.c.orig Tue May 25 23:52:28 2004
+++ syslogd.c Tue May 25 23:50:55 2004
@@ -881,7 +881,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) {
(void)strlcpy(f->f_lasttime, timestamp,
@@ -1135,12 +1135,34 @@
dprintf(" %s\n", f->f_un.f_fname);
v->iov_base = "\n";
v->iov_len = 1;
+ again:
if (writev(f->f_file, iov, 7) < 0) {
int e = errno;
(void)close(f->f_file);
- f->f_type = F_UNUSED;
- errno = e;
- logerror(f->f_un.f_fname);
+
+ /*
+ * Check for errors on TTY's due to loss of tty
+ */
+ 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|O_NONBLOCK, 0);
+ if (f->f_file < 0) {
+ f->f_type = F_UNUSED;
+ logerror(f->f_un.f_fname);
+ } else
+ goto again;
+ } else {
+ f->f_type = F_UNUSED;
+ errno = e;
+ logerror(f->f_un.f_fname);
+ }
} else if (f->f_flags & SYNC_FILE)
(void)fsync(f->f_file);
break;
@@ -1792,7 +1814,8 @@
break;
case '/':
- 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;
@@ -1807,8 +1830,13 @@
(void)strlcpy(f->f_un.f_fname, p + sizeof(_PATH_DEV) - 1,
sizeof(f->f_un.f_fname));
} else {
- (void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
f->f_type = F_FILE;
+ /* 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);
+ }
+ (void)strlcpy(f->f_un.f_fname, p, sizeof(f->f_un.f_fname));
}
break;
More information about the freebsd-current
mailing list