From efea0aa10d862a1a0e36043cfd6f712b8cd326aa Mon Sep 17 00:00:00 2001 From: laforge Date: Thu, 14 Jun 2001 19:25:25 +0000 Subject: Support for logfile cycling (SIGHUP handler) --- Changes | 1 + extensions/ulogd_LOGEMU.c | 27 +++++++++++++++++++++++---- extensions/ulogd_OPRINT.c | 34 +++++++++++++++++++++++++++------- include/ulogd/ulogd.h | 6 ++++-- mysql/ulogd_MYSQL.c | 6 +++--- ulogd.c | 23 ++++++++++++++++++++--- 6 files changed, 78 insertions(+), 19 deletions(-) diff --git a/Changes b/Changes index 4305911..e9248d0 100644 --- 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 diff --git a/extensions/ulogd_LOGEMU.c b/extensions/ulogd_LOGEMU.c index 960084e..35f768d 100644 --- a/extensions/ulogd_LOGEMU.c +++ b/extensions/ulogd_LOGEMU.c @@ -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 * 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 */ diff --git a/extensions/ulogd_OPRINT.c b/extensions/ulogd_OPRINT.c index fc00b46..979548d 100644 --- a/extensions/ulogd_OPRINT.c +++ b/extensions/ulogd_OPRINT.c @@ -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 * 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 diff --git a/include/ulogd/ulogd.h b/include/ulogd/ulogd.h index 36e6a8c..613bb69 100644 --- a/include/ulogd/ulogd.h +++ b/include/ulogd/ulogd.h @@ -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 @@ -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 */ diff --git a/mysql/ulogd_MYSQL.c b/mysql/ulogd_MYSQL.c index e158814..43842a4 100644 --- a/mysql/ulogd_MYSQL.c +++ b/mysql/ulogd_MYSQL.c @@ -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 * 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 : * 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 cb53a5e..a13f5a0 100644 --- 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 + * - added SIGHUP handler for logfile cycling */ #include @@ -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 { -- cgit v1.2.3