From: Ronnie Sahlberg Date: Sat, 5 May 2007 18:31:22 +0000 (+1000) Subject: add a control to get the pid of a daemon. X-Git-Tag: tevent-0.9.20~348^2~2768^2~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25edbc9a5094a0d74cdb3f4ebfba715a021e405a;p=thirdparty%2Fsamba.git add a control to get the pid of a daemon. this makes it possible to kill a specific daemon in the recover test script (This used to be ctdb commit 2fa394b4c80988cb1a6d04b236ec64cc9d9e8a40) --- diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 184ef6e76bd..de6d4f7b69e 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -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; +} + diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index ebba36f6c4d..9596ef2f160 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -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++; diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index f73d5f51429..964872d4475 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -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 diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index cd47bba863e..73767b292ae 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -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, }; diff --git a/ctdb/tests/recover.sh b/ctdb/tests/recover.sh index 79fe70f2a4b..3267699ffde 100755 --- a/ctdb/tests/recover.sh +++ b/ctdb/tests/recover.sh @@ -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 diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index a436ae7210a..d35645aef2f 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -54,7 +54,9 @@ static void usage(void) " setrecmode set recovery mode\n" " writerecord \n" " recover recover the cluster\n" - " attach attach a database\n"); + " attach attach a database\n" + " getpid 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);