From 1937eac90de00ba64b7cd3fd51777c5b286e00b8 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 1 Aug 2018 12:37:33 +0100 Subject: [PATCH] [Minor] Fix option parsing in rspamadm --- src/rspamadm/rspamadm.c | 73 +++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 45a9171ed..9eeccb545 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -61,7 +61,7 @@ static GOptionEntry entries[] = { "Redefine UCL variable", NULL}, {"help", 'h', 0, G_OPTION_ARG_NONE, &show_help, "Show help", NULL}, - {"version", 'v', 0, G_OPTION_ARG_NONE, &show_version, + {"version", 'V', 0, G_OPTION_ARG_NONE, &show_version, "Show version", NULL}, {NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL} }; @@ -346,38 +346,6 @@ main (gint argc, gchar **argv, gchar **env) rspamadm_fill_internal_commands (all_commands); help_command.command_data = all_commands; - /* Setup logger */ - if (verbose) { - cfg->log_level = G_LOG_LEVEL_DEBUG; - } - else { - cfg->log_level = G_LOG_LEVEL_MESSAGE; - } - - cfg->log_type = RSPAMD_LOG_CONSOLE; - /* Avoid timestamps printing */ - cfg->log_flags = RSPAMD_LOG_FLAG_RSPAMADM; - rspamd_set_logger (cfg, process_quark, &rspamd_main->logger, - rspamd_main->server_pool); - (void) rspamd_log_open (rspamd_main->logger); - g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); - g_set_printerr_handler (rspamd_glib_printerr_function); - rspamd_config_post_load (cfg, - RSPAMD_CONFIG_INIT_LIBS|RSPAMD_CONFIG_INIT_URL|RSPAMD_CONFIG_INIT_NO_TLD); - - pworker = &workers[0]; - while (*pworker) { - /* Init string quarks */ - (void) g_quark_from_static_string ((*pworker)->name); - pworker++; - } - - cfg->compiled_modules = modules; - cfg->compiled_workers = workers; - - gperf_profiler_init (cfg, "rspamadm"); - setproctitle ("rspamdadm"); - /* Now read options and store everything till the first non-dash argument */ nargv = g_malloc0 (sizeof (gchar *) * (argc + 1)); nargv[0] = g_strdup (argv[0]); @@ -400,19 +368,52 @@ main (gint argc, gchar **argv, gchar **env) g_option_group_add_entries (og, entries); g_option_context_set_summary (context, "Summary:\n Rspamd administration utility version " - RVERSION - "\n Release id: " - RID); + RVERSION + "\n Release id: " + RID); g_option_context_set_main_group (context, og); targv = nargv; targc = nargc; + if (!g_option_context_parse (context, &targc, &targv, &error)) { fprintf (stderr, "option parsing failed: %s\n", error->message); g_error_free (error); exit (1); } + /* Setup logger */ + if (verbose) { + cfg->log_level = G_LOG_LEVEL_DEBUG; + } + else { + cfg->log_level = G_LOG_LEVEL_MESSAGE; + } + + cfg->log_type = RSPAMD_LOG_CONSOLE; + /* Avoid timestamps printing */ + cfg->log_flags = RSPAMD_LOG_FLAG_RSPAMADM; + rspamd_set_logger (cfg, process_quark, &rspamd_main->logger, + rspamd_main->server_pool); + (void) rspamd_log_open (rspamd_main->logger); + g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); + g_set_printerr_handler (rspamd_glib_printerr_function); + rspamd_config_post_load (cfg, + RSPAMD_CONFIG_INIT_LIBS|RSPAMD_CONFIG_INIT_URL|RSPAMD_CONFIG_INIT_NO_TLD); + + pworker = &workers[0]; + while (*pworker) { + /* Init string quarks */ + (void) g_quark_from_static_string ((*pworker)->name); + pworker++; + } + + cfg->compiled_modules = modules; + cfg->compiled_workers = workers; + + gperf_profiler_init (cfg, "rspamadm"); + setproctitle ("rspamdadm"); + L = cfg->lua_state; rspamd_lua_set_path (L, NULL, ucl_vars); rspamd_lua_set_globals (cfg, L, ucl_vars); -- 2.39.5