]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
Support for logfile cycling (SIGHUP handler)
authorlaforge <laforge>
Thu, 14 Jun 2001 19:25:25 +0000 (19:25 +0000)
committerlaforge <laforge>
Thu, 14 Jun 2001 19:25:25 +0000 (19:25 +0000)
Changes
extensions/ulogd_LOGEMU.c
extensions/ulogd_OPRINT.c
include/ulogd/ulogd.h
mysql/ulogd_MYSQL.c
ulogd.c

diff --git a/Changes b/Changes
index 4305911b151574d183f68f70a4e120af7543e5d8..e9248d04f69945d32b6bf63a895205f455973d04 100644 (file)
--- a/Changes
+++ b/Changes
@@ -9,6 +9,7 @@ Version 0.96
 - better commented example configuration file
 - Makefiles now know DESTDIR (for RPM packaging)
 - documentation now built at release-time, not compile time
+- support for logfile-rotating, using new SIGHUP handler
 
 Version 0.95
 - libipulog problems of 0.94 fixed
index 960084e6f53228336b4778d132de4066ae6e9604..35f768d9a32e7ee4ffd913e890df4aada1777925 100644 (file)
@@ -1,4 +1,4 @@
-/* ulogd_LOGEMU.c, Version $Revision: 1.4 $
+/* ulogd_LOGEMU.c, Version $Revision: 1.5 $
  *
  * ulogd output target for syslog logging emulation
  *
@@ -8,7 +8,7 @@
  * (C) 2000 by Harald Welte <laforge@gnumonks.org>
  * This software is released under the terms of GNU GPL
  *
- * $Id: ulogd_LOGEMU.c,v 1.4 2001/03/25 18:25:01 laforge Exp $
+ * $Id: ulogd_LOGEMU.c,v 1.5 2001/05/20 15:07:45 laforge Exp $
  *
  */
 
@@ -245,9 +245,28 @@ static int get_ids(void)
        return 0;
 }
 
+void sighup_handler_logemu(int signal)
+{
+       switch (signal) {
+       case SIGHUP:
+               ulogd_log(ULOGD_NOTICE, "syslogemu: reopening logfile\n");
+               fclose(of);
+               of = fopen(syslogf_ce.u.string, "a");
+               if (!of) {
+                       ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
+                               strerror(errno));
+                       exit(2);
+               }
+               break;
+       default:
+               break;
+       }
+}
+               
+
 static ulog_output_t logemu_op[] = {
-       { NULL, "syslogemu", &_output_logemu },
-       { NULL, "", NULL },
+       { NULL, "syslogemu", &_output_logemu, &sighup_handler_logemu },
+       { NULL, "", NULL, NULL },
 };
 
 /* register output plugin with ulogd */
index fc00b46da46f4e660f192aa274d4c045653c1ed2..979548de5a34ff74042cd6842a977fe29ba167b8 100644 (file)
@@ -1,11 +1,11 @@
-/* ulogd_MAC.c, Version $Revision: 1.5 $
+/* ulogd_MAC.c, Version $Revision: 1.6 $
  *
  * ulogd output target for logging to a file 
  *
  * (C) 2000 by Harald Welte <laforge@gnumonks.org>
  * This software is released under the terms of GNU GPL
  *
- * $Id: ulogd_OPRINT.c,v 1.5 2000/11/16 17:20:52 laforge Exp $
+ * $Id: ulogd_OPRINT.c,v 1.6 2000/11/20 11:43:22 laforge Exp $
  *
  */
 
@@ -67,9 +67,32 @@ int _output_print(ulog_iret_t *res)
        return 0;
 }
 
+static config_entry_t outf_ce = { NULL, "dumpfile", CONFIG_TYPE_STRING, 
+                                 CONFIG_OPT_NONE, 0,
+                                 { string: ULOGD_OPRINT_DEFAULT } };
+
+void sighup_handler_print(int signal)
+{
+
+       switch (signal) {
+       case SIGHUP:
+               ulogd_log(ULOGD_NOTICE, "PKTLOG: reopening logfile\n");
+               fclose(of);
+               of = fopen(outf_ce.u.string, "a");
+               if (!of) {
+                       ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
+                               strerror(errno));
+                       exit(2);
+               }
+               break;
+       default:
+               break;
+       }
+}
+
 static ulog_output_t base_op[] = {
-       { NULL, "oprint", &_output_print },
-       { NULL, "", NULL },
+       { NULL, "oprint", &_output_print, &sighup_handler_print },
+       { NULL, "", NULL, NULL },
 };
 
 
@@ -82,9 +105,6 @@ static void _base_reg_op(void)
                register_output(p);
 }
 
-static config_entry_t outf_ce = { NULL, "dumpfile", CONFIG_TYPE_STRING, 
-                                 CONFIG_OPT_NONE, 0,
-                                 { string: ULOGD_OPRINT_DEFAULT } };
 void _init(void)
 {
 #ifdef DEBUG
index 36e6a8c3dfc730d319b60d5c19b83e35c1a83ea3..613bb699c7dd24ffa54b8ebf4ba50dd835c92ab6 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef _ULOGD_H
 #define _ULOGD_H
-/* ulogd, Version $Revision: 1.12 $
+/* ulogd, Version $Revision: 1.13 $
  *
  * userspace logging daemon for netfilter ULOG target
  * of the linux 2.4 netfilter subsystem.
@@ -9,7 +9,7 @@
  *
  * this code is released under the terms of GNU GPL
  *
- * $Id: ulogd.h,v 1.12 2001/02/04 13:07:22 laforge Exp $
+ * $Id: ulogd.h,v 1.13 2001/05/26 23:19:28 laforge Exp $
  */
 
 #include <libipulog/libipulog.h>
@@ -108,6 +108,8 @@ typedef struct ulog_output {
        char name[ULOGD_MAX_KEYLEN];
        /* callback function */
        int (*output)(ulog_iret_t *ret);
+       /* callback function for signals (SIGHUP, ..) */
+       int (*signal)(int signal);
 } ulog_output_t;
 
 /* entries of the key hash */
index e158814e336ef4d58a7ca524924a149208edac28..43842a4a4f8291808f889f99e6e2eefa2ccff462 100644 (file)
@@ -1,11 +1,11 @@
-/* ulogd_MYSQL.c, Version $Revision: 1.3 $
+/* ulogd_MYSQL.c, Version $Revision: 1.4 $
  *
  * ulogd output plugin for logging to a MySQL database
  *
  * (C) 2000 by Harald Welte <laforge@gnumonks.org> 
  * This software is distributed under the terms of GNU GPL 
  *
- * $Id: ulogd_MYSQL.c,v 1.3 2001/05/17 15:06:58 laforge Exp $
+ * $Id: ulogd_MYSQL.c,v 1.4 2001/05/20 13:51:46 laforge Exp $
  *
  * 15 May 2001, Alex Janssen <alex@ynfonatic.de>:
  *      Added a compability option for older MySQL-servers, which
@@ -308,7 +308,7 @@ static int _mysql_open_db(char *server, char *user, char *pass, char *db)
        return 0;
 }
 
-static ulog_output_t _mysql_plugin = { NULL, "mysql", &_mysql_output };
+static ulog_output_t _mysql_plugin = { NULL, "mysql", &_mysql_output, NULL };
 
 void _init(void) 
 {
diff --git a/ulogd.c b/ulogd.c
index cb53a5e6c124f3ac49ebf643dc3312018e0c5956..a13f5a0e12e4e18da8a87dfba6e184d505b88c85 100644 (file)
--- a/ulogd.c
+++ b/ulogd.c
@@ -1,4 +1,6 @@
-/* ulogd, Version $Revision: 1.15 $
+/* ulogd, Version $Revision: 1.16 $
+ *
+ * $Id: ulogd.c,v 1.16 2001/05/26 23:19:28 laforge Exp $
  *
  * userspace logging daemon for the netfilter ULOG target
  * of the linux 2.4 netfilter subsystem.
@@ -7,7 +9,9 @@
  *
  * this code is released under the terms of GNU GPL
  *
- * $Id: ulogd.c,v 1.15 2001/02/04 10:15:19 laforge Exp $
+ * Modifications:
+ *     14 Jun 2001 Martin Josefsson <gandalf@wlug.westbo.se>
+ *             - added SIGHUP handler for logfile cycling
  */
 
 #include <stdio.h>
@@ -510,6 +514,18 @@ static void sigterm_handler(int signal)
        exit(0);
 }
 
+static void sighup_handler(int signal)
+{
+       ulog_output_t *p;
+
+       ulogd_log(ULOGD_NOTICE, "sighup received, calling plugin handlers\n");
+       
+       for (p = ulogd_outputs; p; p = p->next) {
+               if (p->sighup)
+                       (*p->sighup)(SIGHUP);
+       }
+}
+
 int main(int argc, char* argv[])
 {
        size_t len;
@@ -555,6 +571,7 @@ int main(int argc, char* argv[])
                fclose(stderr);
 #endif
                signal(SIGTERM, &sigterm_handler);
+               signal(SIGHUP, &sighup_handler);
 
                ulogd_log(ULOGD_NOTICE, 
                          "initialization finished, entering main loop\n");
@@ -570,7 +587,7 @@ int main(int argc, char* argv[])
                }
 
                /* hackish, but result is the same */
-               sigterm_handler(SIGHUP);        
+               sigterm_handler(SIGTERM);       
 
 #ifndef DEBUG
        } else {