From: Rusty Russell Date: Mon, 19 Jul 2010 09:59:09 +0000 (+0930) Subject: logging: give a unique logging name to each forked child. X-Git-Tag: ctdb-1.10~75^2 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=68b3761a0874429b90731741f0531f76dcfbb081;p=sahlberg%2Fctdb.git logging: give a unique logging name to each forked child. This means we can distinguish which child is logging, esp. via syslog where we have no pid. Signed-off-by: Rusty Russell --- diff --git a/client/ctdb_client.c b/client/ctdb_client.c index adba17c2..82b73040 100644 --- a/client/ctdb_client.c +++ b/client/ctdb_client.c @@ -3827,9 +3827,15 @@ int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb) * to the daemon as a client process, this function can be used to change * the ctdb context from daemon into client mode */ -int switch_from_server_to_client(struct ctdb_context *ctdb) +int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...) { int ret; + va_list ap; + + /* Add extra information so we can identify this in the logs */ + va_start(ap, fmt); + debug_extra = talloc_append_string(NULL, talloc_vasprintf(NULL, fmt, ap), ":"); + va_end(ap); /* shutdown the transport */ if (ctdb->methods) { diff --git a/common/ctdb_logging.c b/common/ctdb_logging.c index 18aafa23..de293335 100644 --- a/common/ctdb_logging.c +++ b/common/ctdb_logging.c @@ -164,7 +164,7 @@ int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr) } if (child == 0) { - if (switch_from_server_to_client(ctdb) != 0) { + 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); } diff --git a/include/ctdb_client.h b/include/ctdb_client.h index e9aa8d17..b3b0d675 100644 --- a/include/ctdb_client.h +++ b/include/ctdb_client.h @@ -551,7 +551,8 @@ int ctdb_transaction_commit(struct ctdb_transaction_handle *h); int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb); -int switch_from_server_to_client(struct ctdb_context *ctdb); +int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, + ...); int ctdb_ctrl_getscriptstatus(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, diff --git a/lib/util/debug.c b/lib/util/debug.c index 1cbaa230..e9365d88 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -42,13 +42,15 @@ static void _do_debug_v(const char *format, va_list ap) strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); - fprintf(stderr, "%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s); + fprintf(stderr, "%s.%06u [%s%5u]: %s", tbuf, (unsigned)t.tv_usec, + debug_extra, (unsigned)getpid(), s); fflush(stderr); free(s); } /* default logging function */ void (*do_debug_v)(const char *, va_list ap) = _do_debug_v; +const char *debug_extra = ""; void do_debug(const char *format, ...) { diff --git a/lib/util/debug.h b/lib/util/debug.h index 11ecb197..27490a3d 100644 --- a/lib/util/debug.h +++ b/lib/util/debug.h @@ -18,6 +18,7 @@ */ void (*do_debug_v)(const char *, va_list ap); +const char *debug_extra; void (*do_debug_add_v)(const char *, va_list ap); void log_ringbuffer(const char *format, ...); void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); diff --git a/server/ctdb_freeze.c b/server/ctdb_freeze.c index e641ef3a..bf4c83e8 100644 --- a/server/ctdb_freeze.c +++ b/server/ctdb_freeze.c @@ -202,6 +202,7 @@ static struct ctdb_freeze_handle *ctdb_freeze_lock(struct ctdb_context *ctdb, ui /* in the child */ close(fd[0]); + debug_extra = talloc_asprintf(NULL, "freeze_lock-%u:", priority); ret = ctdb_lock_all_databases(ctdb, priority); if (ret != 0) { _exit(0); diff --git a/server/ctdb_lockwait.c b/server/ctdb_lockwait.c index afbb9214..b7ae55c6 100644 --- a/server/ctdb_lockwait.c +++ b/server/ctdb_lockwait.c @@ -136,6 +136,7 @@ struct lockwait_handle *ctdb_lockwait(struct ctdb_db_context *ctdb_db, if (result->child == 0) { char c = 0; close(result->fd[0]); + debug_extra = talloc_asprintf(NULL, "chainlock-%s:", ctdb_db->db_name); tdb_chainlock(ctdb_db->ltdb->tdb, key); write(result->fd[1], &c, 1); /* make sure we die when our parent dies */ diff --git a/server/ctdb_logging.c b/server/ctdb_logging.c index 807bb179..880f844f 100644 --- a/server/ctdb_logging.c +++ b/server/ctdb_logging.c @@ -115,6 +115,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb) return 0; } + debug_extra = talloc_asprintf(NULL, "syslogd:"); talloc_free(ctdb->ev); ctdb->ev = event_context_init(NULL); @@ -213,15 +214,16 @@ static void ctdb_syslog_log(const char *format, va_list ap) break; } - len = offsetof(struct syslog_message, message) + strlen(s) + 1; + len = offsetof(struct syslog_message, message) + strlen(debug_extra) + strlen(s) + 1; msg = malloc(len); if (msg == NULL) { free(s); return; } msg->level = level; - msg->len = strlen(s); - strcpy(msg->message, s); + msg->len = strlen(debug_extra) + strlen(s); + strcpy(msg->message, debug_extra); + strcat(msg->message, s); if (syslogd_is_started == 0) { syslog(msg->level, "%s", msg->message); @@ -275,8 +277,9 @@ static void ctdb_logfile_log(const char *format, va_list ap) strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm); - ret = asprintf(&s2, "%s.%06u [%5u]: %s", - tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s); + ret = asprintf(&s2, "%s.%06u [%s%5u]: %s", + tbuf, (unsigned)t.tv_usec, + debug_extra, (unsigned)getpid(), s); free(s); if (ret == -1) { const char *errstr = "asprintf failed\n"; diff --git a/server/ctdb_monitor.c b/server/ctdb_monitor.c index 33435016..55cd4e38 100644 --- a/server/ctdb_monitor.c +++ b/server/ctdb_monitor.c @@ -91,6 +91,7 @@ void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event) if (child == 0) { int ret; + debug_extra = talloc_asprintf(NULL, "notification-%s:", event); ret = ctdb_run_notification_script_child(ctdb, event); if (ret != 0) { DEBUG(DEBUG_ERR,(__location__ " Notification script failed\n")); diff --git a/server/ctdb_persistent.c b/server/ctdb_persistent.c index d38aa8d9..4401bcda 100644 --- a/server/ctdb_persistent.c +++ b/server/ctdb_persistent.c @@ -543,6 +543,7 @@ struct childwrite_handle *ctdb_childwrite(struct ctdb_db_context *ctdb_db, char c = 0; close(result->fd[0]); + debug_extra = talloc_asprintf(NULL, "childwrite-%s:", ctdb_db->db_name); ret = ctdb_persistent_store(state); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Failed to write persistent data\n")); diff --git a/server/ctdb_recover.c b/server/ctdb_recover.c index 22e48986..f61b6e7b 100644 --- a/server/ctdb_recover.c +++ b/server/ctdb_recover.c @@ -725,6 +725,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, char cc = 0; close(state->fd[0]); + debug_extra = talloc_asprintf(NULL, "set_recmode:"); /* we should not be able to get the lock on the reclock file, as it should be held by the recovery master */ diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c index 82fe62ea..3145cd07 100644 --- a/server/ctdb_recoverd.c +++ b/server/ctdb_recoverd.c @@ -2774,6 +2774,7 @@ static int check_recovery_lock(struct ctdb_context *ctdb) close(state->fd[0]); state->fd[0] = -1; + debug_extra = talloc_asprintf(NULL, "recovery-lock:"); if (pread(ctdb->recovery_lock_fd, &cc, 1, 0) == -1) { DEBUG(DEBUG_CRIT,("failed read from recovery_lock_fd - %s\n", strerror(errno))); cc = RECLOCK_FAILED; @@ -3582,7 +3583,7 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb) srandom(getpid() ^ time(NULL)); - if (switch_from_server_to_client(ctdb) != 0) { + if (switch_from_server_to_client(ctdb, "recoverd") != 0) { DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch recovery daemon into client mode. shutting down.\n")); exit(1); } diff --git a/server/ctdb_traverse.c b/server/ctdb_traverse.c index 3549007c..52c2f709 100644 --- a/server/ctdb_traverse.c +++ b/server/ctdb_traverse.c @@ -171,6 +171,8 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con if (h->child == 0) { /* start the traverse in the child */ close(h->fd[0]); + debug_extra = talloc_asprintf(NULL, "traverse_local-%s:", + ctdb_db->db_name); tdb_traverse_read(ctdb_db->ltdb->tdb, ctdb_traverse_local_fn, h); _exit(0); } diff --git a/server/ctdb_vacuum.c b/server/ctdb_vacuum.c index f1e61dbf..375d4eff 100644 --- a/server/ctdb_vacuum.c +++ b/server/ctdb_vacuum.c @@ -841,7 +841,7 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te, DEBUG(DEBUG_INFO,("Vacuuming child process %d for db %s started\n", getpid(), ctdb_db->db_name)); - if (switch_from_server_to_client(ctdb) != 0) { + if (switch_from_server_to_client(ctdb, "vacuum-%s", ctdb_db->db_name) != 0) { DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch vacuum daemon into client mode. Shutting down.\n")); _exit(1); } diff --git a/server/eventscript.c b/server/eventscript.c index 8011269e..c4ffd262 100644 --- a/server/eventscript.c +++ b/server/eventscript.c @@ -385,6 +385,9 @@ static int fork_child_for_script(struct ctdb_context *ctdb, if (state->child == 0) { int rt; + debug_extra = talloc_asprintf(NULL, "eventscript-%s-%s:", + current->name, + ctdb_eventscript_call_names[state->call]); close(state->fd[0]); set_close_on_exec(state->fd[1]);