lua_pushvalue (L, -1);
/* Reference table itself */
lua_cmd->command_data = GINT_TO_POINTER (luaL_ref (L, LUA_REGISTRYINDEX));
- lua_cmd->flags |= RSPAMADM_FLAG_LUA;
+ lua_cmd->flags |= RSPAMADM_FLAG_LUA|RSPAMADM_FLAG_DYNAMIC;
lua_cmd->run = rspamadm_lua_command_run;
lua_cmd->help = rspamadm_lua_command_help;
-
g_ptr_array_add (dest, lua_cmd);
}
lua_settop (L, 0);
}
+
+ g_ptr_array_free (lua_paths, TRUE);
}
if (!g_option_context_parse (context, &argc, &argv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (config == NULL) {
if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) {
confdir = RSPAMD_CONFDIR;
pworker++;
}
- cfg->cache = rspamd_symcache_new (cfg);
cfg->compiled_modules = modules;
cfg->compiled_workers = workers;
cfg->cfg_name = config;
if (!g_option_context_parse (context, &argc, &argv, &error)) {
rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
pworker = &workers[0];
while (*pworker) {
/* Init string quarks */
if (!g_option_context_parse (context, &argc, &argv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (config == NULL) {
if ((confdir = g_hash_table_lookup (ucl_vars, "CONFDIR")) == NULL) {
confdir = RSPAMD_CONFDIR;
(void) g_quark_from_static_string ((*pworker)->name);
pworker++;
}
- cfg->cache = rspamd_symcache_new (cfg);
+
cfg->compiled_modules = modules;
cfg->compiled_workers = workers;
cfg->cfg_name = config;
ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
}
- if (ret && !rspamd_symcache_validate (rspamd_main->cfg->cache,
- rspamd_main->cfg,
+ if (ret && !rspamd_symcache_validate (cfg->cache,
+ cfg,
FALSE)) {
ret = FALSE;
}
if (!ret) {
exit (EXIT_FAILURE);
}
-
- exit (EXIT_SUCCESS);
}
if (!g_option_context_parse (context, &argc, &argv, &error)) {
rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (argc <= 1) {
rspamd_fprintf (stderr, "command required\n");
exit (1);
if (!g_option_context_parse (context, &argc, &argv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
rspamadm_dkim_generate_keypair (domain, selector, privkey_file, NULL, bits);
}
if (!g_option_context_parse (context, &argc, &argv, &error)) {
rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (!source_db) {
rspamd_fprintf (stderr, "source db is missing\n");
exit (1);
if (!g_option_context_parse (context, &argc, &argv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (batch == -1) {
if (isatty (STDIN_FILENO)) {
batch = 0;
if (!g_option_context_parse (context, &argc, &argv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (list) {
rspamadm_alg_list ();
exit (EXIT_SUCCESS);
lua_setglobal (L, "rspamadm_dns_resolver");
}
+static void
+rspamadm_cmd_dtor (gpointer p)
+{
+ struct rspamadm_command *cmd = (struct rspamadm_command *)p;
+
+ if (cmd->flags & RSPAMADM_FLAG_DYNAMIC) {
+ if (cmd->aliases) {
+ g_ptr_array_free (cmd->aliases, TRUE);
+ }
+
+ g_free ((gpointer)cmd->name);
+ g_free (cmd);
+ }
+}
+
gint
main (gint argc, gchar **argv, gchar **env)
{
const gchar *cmd_name;
const struct rspamadm_command *cmd;
struct rspamd_dns_resolver *resolver;
- GPtrArray *all_commands = g_ptr_array_new (); /* Discovered during check */
+ GPtrArray *all_commands = g_ptr_array_new_full (32,
+ rspamadm_cmd_dtor); /* Discovered during check */
gint i, nargc, targc;
worker_t **pworker;
gboolean lua_file = FALSE;
+ gint retcode = 0;
ucl_vars = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, g_free, g_free);
if (!g_option_context_parse (context, &targc, &targv, &error)) {
fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
/* Setup logger */
if (verbose) {
cfg->log_level = G_LOG_LEVEL_DEBUG;
rspamd_fprintf (stderr, "Cannot load lua environment: %e", error);
g_error_free (error);
- exit (EXIT_FAILURE);
+ goto end;
}
rspamd_lua_set_globals (cfg, L);
if (show_version) {
rspamadm_version ();
- exit (EXIT_SUCCESS);
+ goto end;
}
if (show_help) {
rspamadm_usage (context);
- exit (EXIT_SUCCESS);
+ goto end;
}
if (list_commands) {
rspamadm_commands (all_commands);
- exit (EXIT_SUCCESS);
+ goto end;
}
cmd_name = argv[nargc];
}
}
- exit (EXIT_FAILURE);
+ retcode = EXIT_FAILURE;
+ goto end;
}
if (nargc < argc) {
ev_break (rspamd_main->event_loop, EVBREAK_ALL);
-
+end:
+ rspamd_dns_resolver_deinit (resolver);
REF_RELEASE (rspamd_main->cfg);
rspamd_log_close (rspamd_main->logger, TRUE);
+ rspamd_url_deinit ();
g_free (rspamd_main);
g_ptr_array_free (all_commands, TRUE);
- return 0;
+ return retcode;
}
typedef void (*rspamadm_lua_exports_func) (gpointer lua_state);
-#define RSPAMADM_FLAG_NOHELP (1 << 0)
-#define RSPAMADM_FLAG_LUA (1 << 1)
+#define RSPAMADM_FLAG_NOHELP (1u << 0u)
+#define RSPAMADM_FLAG_LUA (1u << 1u)
+#define RSPAMADM_FLAG_DYNAMIC (1u << 2u)
struct rspamadm_command {
const gchar *name;
if (!g_option_context_parse (context, &argc, &argv, &error)) {
rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (openssl) {
mode = RSPAMD_CRYPTOBOX_MODE_NIST;
}
if (!g_option_context_parse (context, &argc, &argv, &error)) {
rspamd_fprintf (stderr, "option parsing failed: %s\n", error->message);
g_error_free (error);
+ g_option_context_free (context);
exit (1);
}
+ g_option_context_free (context);
+
if (config_file) {
/* Load config file, assuming that it has all information required */
struct ucl_parser *parser;