From: Vinit Agnihotri Date: Tue, 26 Apr 2022 07:20:21 +0000 (+1000) Subject: ctdb-tests: Add runstate handling to fake ctdbd X-Git-Tag: tevent-0.13.0~218 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=428bc71f98fd560e1d8ea17fd76b4a34ac9421c6;p=thirdparty%2Fsamba.git ctdb-tests: Add runstate handling to fake ctdbd Signed-off-by: Vinit Agnihotri Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c index ca6f5a24e9c..a04ad853306 100644 --- a/ctdb/tests/src/fake_ctdbd.c +++ b/ctdb/tests/src/fake_ctdbd.c @@ -1166,6 +1166,44 @@ fail: return false; } +static bool runstate_parse(struct ctdbd_context *ctdb) +{ + char line[1024]; + char *t; + + if (fgets(line, sizeof(line), stdin) == NULL) { + goto fail; + } + + if (line[0] == '\n') { + goto fail; + } + + /* Get rid of pesky newline */ + if ((t = strchr(line, '\n')) != NULL) { + *t = '\0'; + } + + ctdb->runstate = ctdb_runstate_from_string(line); + if (ctdb->runstate == CTDB_RUNSTATE_UNKNOWN) { + goto fail; + } + + /* Swallow possible blank line following section. Picky + * compiler settings don't allow the return value to be + * ignored, so make the compiler happy. + */ + if (fgets(line, sizeof(line), stdin) == NULL) { + ; + } + D_INFO("Parsing runstate done\n"); + return true; + +fail: + D_ERR("Parsing runstate failed\n"); + return false; +} + /* * Manage clients */ @@ -1265,6 +1303,8 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx, goto fail; } + ctdb->runstate = CTDB_RUNSTATE_RUNNING; + while (fgets(line, sizeof(line), stdin) != NULL) { char *t; @@ -1287,6 +1327,8 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx, status = reclock_parse(ctdb); } else if (strcmp(line, "CONTROLFAILS") == 0) { status = control_failures_parse(ctdb); + } else if (strcmp(line, "RUNSTATE") == 0) { + status = runstate_parse(ctdb); } else { fprintf(stderr, "Unknown line %s\n", line); status = false; @@ -1307,7 +1349,6 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx, ctdb->recovery_end_time = tevent_timeval_current(); ctdb->log_level = DEBUG_ERR; - ctdb->runstate = CTDB_RUNSTATE_RUNNING; ctdb_tunable_set_defaults(&ctdb->tun_list);