syslogd/sysklogd-1.4.1-showpri.patch

179 lines
5.5 KiB
Diff

---
sysklogd.8 | 23 +++++++++++++++++++++++
syslogd.c | 54 ++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 61 insertions(+), 16 deletions(-)
--- sysklogd.8
+++ sysklogd.8 2022-10-14 13:33:28.961599858 +0000
@@ -31,6 +31,7 @@ sysklogd \- Linux system logging utiliti
]
.RB [ " \-t " ]
.RB [ " \-v " ]
+.RB [ " \-S " ]
.SH DESCRIPTION
.B Sysklogd
provides two system utilities which provide support for
@@ -158,6 +159,28 @@ loghost.
.TP
.B "\-v"
Print version and exit.
+.TP
+.B "\-S"
+Insert a special code before the hostname in each message to indicate the
+message's priority and facility. Having the priority and facility encoded in
+each message allows a log analyzer program to monitor a single file
+containing all logged messages. The analyzer program can parse the
+priority/facility code for each logged message to determine if it is
+of interest.
+
+The priority/facility code takes the form of a priority number
+followed by a letter that indicates the facility. The priority number
+can range from 0 to 7. The facility letter can range from 'A' to 'Y',
+where 'A' corresponds to facility number zero (LOG_KERN), 'B'
+corresponds to facility 1 (LOG_USER), etc.
+See /usr/include/sys/syslog.h for a list of priority and LOG_xxx codes.
+
+Example:
+
+ Jun 27 19:22:20 5Q:silence test[1966]: testing
+
+The above message contains a priority/facility code of '5Q', which breaks
+down to a priority of 5 (LOG_NOTICE) and a facility of 16 (LOG_LOCAL0).
.SH SIGNALS
.B Syslogd
reacts to a set of signals. You may easily send a signal to
--- syslogd.c
+++ syslogd.c 2022-10-14 13:27:33.395957312 +0000
@@ -649,6 +649,9 @@ int funix[MAXFUNIX] = { -1, };
#define SYNC_FILE 0x002 /* do fsync on file after printing */
#define ADDDATE 0x004 /* add a date to the message */
#define MARK 0x008 /* this message is a mark */
+#define SHOWPRI 0x010 /* Will craft priFac before hostname */
+
+int showpri = 0; /* Are we showing priority in message ? Default: no */
/*
* This table contains plain text for h_errno errors used by the
@@ -828,7 +831,7 @@ void printchopped(const char *hname, cha
void printline(const char *hname, char *msg);
void printsys(char *msg);
void logmsg(int pri, char *msg, const char *from, int flags);
-void fprintlog(register struct filed *f, char *from, int flags, char *msg);
+void fprintlog(register struct filed *f, char *from, int flags, char *msg, ...);
void endtty();
void wallmsg(register struct filed *f, struct iovec *iov);
void reapchild();
@@ -920,7 +923,7 @@ int main(argc, argv)
funix[i] = -1;
}
- while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:tv")) != EOF)
+ while ((ch = getopt(argc, argv, "a:dhf:l:m:np:rs:tvS")) != EOF)
switch((char)ch) {
case 'a':
if (nfunix < MAXFUNIX)
@@ -972,6 +975,9 @@ int main(argc, argv)
case 'v':
printf("syslogd %s.%s\n", VERSION, PATCHLEVEL);
exit (0);
+ case 'S':
+ showpri++;
+ break;
case '?':
default:
usage();
@@ -1287,7 +1293,7 @@ int main(argc, argv)
int usage()
{
- fprintf(stderr, "usage: syslogd [-drvh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \
+ fprintf(stderr, "usage: syslogd [-drvSh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \
" [-s domainlist] [-f conffile]\n");
exit(1);
}
@@ -1755,7 +1761,7 @@ void logmsg(pri, msg, from, flags)
if (f->f_file >= 0) {
untty();
- fprintlog(f, (char *)from, flags, msg);
+ fprintlog(f, (char *)from, flags|SHOWPRI, msg, prilev, fac);
(void) close(f->f_file);
f->f_file = -1;
}
@@ -1805,13 +1811,13 @@ void logmsg(pri, msg, from, flags)
* in the future.
*/
if (now > REPEATTIME(f)) {
- fprintlog(f, (char *)from, flags, (char *)NULL);
+ fprintlog(f, (char *)from, flags|SHOWPRI, (char *)NULL, prilev, fac);
BACKOFF(f);
}
} else {
/* new line, save it */
if (f->f_prevcount)
- fprintlog(f, (char *)from, 0, (char *)NULL);
+ fprintlog(f, (char *)from, 0|SHOWPRI, (char *)NULL, prilev, fac);
f->f_prevpri = pri;
f->f_repeatcount = 0;
(void) strncpy(f->f_lasttime, timestamp, 15);
@@ -1820,11 +1826,11 @@ void logmsg(pri, msg, from, flags)
if (msglen < MAXSVLINE) {
f->f_prevlen = msglen;
(void) strcpy(f->f_prevline, msg);
- fprintlog(f, (char *)from, flags, (char *)NULL);
+ fprintlog(f, (char *)from, flags|SHOWPRI, (char *)NULL, prilev, fac);
} else {
f->f_prevline[0] = 0;
f->f_prevlen = 0;
- fprintlog(f, (char *)from, flags, msg);
+ fprintlog(f, (char *)from, flags|SHOWPRI, msg, prilev, fac);
}
}
}
@@ -1840,11 +1846,7 @@ void logmsg(pri, msg, from, flags)
} /* balance parentheses for emacs */
#endif
-void fprintlog(f, from, flags, msg)
- register struct filed *f;
- char *from;
- int flags;
- char *msg;
+void fprintlog(register struct filed *f, char *from, int flags,char *msg, ...)
{
struct iovec iov[6];
register struct iovec *v = iov;
@@ -1865,9 +1867,29 @@ void fprintlog(f, from, flags, msg)
v->iov_base = f->f_lasttime;
v->iov_len = 15;
v++;
- v->iov_base = " ";
- v->iov_len = 1;
- v++;
+
+ if(showpri && (flags & SHOWPRI) ) {
+ va_list ap;
+ int prilev;
+ int fac;
+ char prilev_char[5];
+ const char fac_string[LOG_NFACILITIES+1]="ABCDEFGHIJKLMNOPQRSTUVWXY";
+
+ va_start(ap,msg);
+ prilev=va_arg(ap,int);
+ fac=va_arg(ap,int);
+ va_end(ap);
+ sprintf(prilev_char, " %1d%c:", prilev, fac_string[fac]);
+ v->iov_base = prilev_char;
+ v->iov_len = 4;
+ v++;
+ }
+ else {
+ v->iov_base = " ";
+ v->iov_len = 1;
+ v++;
+ }
+
v->iov_base = f->f_prevhost;
v->iov_len = strlen(v->iov_base);
v++;