]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/lib: add option "serverid watch:debug script"
authorRalph Boehme <slow@samba.org>
Thu, 25 Apr 2024 13:17:08 +0000 (15:17 +0200)
committerJule Anger <janger@samba.org>
Wed, 2 Oct 2024 14:34:13 +0000 (14:34 +0000)
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 <metze@samba.org>

Signed-off-by: Ralph Boehme <slow@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 7add7dbf1aee13b4d9ab70d1a5312c8ff30d9e00)

source3/lib/server_id_watch.c

index c372ec8c43176c763be572f38a75882c304e3d9b..8ddf9c6b1c897f89627a3793dfda2b69013186a6 100644 (file)
@@ -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);