feat(controller-peers-env-fallback): default the harness masters setting from XCE_CONTROLLER_PEERS (task 3.3)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
05a7e6dd0c
commit
65ae25a1e6
3 changed files with 154 additions and 8 deletions
|
|
@ -259,7 +259,9 @@ delaymgr_t delaymgr;
|
|||
static setting_t settings[] = {
|
||||
/* HA controller list: comma-separated "name=host:port" or "host:port"
|
||||
* entries (same syntax as the controller --peers flag), enabling the
|
||||
* test client to fail over across controller candidates. */
|
||||
* test client to fail over across controller candidates. main() replaces
|
||||
* this built-in default with XCE_CONTROLLER_PEERS when that is set and
|
||||
* non-empty (masters_default_from_env), before the rc file is loaded. */
|
||||
{ (char*)"masters", (char*)NULL, (char*)"localhost:9990" },
|
||||
{ (char*)"secret", (char*)NULL, (char*)"keepSecret" },
|
||||
{ (char*)"myname", (char*)NULL, (char*)"localhost" },
|
||||
|
|
@ -412,6 +414,11 @@ static const char USAGE_SET[] =
|
|||
" regardless of TTY state, until +y\n"
|
||||
" +y require confirmation before those\n"
|
||||
" commands again (default)\n"
|
||||
" masters default: $XCE_CONTROLLER_PEERS when it\n"
|
||||
" is set and non-empty, else localhost:9990;\n"
|
||||
" an explicit `set masters' wins. To opt\n"
|
||||
" out, leave XCE_CONTROLLER_PEERS unset or\n"
|
||||
" empty (e.g. XCE_CONTROLLER_PEERS= xce_test)\n"
|
||||
"example: set masters ctrl1=localhost:9991,ctrl2=localhost:9992\n";
|
||||
|
||||
static const char USAGE_JOIN_WORKER_HEAD[] =
|
||||
|
|
@ -1011,6 +1018,54 @@ static xce_client_config_t config;
|
|||
* persists for the lifetime of the client context. */
|
||||
static xce_cluster_config_t master_cfg;
|
||||
|
||||
/* The `masters` row of settings[] (the table every context shares). */
|
||||
static setting_t* masters_setting(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; settings[i].key; i++) {
|
||||
if (strcmp(settings[i].key, "masters") == 0) {
|
||||
return &settings[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* controller-peers-env-fallback (Req 1.2, 1.3, 1.7): at startup, before the
|
||||
* rc file is loaded or any command runs, take the `masters` default from
|
||||
* XCE_CONTROLLER_PEERS when it is set and non-empty; otherwise the built-in
|
||||
* default stays. An explicit `set masters` (typed, scripted or in the rc
|
||||
* file) still wins through get_setting()'s value-before-defval rule. The
|
||||
* getenv() storage stays valid for the process lifetime and is only read. */
|
||||
static void masters_default_from_env(void)
|
||||
{
|
||||
const char* env = xce_controller_peers_env();
|
||||
setting_t* m = masters_setting();
|
||||
|
||||
if ((env != NULL) && (m != NULL)) {
|
||||
m->defval = (char*)env;
|
||||
}
|
||||
}
|
||||
|
||||
/* Source note appended to enter_ctx()'s invalid-`masters` message (Req 1.4):
|
||||
* an explicit `set masters` is blamed whenever one ran; otherwise the
|
||||
* variable is named when it supplied the default; otherwise (the built-in
|
||||
* default) the message is today's, with no note. */
|
||||
static const char* masters_source_note(void)
|
||||
{
|
||||
setting_t* m = masters_setting();
|
||||
|
||||
if ((m != NULL) && (m->value != NULL)) {
|
||||
return " (explicit `set masters')";
|
||||
}
|
||||
if (xce_controller_peers_env() != NULL) {
|
||||
return " (default from XCE_CONTROLLER_PEERS)";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
int enter_ctx(command_ctx_t* ctx)
|
||||
{
|
||||
char* masters = get_setting("masters");
|
||||
|
|
@ -1023,8 +1078,8 @@ int enter_ctx(command_ctx_t* ctx)
|
|||
memset(&master_cfg, 0, sizeof(master_cfg));
|
||||
if ((masters == NULL) || (xce_parse_peers(masters, &master_cfg) != 0) ||
|
||||
(master_cfg.candidates_count < 1)) {
|
||||
fprintf(stderr, "enter_ctx: invalid 'masters' setting `%s'\n",
|
||||
masters ? masters : "(null)");
|
||||
fprintf(stderr, "enter_ctx: invalid 'masters' setting `%s'%s\n",
|
||||
masters ? masters : "(null)", masters_source_note());
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
@ -7061,6 +7116,10 @@ int main(int argc, char* argv[])
|
|||
rl_attempted_completion_function = xcetest_complete;
|
||||
}
|
||||
|
||||
/* controller-peers-env-fallback task 3.3: must run before the rc file
|
||||
* (and every later command) so an explicit `set masters` there wins. */
|
||||
masters_default_from_env();
|
||||
|
||||
/* xce-test-rc-file task 2.2: auto-load $XDG_CONFIG_HOME/xce_test/rc (or
|
||||
* $HOME/.config/xce_test/rc) before the read loop starts, for both
|
||||
* interactive and scripted sessions alike -- unless --norc was given.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue