]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add a control to get the pid of a daemon.
authorRonnie Sahlberg <sahlberg@ronnie>
Sat, 5 May 2007 18:31:22 +0000 (04:31 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sat, 5 May 2007 18:31:22 +0000 (04:31 +1000)
this makes it possible to kill a specific daemon in the recover test
script

(This used to be ctdb commit 2fa394b4c80988cb1a6d04b236ec64cc9d9e8a40)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tests/recover.sh
ctdb/tools/ctdb_control.c

index 184ef6e76bd8eb744c739780e7137609ad8538f3..de6d4f7b69e9c8f2ce82d32bd876faaf58a42a4d 100644 (file)
@@ -1569,3 +1569,26 @@ int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f)
        return ctdb_traverse(ctdb_db, dumpdb_fn, f);
 }
 
+/*
+  get the pid of a ctdb daemon
+ */
+int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid)
+{
+       int ret;
+       TDB_DATA data, outdata;
+       int32_t res;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_PID, 0, data, 
+                          ctdb, &outdata, &res, &timeout);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n"));
+               return -1;
+       }
+
+       *pid = ((uint32_t *)outdata.dptr)[0];
+
+       return 0;
+}
+
index ebba36f6c4dd48e97cec7cf9715eb42f1cd45a94..9596ef2f1608198fce098a1b9556c54b8a65565b 100644 (file)
@@ -348,6 +348,14 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return 0;
        }
 
+       case CTDB_CONTROL_GET_PID: {
+               outdata->dsize = sizeof(uint32_t);
+               outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, 1);
+               *((uint32_t *)(&outdata->dptr[0])) = (uint32_t)getpid();
+
+               return 0;
+       }
+
        case CTDB_CONTROL_CONFIG: {
                CHECK_CONTROL_DATA_SIZE(0);
                ctdb->status.controls.get_config++;
index f73d5f51429940e50e360fd4d62106d4066ee300..964872d44751c05c69df495546b3c6f7f53db1b5 100644 (file)
@@ -303,4 +303,9 @@ int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *
 
 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
 
+/*
+  get the pid of a ctdb daemon
+ */
+int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
+
 #endif
index cd47bba863e15d79c43f7b7340edae5f0912da5c..73767b292aed4c5397932a2690319fbafd820758 100644 (file)
@@ -312,6 +312,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
                    CTDB_CONTROL_UPDATE_SEQNUM,
                    CTDB_CONTROL_SET_SEQNUM_FREQUENCY,
                    CTDB_CONTROL_DUMP_MEMORY,
+                   CTDB_CONTROL_GET_PID,
 };
 
 
index 79fe70f2a4baf3848b3e1fbe9829005124957990..3267699ffde3f3a6ace6a74cc997ae7d3008454c 100755 (executable)
@@ -71,7 +71,7 @@ echo
 echo
 echo "killing off node #0"
 echo "==================="
-CTDBPID=`ps aux | grep ctdbd | grep -v grep | head -1 | sed -e "s/^[^ ]* *//" -e "s/ .*$//"`
+CTDBPID=`./bin/ctdb_control getpid 0 | sed -e "s/Pid://"`
 kill $CTDBPID
 sleep 1
 
index a436ae7210af871418af96be7562dc1a52585577..d35645aef2f03cbd0fe600022f360508f48ab0f4 100644 (file)
@@ -54,7 +54,9 @@ static void usage(void)
                "  setrecmode <vnn> <mode>            set recovery mode\n"
                "  writerecord <vnn> <dbid> <key> <data>\n"
                "  recover <vnn>                      recover the cluster\n"
-               "  attach <dbname>                    attach a database\n");
+               "  attach <dbname>                    attach a database\n"
+               "  getpid <vnn>                       get the pid of a ctdb daemon\n"
+       );
        exit(1);
 }
 
@@ -502,6 +504,31 @@ static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **a
        return 0;
 }
 
+/*
+  display pid of a ctdb daemon
+ */
+static int control_getpid(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t vnn, pid;
+       int ret;
+
+
+       if (argc < 1) {
+               usage();
+       }
+
+       vnn     = strtoul(argv[0], NULL, 0);
+
+       ret = ctdb_ctrl_getpid(ctdb, timeval_current_ofs(1, 0), vnn, &pid);
+       if (ret != 0) {
+               printf("Unable to get daemon pid from node %u\n", vnn);
+               return ret;
+       }
+       printf("Pid:%d\n",pid);
+
+       return 0;
+}
+
 /*
   display recovery mode of a remote node
  */
@@ -1000,6 +1027,7 @@ int main(int argc, const char *argv[])
                { "writerecord", control_writerecord },
                { "attach", control_attach },
                { "dumpmemory", control_dumpmemory },
+               { "getpid", control_getpid },
        };
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);