fix handling of long messages in last delta;
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 28 May 1988 02:42:03 +0000 (18:42 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Sat, 28 May 1988 02:42:03 +0000 (18:42 -0800)
use macros in syslog.h for manipulating encoded priorities

SCCS-vsn: usr.sbin/syslogd/syslogd.c 5.21

usr/src/usr.sbin/syslogd/syslogd.c

index bc3af59..321fc38 100644 (file)
@@ -37,7 +37,7 @@ static char sccsid[] = "@(#)syslogd.c 5.21 (Berkeley) %G%";
  */
 
 #define        MAXLINE         1024            /* maximum line length */
  */
 
 #define        MAXLINE         1024            /* maximum line length */
-#define        MAXSVLINE       100             /* maximum saved line length */
+#define        MAXSVLINE       120             /* maximum saved line length */
 #define DEFUPRI                (LOG_USER|LOG_NOTICE)
 #define DEFSPRI                (LOG_KERN|LOG_CRIT)
 #define TIMERINTVL     30              /* interval for checking flush, mark */
 #define DEFUPRI                (LOG_USER|LOG_NOTICE)
 #define DEFSPRI                (LOG_KERN|LOG_CRIT)
 #define TIMERINTVL     30              /* interval for checking flush, mark */
@@ -81,7 +81,7 @@ char  ctty[] = CTTY;
 #define MAXFNAME       200     /* max file pathname length */
 
 #define NOPRI          0x10    /* the "no priority" priority */
 #define MAXFNAME       200     /* max file pathname length */
 
 #define NOPRI          0x10    /* the "no priority" priority */
-#define        LOG_MARK        (LOG_NFACILITIES << 3)  /* mark "facility" */
+#define        LOG_MARK        LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */
 
 /*
  * Flags to logmsg().
 
 /*
  * Flags to logmsg().
@@ -377,13 +377,13 @@ printline(hname, msg)
                        pri = 10 * pri + (*p - '0');
                if (*p == '>')
                        ++p;
                        pri = 10 * pri + (*p - '0');
                if (*p == '>')
                        ++p;
-               if (pri <= 0 || pri >= (LOG_NFACILITIES << 3))
-                       pri = DEFUPRI;
        }
        }
+       if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
+               pri = DEFUPRI;
 
        /* don't allow users to log kernel messages */
 
        /* don't allow users to log kernel messages */
-       if ((pri & LOG_PRIMASK) == LOG_KERN)
-               pri |= LOG_USER;
+       if (LOG_FAC(pri) == LOG_KERN)
+               pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
 
        q = line;
 
 
        q = line;
 
@@ -424,12 +424,12 @@ printsys(msg)
                                pri = 10 * pri + (*p - '0');
                        if (*p == '>')
                                ++p;
                                pri = 10 * pri + (*p - '0');
                        if (*p == '>')
                                ++p;
-                       if (pri <= 0 || pri >= (LOG_NFACILITIES << 3))
-                               pri = DEFSPRI;
                } else {
                        /* kernel printf's come out on console */
                        flags |= IGN_CONS;
                }
                } else {
                        /* kernel printf's come out on console */
                        flags |= IGN_CONS;
                }
+               if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
+                       pri = DEFSPRI;
                q = lp;
                while (*p != '\0' && (c = *p++) != '\n' &&
                    q < &line[MAXLINE])
                q = lp;
                while (*p != '\0' && (c = *p++) != '\n' &&
                    q < &line[MAXLINE])
@@ -478,10 +478,11 @@ logmsg(pri, msg, from, flags)
        }
 
        /* extract facility and priority level */
        }
 
        /* extract facility and priority level */
-       fac = (pri & LOG_FACMASK) >> 3;
        if (flags & MARK)
                fac = LOG_NFACILITIES;
        if (flags & MARK)
                fac = LOG_NFACILITIES;
-       prilev = pri & LOG_PRIMASK;
+       else
+               fac = LOG_FAC(pri);
+       prilev = LOG_PRI(pri);
 
        /* log the message to the particular outputs */
        if (!Initialized) {
 
        /* log the message to the particular outputs */
        if (!Initialized) {
@@ -490,7 +491,7 @@ logmsg(pri, msg, from, flags)
 
                if (f->f_file >= 0) {
                        untty();
 
                if (f->f_file >= 0) {
                        untty();
-                       fprintlog(f, flags);
+                       fprintlog(f, flags, (char *)NULL);
                        (void) close(f->f_file);
                }
                (void) sigsetmask(omask);
                        (void) close(f->f_file);
                }
                (void) sigsetmask(omask);
@@ -501,6 +502,9 @@ logmsg(pri, msg, from, flags)
                if (f->f_pmask[fac] < prilev || f->f_pmask[fac] == NOPRI)
                        continue;
 
                if (f->f_pmask[fac] < prilev || f->f_pmask[fac] == NOPRI)
                        continue;
 
+               if (f->f_type == F_CONSOLE && (flags & IGN_CONS))
+                       continue;
+
                /* don't output marks to recently written files */
                if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2)
                        continue;
                /* don't output marks to recently written files */
                if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2)
                        continue;
@@ -523,34 +527,36 @@ logmsg(pri, msg, from, flags)
                         * in the future.
                         */
                        if (now > REPEATTIME(f)) {
                         * in the future.
                         */
                        if (now > REPEATTIME(f)) {
-                               fprintlog(f, flags);
+                               fprintlog(f, flags, (char *)NULL);
                                BACKOFF(f);
                        }
                } else {
                        /* new line, save it */
                                BACKOFF(f);
                        }
                } else {
                        /* new line, save it */
-                       if (f->f_prevcount) {
-                               fprintlog(f, 0);
-                               f->f_repeatcount = 0;
-                       }
+                       if (f->f_prevcount)
+                               fprintlog(f, 0, (char *)NULL);
+                       f->f_repeatcount = 0;
                        (void) strncpy(f->f_lasttime, timestamp, 15);
                        (void) strncpy(f->f_lasttime, timestamp, 15);
-                       if (msglen < MAXSVLINE && (f->f_type != F_CONSOLE ||
-                           (flags & IGN_CONS) == 0)) {
+                       (void) strncpy(f->f_prevhost, from,
+                                       sizeof(f->f_prevhost));
+                       if (msglen < MAXSVLINE) {
                                f->f_prevlen = msglen;
                                f->f_prevpri = pri;
                                (void) strcpy(f->f_prevline, msg);
                                f->f_prevlen = msglen;
                                f->f_prevpri = pri;
                                (void) strcpy(f->f_prevline, msg);
-                               (void) strncpy(f->f_prevhost, from,
-                                       sizeof(f->f_prevhost));
-                       } else
+                               fprintlog(f, flags, (char *)NULL);
+                       } else {
                                f->f_prevline[0] = 0;
                                f->f_prevline[0] = 0;
-                       fprintlog(f, flags);
+                               f->f_prevlen = 0;
+                               fprintlog(f, flags, msg);
+                       }
                }
        }
        (void) sigsetmask(omask);
 }
 
                }
        }
        (void) sigsetmask(omask);
 }
 
-fprintlog(f, flags)
+fprintlog(f, flags, msg)
        register struct filed *f;
        int flags;
        register struct filed *f;
        int flags;
+       char *msg;
 {
        struct iovec iov[6];
        register struct iovec *v = iov;
 {
        struct iovec iov[6];
        register struct iovec *v = iov;
@@ -570,7 +576,10 @@ fprintlog(f, flags)
        v->iov_base = " ";
        v->iov_len = 1;
        v++;
        v->iov_base = " ";
        v->iov_len = 1;
        v++;
-       if (f->f_prevcount > 1) {
+       if (msg) {
+               v->iov_base = msg;
+               v->iov_len = strlen(msg);
+       } else if (f->f_prevcount > 1) {
                (void) sprintf(repbuf, "last message repeated %d times",
                    f->f_prevcount);
                v->iov_base = repbuf;
                (void) sprintf(repbuf, "last message repeated %d times",
                    f->f_prevcount);
                v->iov_base = repbuf;
@@ -815,7 +824,7 @@ domark()
                        dprintf("flush %s: repeated %d times, %d sec.\n",
                            TypeNames[f->f_type], f->f_prevcount,
                            repeatinterval[f->f_repeatcount]);
                        dprintf("flush %s: repeated %d times, %d sec.\n",
                            TypeNames[f->f_type], f->f_prevcount,
                            repeatinterval[f->f_repeatcount]);
-                       fprintlog(f, 0);
+                       fprintlog(f, 0, (char *)NULL);
                        BACKOFF(f);
                }
        }
                        BACKOFF(f);
                }
        }
@@ -849,7 +858,7 @@ die(sig)
        for (f = Files; f != NULL; f = f->f_next) {
                /* flush any pending output */
                if (f->f_prevcount)
        for (f = Files; f != NULL; f = f->f_next) {
                /* flush any pending output */
                if (f->f_prevcount)
-                       fprintlog(f, 0);
+                       fprintlog(f, 0, (char *)NULL);
        }
        if (sig) {
                dprintf("syslogd: exiting on signal %d\n", sig);
        }
        if (sig) {
                dprintf("syslogd: exiting on signal %d\n", sig);
@@ -882,7 +891,7 @@ init()
        for (f = Files; f != NULL; f = next) {
                /* flush any pending output */
                if (f->f_prevcount)
        for (f = Files; f != NULL; f = next) {
                /* flush any pending output */
                if (f->f_prevcount)
-                       fprintlog(f, 0);
+                       fprintlog(f, 0, (char *)NULL);
 
                switch (f->f_type) {
                  case F_FILE:
 
                switch (f->f_type) {
                  case F_FILE: