use macros in syslog.h for manipulating encoded priorities
SCCS-vsn: usr.sbin/syslogd/syslogd.c 5.21
*/
#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 */
#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" */
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));
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])
}
/* 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) {
if (f->f_file >= 0) {
untty();
if (f->f_file >= 0) {
untty();
+ fprintlog(f, flags, (char *)NULL);
(void) close(f->f_file);
}
(void) sigsetmask(omask);
(void) close(f->f_file);
}
(void) sigsetmask(omask);
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;
* in the future.
*/
if (now > REPEATTIME(f)) {
* in the future.
*/
if (now > REPEATTIME(f)) {
+ 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_prevlen = 0;
+ fprintlog(f, flags, msg);
+ }
}
}
(void) sigsetmask(omask);
}
}
}
(void) sigsetmask(omask);
}
+fprintlog(f, flags, msg)
register struct filed *f;
int flags;
register struct filed *f;
int flags;
{
struct iovec iov[6];
register struct iovec *v = iov;
{
struct iovec iov[6];
register struct iovec *v = iov;
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;
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, (char *)NULL);
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, (char *)NULL);
}
if (sig) {
dprintf("syslogd: exiting on signal %d\n", sig);
}
if (sig) {
dprintf("syslogd: exiting on signal %d\n", sig);
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, (char *)NULL);
switch (f->f_type) {
case F_FILE:
switch (f->f_type) {
case F_FILE: