rpms/sysklogd/devel sysklogd-1.4.2rh-dispatcher.patch, NONE, 1.1 sysklogd.spec, 1.53, 1.54

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Mon Apr 16 18:15:28 UTC 2007


Author: pvrabec

Update of /cvs/dist/rpms/sysklogd/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv11935

Modified Files:
	sysklogd.spec 
Added Files:
	sysklogd-1.4.2rh-dispatcher.patch 
Log Message:
sysklogd provides new realtime interface (#236356)


sysklogd-1.4.2rh-dispatcher.patch:
 Makefile            |   10 +-
 sysklogd-dispatch.c |  185 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sysklogd-dispatch.h |   64 +++++++++++++++++
 sysklogd.8          |   24 ++++++
 syslogd.c           |   48 ++++++++++++-
 5 files changed, 323 insertions(+), 8 deletions(-)

--- NEW FILE sysklogd-1.4.2rh-dispatcher.patch ---
--- sysklogd-1.4.2rh/sysklogd.8.dispatcher	2007-04-16 19:27:44.000000000 +0200
+++ sysklogd-1.4.2rh/sysklogd.8	2007-04-16 19:27:44.000000000 +0200
@@ -30,6 +30,9 @@
 .RB [ " \-s "
 .I domainlist
 ]
+.RB [ " \-D "
+.I dispatcher
+]
 .RB [ " \-v " ]
 .RB [ " \-x " ]
 .LP
@@ -178,6 +181,14 @@
 once, the names of the facility and priority are logged with each
 locally-written message.
 .TP
+.BI "\-D " "dispatcher"
+The syslogd daemon will start up a dispatcher program and open
+standard input to the socketpair used to pass events. So, the 
+dispatcher only needs to read stdin. Because IPC communication 
+buffers have a limited size, it must read the events as fast 
+as possible. The syslogd send SIGTERM to indicate that the 
+dispatcher should exit.
+.TP
 .B "\-v"
 Print version and exit.
 .TP
@@ -444,6 +455,19 @@
 	kern.=debug			|/usr/adm/debug
 .fi
 .LP
+.SH OUTPUT TO DISPATCHER
+If you run syslogd with the
+.B \-D 
+option, you can route your messages 
+to dispatcher process. To specify messages, which go to dispatcher, 
+you use "!dispatcher" directive. 
+.IP
+Following configuration routes info messages to a dispatcher process:
+.IP
+.nf
+	*.info				!dispatcher
+.fi
+.LP
 .SH INSTALLATION CONCERNS
 There is probably one important consideration when installing this
 version of syslogd.  This version of syslogd is dependent on proper
--- /dev/null	2007-04-11 16:01:52.461576228 +0200
+++ sysklogd-1.4.2rh/sysklogd-dispatch.h	2007-04-16 19:27:44.000000000 +0200
@@ -0,0 +1,64 @@
+/* sysklogd-dispatch.h -- 
+ * Copyright 2007 Red Hat Inc., Durham, North Carolina.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Steve Grubb <sgrubb at redhat.com>
+ *   Peter Vrabec <pvrabec at redhat.com>
+ * 
+ */
+
+#ifndef SYSKLOGD_DISPATCH_H
+#define SYSKLOGD_DISPATCH_H
+
+
+typedef enum { QOS_NON_BLOCKING, QOS_BLOCKING } qos_t;
+
+struct daemon_conf
+{
+        char * dispatcher;
+        qos_t qos;              /* use blocking/non-blocking sockets */
+};
+
+/* Sysklogd protocol #1 contains only one type of reply message
+   and that is standart message. */
+#define SYSKLOGD_PROTOCOL_VER	1
+#define MAXLINE			1024 /* Should be same MAXLINE as in syslogd.c */
+typedef enum { STD_MESS } mess_t;   
+
+struct sysklogd_reply {
+        mess_t			type;
+        int			len;
+	union {
+	       	const char		*message;
+	};
+};
+
+struct sysklogd_dispatcher_header {
+        int        ver;    /* The version of this protocol */
+        int        hlen;   /* Header length */
+        mess_t     type;   /* Message type */
+        int        size;   /* Size of data following the header */
+};
+
+
+int init_dispatcher(const struct daemon_conf *config);
+void shutdown_dispatcher(void);
+void reconfigure_dispatcher(void);
+void dispatch_event(const struct sysklogd_reply *rep);
+
+#endif
--- sysklogd-1.4.2rh/Makefile.dispatcher	2007-02-26 10:46:08.000000000 +0100
+++ sysklogd-1.4.2rh/Makefile	2007-04-16 19:30:48.000000000 +0200
@@ -10,6 +10,7 @@
 INSTALL = /usr/bin/install
 BINDIR = $(TOPDIR)/sbin
 MANDIR = $(TOPDIR)/usr/man
+INCLUDEDIR = $(TOPDIR)/usr/include
 
 # There is one report that under an all ELF system there may be a need to
 # explicilty link with libresolv.a.  If linking syslogd fails you may wish
@@ -57,10 +58,10 @@
 
 test: syslog_tst ksym oops_test tsyslogd
 
-install: install_man install_exec
+install: install_man install_exec install_include
 
-syslogd: syslogd.o pidfile.o
-	${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o ${LIBS}
+syslogd: syslogd.o pidfile.o sysklogd-dispatch.o
+	${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o sysklogd-dispatch.o ${LIBS}
 
 klogd:	klogd.o syslog.o pidfile.o ksym.o ksym_mod.o
 	${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o \
@@ -121,6 +122,9 @@
 	${INSTALL} -m 644 syslog.conf.5 ${MANDIR}/man5/syslog.conf.5
 	${INSTALL} -m 644 klogd.8 ${MANDIR}/man8/klogd.8
 
+install_include:
+	${INSTALL} -m 644 sysklogd-dispatch.h ${INCLUDEDIR}/sysklogd/sysklogd-dispatch.h
+
 
 ## Red Hat specific additions
 
--- /dev/null	2007-04-11 16:01:52.461576228 +0200
+++ sysklogd-1.4.2rh/sysklogd-dispatch.c	2007-04-16 19:27:44.000000000 +0200
@@ -0,0 +1,185 @@
+/* sysklogd-dispatch.c -- 
+ * Copyright 2007 Red Hat Inc., Durham, North Carolina.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Authors:
+ *   Steve Grubb <sgrubb at redhat.com>
+ *   Junji Kanemaru <junji.kanemaru at linuon.com>
+ *   Peter Vrabec <pvrabec at redhat.com>
+ */
+
+#include <unistd.h>
+#include <sys/uio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include "sysklogd-dispatch.h"
+
+/* This is the communications channel between sysklogd & the dispatcher */
+static int disp_pipe[2] = {-1, -1};
+static pid_t pid = 0;
+static int n_errs = 0;
+#define REPORT_LIMIT 10
+
+/* set_flags: to set flags to file desc */
+static int set_flags(int fn, int flags)
+{
+	int fl;
+
+	if ((fl = fcntl(fn, F_GETFL, 0)) < 0) {
+		fprintf(stderr, "fcntl failed. Cannot get flags (%s)\n", 
+			strerror(errno));
+		return fl;
+	}
+
+	fl |= flags;
+
+	return fcntl(fn, F_SETFL, fl);
+}
+
+/* This function returns 1 on error & 0 on success */
+int init_dispatcher(const struct daemon_conf *config)
+{
+	if (config->dispatcher == NULL) 
+		return 0;
+
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, disp_pipe)) {
+		fprintf(stderr, "Failed creating disp_pipe\n");
+		return 1;
+	}
+
+	/* Make both disp_pipe non-blocking */
+	if (config->qos == QOS_NON_BLOCKING) {
+		if (set_flags(disp_pipe[0], O_NONBLOCK) < 0 ||
+			set_flags(disp_pipe[1], O_NONBLOCK) < 0) {
+			fprintf(stderr, "Failed to set O_NONBLOCK flag\n");
+			return 1;
+		}
+	}
+
+	// do the fork
+	pid = fork();
+	switch(pid) {
+		case 0:	// child
+			dup2(disp_pipe[0], 0);
+			close(disp_pipe[0]);
+			close(disp_pipe[1]);
+			setsid();
+			execl(config->dispatcher, config->dispatcher, NULL);
+			fprintf(stderr, "exec() failed\n");
+			exit(1);
+			break;
+		case -1:	// error
+			return 1;
+			break;
+		default:	// parent
+			close(disp_pipe[0]);
+			disp_pipe[0] = -1;
+			/* Avoid leaking this */
+			if (fcntl(disp_pipe[1], F_SETFD, FD_CLOEXEC) < 0) {
+				fprintf(stderr,
+					"Failed to set FD_CLOEXEC flag\n");
+				return 1;
+			}
+			fprintf(stderr, "Started dispatcher: %s pid: %u\n",
+					config->dispatcher, pid);
+			break;
+	}
+
+	return 0;
+}
+
+void shutdown_dispatcher(void)
+{
+	// kill child
+	if (pid)
+		kill(pid, SIGTERM);
+	// wait for term
+	// if not in time, send sigkill
+	pid = 0;
+
+	// cleanup comm pipe
+	if (disp_pipe[0] >= 0) {
+		close(disp_pipe[0]);
+		disp_pipe[0] = -1;
+	}
+	if (disp_pipe[1] >= 0) {
+		close(disp_pipe[1]);
+		disp_pipe[1] = -1;
+	}
+}
+
+void reconfigure_dispatcher(void)
+{
+	// signal child
+	if (pid)
+		kill(pid, SIGHUP);
+}
+
+void dispatch_event(const struct sysklogd_reply *rep)
+{
+	int rc, count = 0;
+	struct iovec vec[2];
+	struct sysklogd_dispatcher_header hdr;
+
+	if (disp_pipe[1] == -1)
+		return;
+
+	hdr.ver = SYSKLOGD_PROTOCOL_VER; /* Hard-coded to current protocol */
+	hdr.hlen = sizeof(struct sysklogd_dispatcher_header);
+	hdr.type = rep->type;
+	hdr.size = rep->len;
+
+	vec[0].iov_base = (void*)&hdr;
+	vec[0].iov_len = sizeof(hdr);
+	vec[1].iov_base = (void*)rep->message;
+	vec[1].iov_len = rep->len;
+
+	do {
+		rc = writev(disp_pipe[1], vec, 2);
+	} while (rc < 0 && errno == EAGAIN && count++ < 10);
+
+	// close pipe if no child or peer has been lost
+	if (rc <= 0) {
+		if (errno == EPIPE) {
+			shutdown_dispatcher();
+			n_errs = 0;
+		} else {
+			if (n_errs <= REPORT_LIMIT) {
+				fprintf(stderr, 
+					"dispatch err (%s) event lost\n",
+					errno == EAGAIN ? "pipe full" :
+					strerror(errno));
+				n_errs++;
+			}
+			if (n_errs == REPORT_LIMIT) {
+				fprintf(stderr, 
+					"dispatch error reporting limit\n"
+					" reached - ending report"
+					" notification.");
+				n_errs++;
+			}
+		}
+	} else
+		n_errs = 0;
+}
--- sysklogd-1.4.2rh/syslogd.c.dispatcher	2007-04-16 19:27:44.000000000 +0200
+++ sysklogd-1.4.2rh/syslogd.c	2007-04-16 19:27:44.000000000 +0200
@@ -507,6 +507,8 @@
 #endif
 #include "version.h"
 
+#include "sysklogd-dispatch.h"
+
 #if defined(__linux__)
 #include <paths.h>
 #endif
@@ -572,6 +574,8 @@
 static int alarm_signal = 0;
 static int exit_on_signal = 0;
 
+struct daemon_conf disp =  { NULL, QOS_NON_BLOCKING };
+
 #define MAXFUNIX	20
 
 int nfunix = 1;
@@ -674,10 +678,11 @@
 #define F_FORW_SUSP	7		/* suspended host forwarding */
 #define F_FORW_UNKN	8		/* unknown host forwarding */
 #define F_PIPE		9		/* named pipe */
+#define F_DISP		10		/* named pipe */
 char	*TypeNames[] = {
 	"UNUSED",	"FILE",		"TTY",		"CONSOLE",
 	"FORW",		"USERS",	"WALL",		"FORW(SUSPENDED)",
-	"FORW(UNKNOWN)", "PIPE"
+	"FORW(UNKNOWN)", "PIPE",	"DISP"
 };
 
 struct	filed *Files = (struct filed *) 0;
@@ -859,7 +864,7 @@
 		funix[i]  = -1;
 	}
 
-	while ((ch = getopt(argc, argv, "46Aa:dhf:l:m:np:rSs:vx")) != EOF)
+	while ((ch = getopt(argc, argv, "46Aa:dhf:D:l:m:np:rSs:vx")) != EOF)
 		switch((char)ch) {
                 case '4':
                               family = PF_INET;
@@ -881,6 +886,9 @@
 		case 'd':		/* debug */
 			Debug = 1;
 			break;
+		case 'D':		/* dispatcher */
+			disp.dispatcher = optarg;
+			break;
 		case 'f':		/* configuration file */
 			ConfFile = optarg;
 			break;
@@ -1067,6 +1075,15 @@
 	    parts[i] = (char *) 0;
 
 	dprintf("Starting.\n");
+
+	if( disp.dispatcher != NULL ) {
+		dprintf("Dispatcher initialisation.\n");
+	        if( init_dispatcher(&disp) == 1) {
+			dprintf("Dispatcher initialisation FAIL.\n");
+			die(0);
+		}
+        }
+
 	init();
 #ifndef TESTING
 	if ( Debug )
@@ -1249,7 +1266,7 @@
 int usage()
 {
 	fprintf(stderr, "usage: syslogd [-46AdiIrvxh] [-l hostlist] [-m markinterval] [-n] [-p path]\n" \
-		" [-s domainlist] [-f conffile]\n");
+		" [-s domainlist] [-D dispatcher] [-f conffile]\n");
 	exit(1);
 }
 
@@ -1767,6 +1784,7 @@
 	time_t fwd_suspend;
 	struct addrinfo *saddr;
 #endif
+	struct sysklogd_reply reply;
 
 	dprintf("Called fprintlog, ");
 
@@ -2012,7 +2030,19 @@
 		} else if (f->f_flags & SYNC_FILE)
 			(void) fsync(f->f_file);
 		break;
-
+	case F_DISP:
+		f->f_time = now;
+		dprintf("\n");
+                v->iov_base = "";
+                v->iov_len = 0;
+		(void) snprintf(line, sizeof(line), "%s%s%s%s%s%s%s\n", (char *) iov[0].iov_base, 
+				(char *) iov[1].iov_base, (char *) iov[2].iov_base, (char *) iov[3].iov_base,
+         			(char *) iov[4].iov_base, (char *) iov[5].iov_base, (char *) iov[6].iov_base);
+                reply.type = STD_MESS;
+		reply.message = line;
+	        reply.len = strlen(reply.message);
+	        dispatch_event(&reply);
+		break;
 	case F_USERS:
 	case F_WALL:
 		f->f_time = now;
@@ -2868,7 +2898,15 @@
 		if (strcmp(p, ctty) == 0)
 			f->f_type = F_CONSOLE;
 		break;
-
+	case '!':
+		if( !strncmp(++p, "dispatcher", 10) ) {
+			dprintf ("sending to: %s\n", disp.dispatcher);
+			f->f_type = F_DISP;
+		}
+		else {
+			dprintf ("\"!\" is not followed by \"dispatcher\"\n");
+		}
+		break;
 	case '*':
 		dprintf ("write-all\n");
 		f->f_type = F_WALL;


Index: sysklogd.spec
===================================================================
RCS file: /cvs/dist/rpms/sysklogd/devel/sysklogd.spec,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- sysklogd.spec	11 Apr 2007 15:52:41 -0000	1.53
+++ sysklogd.spec	16 Apr 2007 18:15:26 -0000	1.54
@@ -1,7 +1,7 @@
 Summary: System logging and kernel message trapping daemons
 Name: sysklogd
 Version: 1.4.2
-Release: 4%{?dist}
+Release: 5%{?dist}
 License: GPL
 Group: System Environment/Daemons
 URL: http://www.infodrom.org/projects/sysklogd/
@@ -15,6 +15,7 @@
 Source: sysklogd-%{version}rh.tar.gz
 Patch1: sysklogd-1.4.2rh.timezone.patch
 Patch2: sysklogd-1.4.2rh-includeFacPri.patch
+Patch3: sysklogd-1.4.2rh-dispatcher.patch
 Conflicts: logrotate < 3.5.2
 Requires: logrotate
 Requires: bash >= 2.0
@@ -30,6 +31,14 @@
 daemons (background processes) and log system messages to different
 places, like sendmail logs, security logs, error logs, etc.
 
+%package devel
+Group: Development/Libraries
+Summary: Development tools for the sysklogd daemon
+
+%description devel
+The sysklogd-devel package contains the header file, which provides 
+interface for dispatcher extension.
+
 %prep
 %setup -q -n sysklogd-%{version}rh
 %ifarch s390 s390x
@@ -37,13 +46,14 @@
 %endif
 %patch1 -p1 -b .timezone
 %patch2 -p1 -b .includeFacPri
+%patch3 -p1 -b .dispatcher
 
 %build
 make %{?_smp_mflags}
 
 %install
 rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT{/etc,%{_bindir},%{_mandir}/man{5,8},/usr/sbin}
+mkdir -p $RPM_BUILD_ROOT{/etc,%{_bindir},%{_mandir}/man{5,8},/usr/sbin,%{_includedir}/sysklogd}
 mkdir -p $RPM_BUILD_ROOT/sbin
 
 make install TOPDIR=$RPM_BUILD_ROOT MANDIR=$RPM_BUILD_ROOT%{_mandir} \
@@ -102,7 +112,15 @@
 /sbin/*
 %{_mandir}/*/*
 
+%files devel
+%defattr(-,root,root)
+%dir %{_includedir}/sysklogd
+%{_includedir}/sysklogd/sysklogd-dispatch.h
+
 %changelog
+* Mon Apr 16 2007 Peter Vrabec <pvrabec at redhat.com> 1.4.2-5
+- sysklogd provides new realtime interface (#236356) 
+
 * Wed Apr 11 2007 Peter Vrabec <pvrabec at redhat.com> 1.4.2-4
 - some fixes of previous release (#223573)
 




More information about the fedora-cvs-commits mailing list