diff --git a/src/worker/src/main.c b/src/worker/src/main.c index 6ea6cc98..857e0a1c 100644 --- a/src/worker/src/main.c +++ b/src/worker/src/main.c @@ -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 */