diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-24 17:37:45 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-09-24 17:37:45 +0100 |
commit | 2845e192b02897996de2c1a0e65e11f7f268072a (patch) | |
tree | 0c41a3f45f0e92241c99ef532762f2f2a455e357 /src/rspamadm/rspamadm.c | |
parent | f267ddb5a7f2f2556b7a0c0751161f2f97bcae67 (diff) | |
download | rspamd-2845e192b02897996de2c1a0e65e11f7f268072a.tar.gz rspamd-2845e192b02897996de2c1a0e65e11f7f268072a.zip |
Improve passing of arguments to commands.
Diffstat (limited to 'src/rspamadm/rspamadm.c')
-rw-r--r-- | src/rspamadm/rspamadm.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 0a6ecc7d7..235eb0acc 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -88,7 +88,6 @@ rspamadm_usage (GOptionContext *context) static void rspamadm_commands (GOptionContext *context) { - gchar *help_str; const struct rspamadm_command **cmd; printf ("Rspamadm %s\n", RVERSION); @@ -179,10 +178,10 @@ main (gint argc, gchar **argv, gchar **env) struct rspamd_config *cfg; struct rspamd_main *rspamd_main; GQuark process_quark; - gchar **nargv; + gchar **nargv, **targv; const gchar *cmd_name; const struct rspamadm_command *cmd; - gint i, nargc; + gint i, nargc, targc; ucl_vars = g_hash_table_new_full (rspamd_strcase_hash, rspamd_strcase_equal, g_free, g_free); @@ -216,7 +215,7 @@ main (gint argc, gchar **argv, gchar **env) setproctitle ("rspamdadm"); /* Now read options and store everything till the first non-dash argument */ - nargv = g_slice_alloc0 (sizeof (gchar *) * (argc + 1)); + nargv = g_malloc0 (sizeof (gchar *) * (argc + 1)); nargv[0] = g_strdup (argv[0]); for (i = 1, nargc = 1; i < argc; i ++) { @@ -242,12 +241,16 @@ main (gint argc, gchar **argv, gchar **env) RID); g_option_context_set_main_group (context, og); - if (!g_option_context_parse (context, &nargc, &nargv, &error)) { + 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); } + g_strfreev (nargv); + if (show_version) { rspamadm_version (); } @@ -272,7 +275,17 @@ main (gint argc, gchar **argv, gchar **env) } if (nargc < argc) { - cmd->run (argc - nargc - 1, &argv[nargc]); + nargv = g_malloc0 (sizeof (gchar *) * (argc - nargc + 1)); + nargv[0] = g_strdup_printf ("%s %s", argv[0], cmd_name); + + for (i = 1; i < argc - nargc; i ++) { + nargv[i] = g_strdup (argv[i + nargc]); + } + + targc = argc - nargc - 1; + targv = nargv; + cmd->run (targc, targv); + g_strfreev (nargv); } else { cmd->run (0, NULL); |