diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-25 15:49:18 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-25 15:49:18 +0100 |
commit | 9704de005f2278fc03155ae7d2ded89c78ed1e07 (patch) | |
tree | bdc71b3040eadc6e7f27b98d3c21d968a938ed59 /src/client | |
parent | f6dcca2291fab99aaa8ba711e801dacc1e9c5dd5 (diff) | |
download | rspamd-9704de005f2278fc03155ae7d2ded89c78ed1e07.tar.gz rspamd-9704de005f2278fc03155ae7d2ded89c78ed1e07.zip |
Wait for children before exit.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index b5b4a8042..b4d266bf0 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -60,6 +60,7 @@ static gboolean raw = FALSE; static gboolean extended_urls = FALSE; static gboolean mime_output = FALSE; static gchar *key = NULL; +static GList *children; static GOptionEntry entries[] = { @@ -925,13 +926,14 @@ rspamc_client_execute_cmd (struct rspamc_command *cmd, ucl_object_t *result, } if (!g_spawn_async_with_pipes (NULL, eargv, NULL, - G_SPAWN_SEARCH_PATH, NULL, NULL, &cld, + G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &cld, &infd, &outfd, &errfd, &err)) { rspamd_fprintf (stderr, "Cannot execute %s: %e", execute, err); g_error_free (err); } else { + children = g_list_prepend (children, GSIZE_TO_POINTER (cld)); out = fdopen (infd, "w"); if (result != NULL) { @@ -1134,12 +1136,15 @@ rspamc_process_dir (struct event_base *ev_base, struct rspamc_command *cmd, gint main (gint argc, gchar **argv, gchar **env) { - gint i, start_argc, cur_req = 0; + gint i, start_argc, cur_req = 0, res; GHashTable *kwattrs; + GList *cur; + GPid cld; struct rspamc_command *cmd; FILE *in = NULL; struct event_base *ev_base; struct stat st; + struct sigaction sigpipe_act; kwattrs = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); @@ -1155,6 +1160,13 @@ main (gint argc, gchar **argv, gchar **env) ev_base = event_init (); g_mime_init (0); + /* Ignore sigpipe */ + sigemptyset (&sigpipe_act.sa_mask); + sigaddset (&sigpipe_act.sa_mask, SIGPIPE); + sigpipe_act.sa_handler = SIG_IGN; + sigpipe_act.sa_flags = 0; + sigaction (SIGPIPE, &sigpipe_act, NULL); + /* Now read other args from argc and argv */ if (argc == 1) { start_argc = argc; @@ -1242,5 +1254,23 @@ main (gint argc, gchar **argv, gchar **env) g_hash_table_destroy (kwattrs); g_mime_shutdown (); + /* Wait for children processes */ + cur = g_list_first (children); + + while (cur) { + cld = GPOINTER_TO_SIZE (cur->data); + + if (waitpid (cld, &res, 0) == -1) { + fprintf (stderr, "Cannot wait for %d: %s", (gint)cld, + strerror (errno)); + } + + cur = g_list_next (cur); + } + + if (children != NULL) { + g_list_free (children); + } + return 0; } |