]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix option parsing in rspamadm
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 1 Aug 2018 11:37:33 +0000 (12:37 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 1 Aug 2018 11:37:52 +0000 (12:37 +0100)
src/rspamadm/rspamadm.c

index 45a9171ed918ea955c86d74957d42c760fda63d1..9eeccb5453f9ddb609e43173389fff245c556e27 100644 (file)
@@ -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);