From 7d034fe1399ecb7305c91e16e114a63c67f5a983 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 30 Aug 2017 17:04:44 +1000 Subject: [PATCH] ctdb-tests: Implement control CHECK_PID_SRVID in fake daemon BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/tests/src/fake_ctdbd.c | 47 ++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c index b09e80d70d0..8b3a0c44887 100644 --- a/ctdb/tests/src/fake_ctdbd.c +++ b/ctdb/tests/src/fake_ctdbd.c @@ -1651,9 +1651,6 @@ static void control_deregister_srvid(TALLOC_CTX *mem_ctx, reply.status = 0; reply.errmsg = NULL; - client_send_control(req, header, &reply); - return; - fail: client_send_control(req, header, &reply); } @@ -2787,6 +2784,46 @@ fail: client_send_control(req, header, &reply); } +static void control_check_pid_srvid(TALLOC_CTX *mem_ctx, + struct tevent_req *req, + struct ctdb_req_header *header, + struct ctdb_req_control *request) +{ + struct client_state *state = tevent_req_data( + req, struct client_state); + struct ctdbd_context *ctdb = state->ctdb; + struct client_state *cstate; + struct ctdb_reply_control reply; + int ret; + + reply.rdata.opcode = request->opcode; + + cstate = client_find(ctdb, request->rdata.data.pid_srvid->pid); + if (cstate == NULL) { + reply.status = -1; + reply.errmsg = "No client for PID"; + } else { + ret = srvid_exists(ctdb->srv, + request->rdata.data.pid_srvid->srvid, + cstate); + if (ret != 0) { + reply.status = -1; + reply.errmsg = "No client for PID and SRVID"; + } else { + ret = kill(cstate->pid, 0); + if (ret != 0) { + reply.status = ret; + reply.errmsg = strerror(errno); + } else { + reply.status = 0; + reply.errmsg = NULL; + } + } + } + + client_send_control(req, header, &reply); +} + static bool fake_control_failure(TALLOC_CTX *mem_ctx, struct tevent_req *req, struct ctdb_req_header *header, @@ -3376,6 +3413,10 @@ static void client_process_control(struct tevent_req *req, control_get_nodes_file(mem_ctx, req, &header, &request); break; + case CTDB_CONTROL_CHECK_PID_SRVID: + control_check_pid_srvid(mem_ctx, req, &header, &request); + break; + default: if (! (request.flags & CTDB_CTRL_FLAG_NOREPLY)) { control_error(mem_ctx, req, &header, &request);