syslogd/sysklogd-1.4.1-showpri.patch
Marcus Meissner 53bbc01f78 Accepting request 24994 from home:elvigia:branches:Base:System
Copy from home:elvigia:branches:Base:System/syslogd via accept of submit request 24994 revision 2.
Request was accepted with message:
ok

OBS-URL: https://build.opensuse.org/request/show/24994
OBS-URL: https://build.opensuse.org/package/show/Base:System/syslogd?expand=0&rev=10
2009-11-25 15:23:34 +00:00

190 lines
5.7 KiB
Diff

Index: sysklogd.8
===================================================================
--- sysklogd.8.orig 2009-11-24 18:12:52.655464000 +0100
+++ sysklogd.8 2009-11-24 18:12:55.314207000 +0100
@@ -31,6 +31,7 @@ sysklogd \- Linux system logging utiliti
]
.RB [ " \-t " ]
.RB [ " \-v " ]
+.RB [ " \-S " ]
.LP
.SH DESCRIPTION
.B Sysklogd
@@ -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).
.LP
.SH SIGNALS
.B Syslogd
Index: syslogd.c
===================================================================
--- syslogd.c.orig 2009-11-24 18:12:55.083205000 +0100
+++ syslogd.c 2009-11-24 18:12:55.320216000 +0100
@@ -594,6 +594,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
@@ -772,7 +775,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();
@@ -861,7 +864,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)
@@ -913,6 +916,9 @@ int main(argc, argv)
case 'v':
printf("syslogd %s.%s\n", VERSION, PATCHLEVEL);
exit (0);
+ case 'S':
+ showpri++;
+ break;
case '?':
default:
usage();
@@ -1151,9 +1157,9 @@ int main(argc, argv)
dprintf("UNIX socket error: %d = %s.\n", \
errno, strerror(errno));
logerror("recvfrom UNIX");
- }
- }
}
+ }
+ }
#endif
#ifdef SYSLOG_INET
@@ -1221,7 +1227,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);
}
@@ -1660,7 +1666,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;
}
@@ -1706,13 +1712,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);
@@ -1721,11 +1727,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);
}
}
}
@@ -1737,11 +1743,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;
@@ -1762,9 +1764,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++;