[netfilter-cvslog] r6300 - branches/ulog/ulogd2/src

laforge at netfilter.org laforge at netfilter.org
Thu Dec 8 08:25:22 CET 2005


Author: laforge at netfilter.org
Date: 2005-12-08 08:25:17 +0100 (Thu, 08 Dec 2005)
New Revision: 6300

Modified:
   branches/ulog/ulogd2/src/ulogd.c
Log:
fix/cleanup logfile handling


Modified: branches/ulog/ulogd2/src/ulogd.c
===================================================================
--- branches/ulog/ulogd2/src/ulogd.c	2005-12-08 07:24:50 UTC (rev 6299)
+++ branches/ulog/ulogd2/src/ulogd.c	2005-12-08 07:25:17 UTC (rev 6300)
@@ -86,24 +86,27 @@
 /* global variables */
 static FILE *logfile = NULL;		/* logfile pointer */
 static char *ulogd_configfile = ULOGD_CONFIGFILE;
-static FILE *syslog_dummy;
+static char *ulogd_logfile = ULOGD_LOGFILE_DEFAULT;
+static FILE syslog_dummy;
 
 /* linked list for all registered plugins */
 static LLIST_HEAD(ulogd_plugins);
 static LLIST_HEAD(ulogd_pi_stacks);
 
 
-static int load_plugin(char *file);
-static int create_stack(char *file);
+static int load_plugin(const char *file);
+static int create_stack(const char *file);
+static int logfile_open(const char *name);
 
 static struct config_keyset ulogd_kset = {
 	.num_ces = 4,
 	.ces = {
 		{
 			.key = "logfile",
-			.type = CONFIG_TYPE_STRING, 
+			.type = CONFIG_TYPE_CALLBACK,
 			.options = CONFIG_OPT_NONE,
 			.u.string = ULOGD_LOGFILE_DEFAULT,
+			.u.parser = &logfile_open,
 		},
 		{
 			.key = "plugin",
@@ -207,7 +210,7 @@
 	if (level < loglevel_ce.u.value)
 		return;
 
-	if (logfile == syslog_dummy) {
+	if (logfile == &syslog_dummy) {
 		/* FIXME: this omits the 'file' string */
 		va_start(ap, format);
 		vsyslog(ulogd2syslog_level(level), format, ap);
@@ -348,7 +351,7 @@
 
 
 /* plugin loader to dlopen() a plugins */
-static int load_plugin(char *file)
+static int load_plugin(const char *file)
 {
 	if (!dlopen(file, RTLD_NOW)) {
 		ulogd_log(ULOGD_ERROR, "load_plugin: '%s': %s\n", file,
@@ -505,7 +508,7 @@
 }
 
 /* create a new stack of plugins */
-static int create_stack(char *option)
+static int create_stack(const char *option)
 {
 	struct ulogd_pluginstance_stack *stack;
 	char *buf = strdup(option);
@@ -620,10 +623,15 @@
 /* open the logfile */
 static int logfile_open(const char *name)
 {
-	if (!strcmp(name,"stdout")) {
+	if (name)
+		ulogd_logfile = name;
+
+	if (!strcmp(name, "stdout")) {
 		logfile = stdout;
+	} else if (!strcmp(name, "syslog")) {
+		logfile = &syslog_dummy;
 	} else {
-		logfile = fopen(name, "a");
+		logfile = fopen(ulogd_logfile, "a");
 		if (!logfile) {
 			fprintf(stderr, "ERROR: can't open logfile %s: %s\n", 
 				name, strerror(errno));
@@ -671,10 +679,8 @@
 			break;
 	}
 	return 1;
-
 }
 
-
 static void deliver_signal_pluginstances(int signal)
 {
 	struct ulogd_pluginstance_stack *stack;
@@ -705,15 +711,21 @@
 {
 	ulogd_log(ULOGD_NOTICE, "signal received, calling pluginstances\n");
 	
+	switch (signal) {
+	case SIGHUP:
+		/* reopen logfile */
+		if (logfile != stdout && logfile != &syslog_dummy) {
+			fclose(logfile);
+			logfile = fopen(ulogd_logfile, "a");
+			if (!logfile)
+				sigterm_handler(signal);
+		}
+		break;
+	default:
+		break;
+	}
+
 	deliver_signal_pluginstances(signal);
-
-	/* reopen logfile */
-	if (logfile != stdout && logfile != syslog_dummy) {
-		fclose(logfile);
-		logfile = fopen(logfile_ce.u.string, "a");
-		if (!logfile)
-			sigterm_handler(signal);
-	}
 }
 
 static void print_usage(void)
@@ -838,13 +850,11 @@
 		}
 	}
 
-	logfile_open(logfile_ce.u.string);
-
 	if (daemonize){
 		if (fork()) {
 			exit(0);
 		}
-		if (logfile != stdout && logfile != syslog_dummy)
+		if (logfile != stdout && logfile != &syslog_dummy)
 			fclose(stdout);
 		fclose(stderr);
 		fclose(stdin);
@@ -853,6 +863,7 @@
 
 	signal(SIGTERM, &sigterm_handler);
 	signal(SIGHUP, &signal_handler);
+	signal(SIGUSR1, &signal_handler);
 
 	ulogd_log(ULOGD_INFO, 
 		  "initialization finished, entering main loop\n");




More information about the netfilter-cvslog mailing list