1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-31 17:18:04 +03:00

ctdb-common: Add support for reopening logs

Now that CTDB uses Samba's file logging it is possible to reopen the
logs, so that log rotation can be supported.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2021-09-30 20:55:27 +10:00 committed by Amitay Isaacs
parent d0a19778cd
commit 7277385390
2 changed files with 82 additions and 0 deletions

View File

@ -667,3 +667,78 @@ int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
talloc_free(option);
return ret;
}
bool logging_reopen_logs(void)
{
bool status;
status = reopen_logs_internal();
return status;
}
struct logging_reopen_logs_data {
void (*hook)(void *private_data);
void *private_data;
};
static void logging_sig_hup_handler(struct tevent_context *ev,
struct tevent_signal *se,
int signum,
int count,
void *dont_care,
void *private_data)
{
bool status;
if (private_data != NULL) {
struct logging_reopen_logs_data *data = talloc_get_type_abort(
private_data, struct logging_reopen_logs_data);
if (data->hook != NULL) {
data->hook(data->private_data);
}
}
status = logging_reopen_logs();
if (!status) {
D_WARNING("Failed to reopen logs\n");
return;
}
D_NOTICE("Reopened logs\n");
}
bool logging_setup_sighup_handler(struct tevent_context *ev,
TALLOC_CTX *talloc_ctx,
void (*hook)(void *private_data),
void *private_data)
{
struct logging_reopen_logs_data *data = NULL;
struct tevent_signal *se;
if (hook != NULL) {
data = talloc(talloc_ctx, struct logging_reopen_logs_data);
if (data == NULL) {
return false;
}
data->hook = hook;
data->private_data = private_data;
}
se = tevent_add_signal(ev,
talloc_ctx,
SIGHUP,
0,
logging_sig_hup_handler,
data);
if (se == NULL) {
talloc_free(data);
return false;
}
return true;
}

View File

@ -21,6 +21,7 @@
#define __CTDB_LOGGING_H__
#include <talloc.h>
#include <tevent.h>
#include "lib/util/debug.h"
#define DEBUG_ERR DBGLVL_ERR
@ -41,4 +42,10 @@ bool logging_validate(const char *logging);
int logging_init(TALLOC_CTX *mem_ctx, const char *logging,
const char *debuglevel, const char *app_name);
bool logging_reopen_logs(void);
bool logging_setup_sighup_handler(struct tevent_context *ev,
TALLOC_CTX *talloc_ctx,
void (*hook)(void *private_data),
void *private_data);
#endif /* __CTDB_LOGGING_H__ */