Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/syslogd Now need to use own buffer for klog read du...



details:   https://anonhg.NetBSD.org/src/rev/fd5a9e5109f1
branches:  trunk
changeset: 766292:fd5a9e5109f1
user:      enami <enami%NetBSD.org@localhost>
date:      Mon Jun 20 08:27:15 2011 +0000

description:
Now need to use own buffer for klog read due to previous change.

diffstat:

 usr.sbin/syslogd/syslogd.c |  32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diffs (86 lines):

diff -r 8b377df51209 -r fd5a9e5109f1 usr.sbin/syslogd/syslogd.c
--- a/usr.sbin/syslogd/syslogd.c        Mon Jun 20 08:22:43 2011 +0000
+++ b/usr.sbin/syslogd/syslogd.c        Mon Jun 20 08:27:15 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syslogd.c,v 1.103 2011/06/20 00:42:11 enami Exp $      */
+/*     $NetBSD: syslogd.c,v 1.104 2011/06/20 08:27:15 enami Exp $      */
 
 /*
  * Copyright (c) 1983, 1988, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)syslogd.c  8.3 (Berkeley) 4/4/94";
 #else
-__RCSID("$NetBSD: syslogd.c,v 1.103 2011/06/20 00:42:11 enami Exp $");
+__RCSID("$NetBSD: syslogd.c,v 1.104 2011/06/20 08:27:15 enami Exp $");
 #endif
 #endif /* not lint */
 
@@ -273,10 +273,11 @@
 
 /*
  * Global line buffer. Since we only process one event at a time,
- * a global one will do.
+ * a global one will do.  But for klog, we use own buffer so that
+ * partial line at the end of buffer can be deferred.
  */
-char *linebuf;
-size_t linebufsize, linebufoff;
+char *linebuf, *klog_linebuf;
+size_t linebufsize, klog_linebufoff;
 
 static const char *bindhostname = NULL;
 
@@ -457,6 +458,11 @@
                logerror("Couldn't allocate buffer");
                die(0, 0, NULL);
        }
+       if (!(klog_linebuf = malloc(linebufsize))) {
+               logerror("Couldn't allocate buffer for klog");
+               die(0, 0, NULL);
+       }
+
 
 #ifndef SUN_LEN
 #define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
@@ -662,16 +668,16 @@
 dispatch_read_klog(int fd, short event, void *ev)
 {
        ssize_t rv;
-       size_t resid = linebufsize - linebufoff;
+       size_t resid = linebufsize - klog_linebufoff;
 
        DPRINTF((D_CALL|D_EVENT), "Kernel log active (%d, %d, %p)"
                " with linebuf@%p, length %zu)\n", fd, event, ev,
-               linebuf, linebufsize);
-
-       rv = read(fd, &linebuf[linebufoff], resid - 1);
+               klog_linebuf, linebufsize);
+
+       rv = read(fd, &klog_linebuf[klog_linebufoff], resid - 1);
        if (rv > 0) {
-               linebuf[linebufoff + rv] = '\0';
-               printsys(linebuf);
+               klog_linebuf[klog_linebufoff + rv] = '\0';
+               printsys(klog_linebuf);
        } else if (rv < 0 && errno != EINTR) {
                /*
                 * /dev/klog has croaked.  Disable the event
@@ -1504,7 +1510,7 @@
        char *p, *q;
        struct buf_msg *buffer;
 
-       linebufoff = 0;
+       klog_linebufoff = 0;
        for (p = msg; *p != '\0'; ) {
                bool bsdsyslog = true;
 
@@ -1537,7 +1543,7 @@
                if (*q != '\0')
                        *q++ = '\0';
                else {
-                       memcpy(linebuf, p, linebufoff = q - p);
+                       memcpy(linebuf, p, klog_linebufoff = q - p);
                        break;
                }
 



Home | Main Index | Thread Index | Old Index