[syslog-ng] patch for $PID support
Roberto Nibali
ratz at tac.ch
Thu Oct 6 13:27:16 CEST 2005
> Hurray for insomnia!
Feels good, doesn't it.
> I have implemented $PID macro support in syslog-ng 1.6.8, and have
> tested it out on gentoo linux.
>
> http://www.ices.utexas.edu/~cell/gentoo/syslog-ng/
Could you attach the patch next time, so it's easier to comment?
>diff -urN syslog-ng-1.6.8.orig/src/log.c syslog-ng-1.6.8/src/log.c
>--- syslog-ng-1.6.8.orig/src/log.c 2004-01-13 12:08:02.000000000 >-0600
>+++ syslog-ng-1.6.8/src/log.c 2005-10-06 01:14:35.000000000 -0500
>@@ -223,6 +223,31 @@
> if (left) {
> lm->program = c_format_cstring("%s",
> oldleft - left, oldsrc);
>+
>+ /* Try to extract a pid */
>+ if (*src == '[') {
>+ unsigned char *pid_start = NULL;
>+ unsigned char *pid_end = NULL;
>+ src++;
>+ left--;
>+
>+ if (left && *src >= '0' && *src <= '9') {
Consider isdigit(3)
>+ pid_start = src;
>+ pid_end = src;
>+ src++;
>+ left--;
>+ while (left && *src >= '0' && *src <= '9') {
Consider isdigit(3) or parse up to *src == ']'
>+ pid_end = src;
>+ src++;
>+ left--;
>+ }
>+ }
>+
>+ if (pid_start != NULL && pid_end != NULL &&
>+ pid_end - pid_start > 0) {
>+ lm->pid = c_format_cstring("%s", >pid_end - pid_start,
pid_start);
>+ }
>+ }
> }
>
> src = oldsrc;
>@@ -278,6 +303,7 @@
> if (--msg->use_cnt == 0) {
> ol_string_free(msg->host);
> ol_string_free(msg->program);
>+ ol_string_free(msg->pid);
> ol_string_free(msg->date);
> ol_string_free(msg->msg);
> ol_string_free(msg->host_from);
>@@ -304,6 +330,7 @@
> NEW_SPACE(self);
> self->msg = c_format_cstring("syslog-ng[%i]: %s", getpid(), >length,
data);
> self->program = c_format_cstring("syslog-ng");
>+ self->pid = c_format_cstring("%i", getpid());
This is wrong! You most certainly don't want to add the pid of the
receiving syslog-ng process.
> self->stamp = self->recvd = time(NULL);
> self->pri = pri;
> self->flags = LF_INTERNAL;
>diff -urN syslog-ng-1.6.8.orig/src/log.h syslog-ng-1.6.8/src/log.h
>--- syslog-ng-1.6.8.orig/src/log.h 2003-01-08 03:31:37.000000000 >-0600
>+++ syslog-ng-1.6.8/src/log.h 2005-10-06 00:49:45.000000000 -0500
>@@ -46,6 +46,7 @@
> struct ol_string *msg;
> struct ol_string *date;
> struct ol_string *program;
>+ struct ol_string *pid;
Whitespace/tab damage.
The rest seems ok from a quick glance.
Good night :),
Roberto Nibali, ratz
--
-------------------------------------------------------------
addr://Kasinostrasse 30, CH-5001 Aarau tel://++41 62 823 9355
http://www.terreactive.com fax://++41 62 823 9356
-------------------------------------------------------------
terreActive AG Wir sichern Ihren Erfolg
-------------------------------------------------------------
More information about the syslog-ng
mailing list