From: Ralph Boehme Date: Thu, 25 Apr 2024 13:17:08 +0000 (+0200) Subject: s3/lib: add option "serverid watch:debug script" X-Git-Tag: ldb-2.8.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5388c25b886b207e6a24e29c1495654c29d2de6;p=thirdparty%2Fsamba.git s3/lib: add option "serverid watch:debug script" This takes just PID and NODE:PID on a cluster. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15624 Pair-Programmed-With: Stefan Metzmacher Signed-off-by: Ralph Boehme Signed-off-by: Stefan Metzmacher Reviewed-by: Guenther Deschner (cherry picked from commit 7add7dbf1aee13b4d9ab70d1a5312c8ff30d9e00) --- diff --git a/source3/lib/server_id_watch.c b/source3/lib/server_id_watch.c index c372ec8c431..8ddf9c6b1c8 100644 --- a/source3/lib/server_id_watch.c +++ b/source3/lib/server_id_watch.c @@ -100,6 +100,7 @@ static void server_id_watch_waited(struct tevent_req *subreq) if (timeval_compare(&state->warn, &now) == -1) { double duration = timeval_elapsed2(&state->start, &now); + const char *cmd = NULL; char proc_path[64] = { 0, }; char *kstack = NULL; struct server_id_buf buf; @@ -108,6 +109,57 @@ static void server_id_watch_waited(struct tevent_req *subreq) state->warn = tevent_timeval_add(&now, 10, 0); + cmd = lp_parm_const_string(GLOBAL_SECTION_SNUM, + "serverid watch", + "debug script", + NULL); + if (cmd != NULL) { + char *cmdstr = NULL; + char *output = NULL; + int fd; + + /* + * Note in a cluster setup pid will be + * a NOTE:PID like '1:3978365' + * + * Without clustering it is just '3978365' + */ + cmdstr = talloc_asprintf(state, "%s %s", cmd, pid); + if (cmdstr == NULL) { + DBG_ERR("Process %s hanging for %f seconds?\n" + "talloc_asprintf failed\n", + pid, duration); + goto next; + } + + become_root(); + ret = smbrun(cmdstr, &fd, NULL); + unbecome_root(); + if (ret != 0) { + DBG_ERR("Process %s hanging for %f seconds?\n" + "smbrun('%s') failed\n", + pid, duration, cmdstr); + TALLOC_FREE(cmdstr); + goto next; + } + + output = fd_load(fd, NULL, 0, state); + close(fd); + if (output == NULL) { + DBG_ERR("Process %s hanging for %f seconds?\n" + "fd_load() of smbrun('%s') failed\n", + pid, duration, cmdstr); + TALLOC_FREE(cmdstr); + goto next; + } + DBG_ERR("Process %s hanging for %f seconds?\n" + "%s returned:\n%s", + pid, duration, cmdstr, output); + TALLOC_FREE(cmdstr); + TALLOC_FREE(output); + goto next; + } + if (!procid_is_local(&state->pid) || !sys_have_proc_fds()) { DBG_ERR("Process %s hanging for %f seconds?\n", pid, duration);