From 71cd2f7ce705561d8d8f3cb7f385a57bedad1ef1 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 24 Feb 2010 18:58:15 +0100 Subject: Reopen logs when SIGHUP is caught Upon receiving SIGHUP, the monitor signals all services to reopen their debug logs. It is also possible to signal individual services to reopen their particular files. Fixes: #332 --- src/util/debug.c | 13 +++++++++++++ src/util/server.c | 19 +++++++++++++++++++ src/util/util.h | 1 + 3 files changed, 33 insertions(+) (limited to 'src/util') diff --git a/src/util/debug.c b/src/util/debug.c index d26d31c9..5b6fccd6 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -152,3 +152,16 @@ int open_debug_file(void) { return open_debug_file_ex(NULL, NULL); } + +int rotate_debug_files(void) +{ + int ret; + + if (!debug_to_file) return EOK; + + ret = fclose(debug_file); + if (ret) return ret; + debug_file = NULL; + + return open_debug_file(); +} diff --git a/src/util/server.c b/src/util/server.c index 226e16e2..a0ec2a26 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -284,6 +284,17 @@ int die_if_parent_died(void) return EOK; } +static void te_server_hup(struct tevent_context *ev, + struct tevent_signal *se, + int signum, + int count, + void *siginfo, + void *private_data) +{ + DEBUG(1, ("Received SIGHUP. Rotating logfiles.\n")); + rotate_debug_files(); +} + int server_setup(const char *name, int flags, const char *conf_entry, struct main_context **main_ctx) @@ -295,6 +306,7 @@ int server_setup(const char *name, int flags, int ret = EOK; bool dt; bool dl; + struct tevent_signal *tes; debug_prg_name = strdup(name); if (!debug_prg_name) { @@ -391,6 +403,13 @@ int server_setup(const char *name, int flags, } if (dl) debug_to_file = 1; + /* before opening the log file set up log rotation */ + tes = tevent_add_signal(ctx->event_ctx, ctx, SIGHUP, 0, + te_server_hup, NULL); + if (tes == NULL) { + return EIO; + } + /* open log file if told so */ if (debug_to_file) { ret = open_debug_file(); diff --git a/src/util/util.h b/src/util/util.h index 1f5573d4..db8e1ac3 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -201,6 +201,7 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level, const char *fmt, va_list ap); int open_debug_file_ex(const char *filename, FILE **filep); int open_debug_file(void); +int rotate_debug_files(void); /* from server.c */ struct main_context { -- cgit