fix(worker): xcecd -h exits immediately without root or config check
Reorder startup: parse arguments before check_user() and config_load() so -h/--help short-circuits before any initialization. Exit code 0.
This commit is contained in:
parent
ce96fd6d93
commit
9ffb1d511f
1 changed files with 39 additions and 37 deletions
|
|
@ -303,8 +303,6 @@ int main(int argc, char* argv[])
|
|||
xce_cluster_config_t cluster_cfg = {0};
|
||||
int use_ha = 0; /* 1 when --peers given */
|
||||
|
||||
check_user();
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
struct sigaction sa;
|
||||
|
|
@ -356,41 +354,6 @@ int main(int argc, char* argv[])
|
|||
custom_config_path = strdup(DEFAULT_CONFIG_PATH);
|
||||
}
|
||||
|
||||
if (access(custom_config_path, F_OK) == 0) {
|
||||
|
||||
/* load config from custom file */
|
||||
config_result = config_load(custom_config_path);
|
||||
if (!config_result) {
|
||||
fprintf(stderr, "Failed to load config from %s\n",
|
||||
custom_config_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (config_result->error_code == CONFIG_SUCCESS) {
|
||||
if (config_result->config->controller_port > 0) {
|
||||
config.remote_port = config_result->config->controller_port;
|
||||
}
|
||||
|
||||
if (config_result->config->log_dir) {
|
||||
logdir = strdup(config_result->config->log_dir);
|
||||
}
|
||||
|
||||
if (config_result->config->log_level) {
|
||||
config.debug_level
|
||||
= level_to_int(config_result->config->log_level);
|
||||
}
|
||||
|
||||
if (config_result->config->management_list_count > 0) {
|
||||
config.remote_host
|
||||
= config_result->config->management_list[0].hostname;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Configuration file %s not found.\n",
|
||||
custom_config_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct option long_opts[] = {
|
||||
{ "peers", required_argument, NULL, OPT_PEERS },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
|
|
@ -450,8 +413,47 @@ int main(int argc, char* argv[])
|
|||
"[-h help]\n",
|
||||
argv[0]);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Performed after argument parsing so -h/--help exits immediately
|
||||
* without requiring root privileges or a configuration file. */
|
||||
check_user();
|
||||
|
||||
if (access(custom_config_path, F_OK) == 0) {
|
||||
|
||||
/* load config from custom file */
|
||||
config_result = config_load(custom_config_path);
|
||||
if (!config_result) {
|
||||
fprintf(stderr, "Failed to load config from %s\n",
|
||||
custom_config_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (config_result->error_code == CONFIG_SUCCESS) {
|
||||
if (config_result->config->controller_port > 0) {
|
||||
config.remote_port = config_result->config->controller_port;
|
||||
}
|
||||
|
||||
if (config_result->config->log_dir) {
|
||||
logdir = strdup(config_result->config->log_dir);
|
||||
}
|
||||
|
||||
if (config_result->config->log_level) {
|
||||
config.debug_level
|
||||
= level_to_int(config_result->config->log_level);
|
||||
}
|
||||
|
||||
if (config_result->config->management_list_count > 0) {
|
||||
config.remote_host
|
||||
= config_result->config->management_list[0].hostname;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Configuration file %s not found.\n",
|
||||
custom_config_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* P2.5-5: populate and validate xce_cluster_config_t when --peers given */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue