From 1c21f37e57a4ae8436e78a159b2e4c0cca3a33a1 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Tue, 9 Jul 2013 12:32:53 +1000 Subject: [PATCH] ctdbd: Set process names for child processes This helps distinguish processes in process list in top, perf, etc. Signed-off-by: Amitay Isaacs (This used to be ctdb commit 2493f57ce268d6fe7e4c40a87852c347fd60d29e) --- ctdb/common/ctdb_logging.c | 1 + ctdb/server/ctdb_call.c | 1 + ctdb/server/ctdb_logging.c | 1 + ctdb/server/ctdb_monitor.c | 1 + ctdb/server/ctdb_recover.c | 1 + ctdb/server/ctdb_recoverd.c | 3 +++ ctdb/server/ctdb_takeover.c | 1 + ctdb/server/ctdb_traverse.c | 1 + ctdb/server/ctdb_update_record.c | 1 + ctdb/server/ctdb_vacuum.c | 2 +- ctdb/server/eventscript.c | 2 ++ 11 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ctdb/common/ctdb_logging.c b/ctdb/common/ctdb_logging.c index 9b69b383ecf..990a6b558c9 100644 --- a/ctdb/common/ctdb_logging.c +++ b/ctdb/common/ctdb_logging.c @@ -166,6 +166,7 @@ int32_t ctdb_control_get_log(struct ctdb_context *ctdb, TDB_DATA addr) } 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); diff --git a/ctdb/server/ctdb_call.c b/ctdb/server/ctdb_call.c index fe83bc158af..aa69f93d6c8 100644 --- a/ctdb/server/ctdb_call.c +++ b/ctdb/server/ctdb_call.c @@ -1645,6 +1645,7 @@ int ctdb_start_revoke_ro_record(struct ctdb_context *ctdb, struct ctdb_db_contex close(rc->fd[0]); debug_extra = talloc_asprintf(NULL, "revokechild-%s:", ctdb_db->db_name); + ctdb_set_process_name("ctdb_revokechild"); if (switch_from_server_to_client(ctdb, "revokechild-%s", ctdb_db->db_name) != 0) { DEBUG(DEBUG_ERR,("Failed to switch from server to client for revokechild process\n")); c = 1; diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index 44f0da75225..adf1c8f2ba6 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -141,6 +141,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb) ctdb->ev = event_context_init(NULL); syslog(LOG_ERR, "Starting SYSLOG daemon with pid:%d", (int)getpid()); + ctdb_set_process_name("ctdb_syslogd"); close(state->fd[0]); close(startup_fd[0]); diff --git a/ctdb/server/ctdb_monitor.c b/ctdb/server/ctdb_monitor.c index 8d28fff14f0..63eb9dfc005 100644 --- a/ctdb/server/ctdb_monitor.c +++ b/ctdb/server/ctdb_monitor.c @@ -90,6 +90,7 @@ void ctdb_run_notification_script(struct ctdb_context *ctdb, const char *event) if (child == 0) { int ret; + ctdb_set_process_name("ctdb_notification"); debug_extra = talloc_asprintf(NULL, "notification-%s:", event); ret = ctdb_run_notification_script_child(ctdb, event); if (ret != 0) { diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index 1c18acaed8f..18b4d8e58eb 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -669,6 +669,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, char cc = 0; close(state->fd[0]); + ctdb_set_process_name("ctdb_recmode"); 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/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index ece1491af99..2d0b9673a2e 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -2165,6 +2165,7 @@ static void getlog_handler(struct ctdb_context *ctdb, uint64_t srvid, } if (child == 0) { + ctdb_set_process_name("ctdb_rec_log_collector"); if (switch_from_server_to_client(ctdb, "recoverd-log-collector") != 0) { DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch log collector child into client mode.\n")); _exit(1); @@ -3224,6 +3225,7 @@ static int check_recovery_lock(struct ctdb_context *ctdb) close(state->fd[0]); state->fd[0] = -1; + ctdb_set_process_name("ctdb_rec_reclock"); 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))); @@ -4070,6 +4072,7 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb) /* Clear the log ringbuffer */ ctdb_clear_log(ctdb); + ctdb_set_process_name("ctdb_recovered"); 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/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 1a15596257e..be49b3f3b7f 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -4524,6 +4524,7 @@ int32_t ctdb_control_reload_public_ips(struct ctdb_context *ctdb, struct ctdb_re close(h->fd[0]); debug_extra = talloc_asprintf(NULL, "reloadips:"); + ctdb_set_process_name("ctdb_reloadips"); if (switch_from_server_to_client(ctdb, "reloadips-child") != 0) { DEBUG(DEBUG_CRIT,("ERROR: Failed to switch reloadips child into client mode\n")); res = -1; diff --git a/ctdb/server/ctdb_traverse.c b/ctdb/server/ctdb_traverse.c index bbbc3e1df01..ed6e8e484b2 100644 --- a/ctdb/server/ctdb_traverse.c +++ b/ctdb/server/ctdb_traverse.c @@ -182,6 +182,7 @@ static struct ctdb_traverse_local_handle *ctdb_traverse_local(struct ctdb_db_con close(h->fd[0]); + ctdb_set_process_name("ctdb_traverse"); if (switch_from_server_to_client(ctdb_db->ctdb, "traverse_local-%s:", ctdb_db->db_name) != 0) { diff --git a/ctdb/server/ctdb_update_record.c b/ctdb/server/ctdb_update_record.c index ce8e8afe117..7bfa08ac8b4 100644 --- a/ctdb/server/ctdb_update_record.c +++ b/ctdb/server/ctdb_update_record.c @@ -250,6 +250,7 @@ static struct childwrite_handle *ctdb_childwrite( char c = 0; close(result->fd[0]); + ctdb_set_process_name("ctdb_write_persistent"); debug_extra = talloc_asprintf(NULL, "childwrite-%s:", ctdb_db->db_name); ret = ctdb_persistent_store(state); if (ret != 0) { diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c index 1f2fb01e752..d07afd4f90c 100644 --- a/ctdb/server/ctdb_vacuum.c +++ b/ctdb/server/ctdb_vacuum.c @@ -1627,7 +1627,7 @@ ctdb_vacuum_event(struct event_context *ev, struct timed_event *te, close(child_ctx->fd[0]); DEBUG(DEBUG_INFO,("Vacuuming child process %d for db %s started\n", getpid(), ctdb_db->db_name)); - + ctdb_set_process_name("ctdb_vacuum"); 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/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index 3e79d4b1034..1152319b039 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -407,6 +407,7 @@ static int fork_child_for_script(struct ctdb_context *ctdb, ctdb_eventscript_call_names[state->call]); close(state->fd[0]); set_close_on_exec(state->fd[1]); + ctdb_set_process_name("ctdb_eventscript"); rt = child_run_script(ctdb, state->from_user, state->call, state->options, current); /* We must be able to write PIPEBUF bytes at least; if this @@ -540,6 +541,7 @@ static void ctdb_run_debug_hung_script(struct ctdb_context *ctdb, struct ctdb_ev if (pid == 0) { char *buf; + ctdb_set_process_name("ctdb_debug_hung_script"); if (getenv("CTDB_DEBUG_HUNG_SCRIPT") != NULL) { debug_hung_script = getenv("CTDB_DEBUG_HUNG_SCRIPT"); }