From fbb5ac8404525a0828504cd744992dfcb7c8e216 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 10 Nov 2017 12:10:05 +1100 Subject: [PATCH] ctdb-common: Return status from sock_daemon startup()/reconfigure() Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/sock_daemon.c | 21 +++++++++++-- ctdb/common/sock_daemon.h | 14 ++++++--- ctdb/tests/cunit/sock_daemon_test_001.sh | 14 +++++++++ ctdb/tests/src/sock_daemon_test.c | 54 +++++++++++++++++++++++++------- 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c index a41a5d5a7ea..bb241e0ebd8 100644 --- a/ctdb/common/sock_daemon.c +++ b/ctdb/common/sock_daemon.c @@ -648,7 +648,16 @@ static void sock_daemon_run_started(struct tevent_req *subreq) D_NOTICE("daemon started, pid=%u\n", getpid()); if (sockd->funcs != NULL && sockd->funcs->startup != NULL) { - sockd->funcs->startup(sockd->private_data); + int ret; + + ret = sockd->funcs->startup(sockd->private_data); + if (ret != 0) { + D_ERR("startup failed, ret=%d\n", ret); + tevent_req_error(req, EIO); + return; + } + + D_NOTICE("startup completed successfully\n"); } } @@ -680,7 +689,15 @@ static void sock_daemon_run_reconfigure(struct tevent_req *req) struct sock_daemon_context *sockd = state->sockd; if (sockd->funcs != NULL && sockd->funcs->reconfigure != NULL) { - sockd->funcs->reconfigure(sockd->private_data); + int ret; + + ret = sockd->funcs->reconfigure(sockd->private_data); + if (ret != 0) { + D_ERR("reconfigure failed, ret=%d\n", ret); + return; + } + + D_NOTICE("reconfigure completed successfully\n"); } } diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h index 18210287771..190a4ef172f 100644 --- a/ctdb/common/sock_daemon.h +++ b/ctdb/common/sock_daemon.h @@ -48,8 +48,14 @@ struct sock_client_context; * @brief The callback routines called during daemon life cycle * * startup() is called when the daemon starts running - * either via sock_daemon_run() or via sock_daemon_run_send() - * reconfigure() is called when process receives SIGUSR1 or SIGHUP + * either via sock_daemon_run() or via sock_daemon_run_send() + * startup() should return 0 for success, non-zero value on failure + * On failure, sock_daemon_run() will return error. + * + * reconfigure() is called when the daemon receives SIGUSR1 or SIGHUP + * reconfigure() should return 0 for success, non-zero value on failure + * On failure, sock_daemon_run() will continue to run. + * * shutdown() is called when process receives SIGINT or SIGTERM or * when wait computation has finished * @@ -60,8 +66,8 @@ struct sock_client_context; * If wait_send() returns req, then when req is over, daemon will shutdown. */ struct sock_daemon_funcs { - void (*startup)(void *private_data); - void (*reconfigure)(void *private_data); + int (*startup)(void *private_data); + int (*reconfigure)(void *private_data); void (*shutdown)(void *private_data); struct tevent_req * (*wait_send)(TALLOC_CTX *mem_ctx, diff --git a/ctdb/tests/cunit/sock_daemon_test_001.sh b/ctdb/tests/cunit/sock_daemon_test_001.sh index 9da484a7616..cbb5a7e292a 100755 --- a/ctdb/tests/cunit/sock_daemon_test_001.sh +++ b/ctdb/tests/cunit/sock_daemon_test_001.sh @@ -23,6 +23,8 @@ result_filter () ok <fd); server_state->fd = -1; + return 0; } struct test6_wait_state { -- 2.11.4.GIT