]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Unify `--var` argument for rspamd and rspamadm
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Mar 2019 16:47:59 +0000 (16:47 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Mar 2019 16:47:59 +0000 (16:47 +0000)
src/rspamadm/rspamadm.c
src/rspamd.c

index 227cbc86b43cdf1a0b6da956558d489fc20a116e..28169013224ebf4314719b9cf9a457cfcef363de 100644 (file)
@@ -60,7 +60,7 @@ static GOptionEntry entries[] = {
        {"list-commands", 'l', 0, G_OPTION_ARG_NONE, &list_commands,
                        "List available commands", NULL},
        {"var", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer)&rspamadm_parse_ucl_var,
-                       "Redefine UCL variable", NULL},
+                       "Redefine/define environment variable", NULL},
        {"help", 'h', 0, G_OPTION_ARG_NONE, &show_help,
                        "Show help", NULL},
        {"version", 'V', 0, G_OPTION_ARG_NONE, &show_version,
index 142915df90d7ab78cb39b74f6363e638d337a6e7..631759f05abb4a22a02a6815a47b4db0942c899c 100644 (file)
@@ -108,7 +108,10 @@ static GHashTable *listen_sockets = NULL;
 extern module_t *modules[];
 extern worker_t *workers[];
 
-/* Commandline options */
+/* Command line options */
+static gboolean rspamd_parse_var (const gchar *option_name,
+                                                                 const gchar *value, gpointer data,
+                                                                 GError **error);
 static GOptionEntry entries[] =
 {
        { "config-test", 't', 0, G_OPTION_ARG_NONE, &config_test,
@@ -141,9 +144,36 @@ static GOptionEntry entries[] =
          "controller password to store in the configuration file", NULL },
        { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
          "Show version and exit", NULL },
+       {"var", 0, 0, G_OPTION_ARG_CALLBACK, (gpointer)&rspamd_parse_var,
+                       "Redefine/define environment variable", NULL},
        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
 };
 
+static gboolean
+rspamd_parse_var (const gchar *option_name,
+                                               const gchar *value, gpointer data,
+                                               GError **error)
+{
+       gchar *k, *v, *t;
+
+       t = strchr (value, '=');
+
+       if (t != NULL) {
+               k = g_strdup (value);
+               t = k + (t - value);
+               v = g_strdup (t + 1);
+               *t = '\0';
+
+               g_hash_table_insert (ucl_vars, k, v);
+       }
+       else {
+               g_set_error (error, g_quark_try_string ("main"), EINVAL,
+                               "Bad variable format: %s", value);
+               return FALSE;
+       }
+
+       return TRUE;
+}
 
 static void
 read_cmd_line (gint *argc, gchar ***argv, struct rspamd_config *cfg)