From e7c72588d187f9505444f48a1c5b19e47b15ccd9 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 6 Jun 2014 15:43:22 +1000 Subject: ctdb-logging: Move controls handling functions from common to server Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/server/ctdb_logging.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'ctdb/server') diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index d33419177bb..f22c9f30ee9 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -644,5 +644,44 @@ int ctdb_init_tevent_logging(struct ctdb_context *ctdb) return ret; } +void ctdb_collect_log(struct ctdb_context *ctdb, struct ctdb_get_log_addr *log_addr) +{ + TDB_DATA data; - + data = ctdb_log_ringbuffer_collect_log(ctdb, log_addr->level); + + DEBUG(DEBUG_ERR,("Send log to %d:%d\n", (int)log_addr->pnn, (int)log_addr->srvid)); + ctdb_client_send_message(ctdb, log_addr->pnn, log_addr->srvid, data); + + if (data.dptr) { + talloc_free(data.dptr); + } +} + +int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr) +{ + struct ctdb_get_log_addr *log_addr = (struct ctdb_get_log_addr *)addr.dptr; + pid_t child; + + /* spawn a child process to marshall the huge log blob and send it back + to the ctdb tool using a MESSAGE + */ + child = ctdb_fork_no_free_ringbuffer(ctdb); + if (child == (pid_t)-1) { + DEBUG(DEBUG_ERR,("Failed to fork a log collector child\n")); + return -1; + } + + if (child == 0) { + ctdb_set_process_name("ctdb_log_collector"); + if (switch_from_server_to_client(ctdb, "log-collector") != 0) { + DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch log collector child into client mode.\n")); + _exit(1); + } + /* do logging here */ + ctdb_collect_log(ctdb, log_addr); + _exit(0); + } + + return 0; +} -- cgit