diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-12-22 16:18:14 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-12-22 16:18:14 +0000 |
commit | a7ff0a1da4682e42ceba957f3feb0697cda7519b (patch) | |
tree | 7332eaea6b3c28ed31372b9acad68442d977972c /src/main.c | |
parent | 7eb157330ce1c64bad55bd454055289c5ea5358d (diff) | |
download | rspamd-a7ff0a1da4682e42ceba957f3feb0697cda7519b.tar.gz rspamd-a7ff0a1da4682e42ceba957f3feb0697cda7519b.zip |
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
I will never ever use malloc in signal handler.
...
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c index b1d9d51ff..8b76af889 100644 --- a/src/main.c +++ b/src/main.c @@ -84,6 +84,11 @@ static gboolean is_insecure = FALSE; /* List of workers that are pending to start */ static GList *workers_pending = NULL; +#ifdef HAVE_SA_SIGINFO +static siginfo_t static_sg[64]; +static sig_atomic_t cur_sg = 0; +#endif + /* List of unrelated forked processes */ static GArray *other_workers = NULL; @@ -132,10 +137,10 @@ sig_handler (gint signo, siginfo_t *info, void *unused) #endif { #ifdef HAVE_SA_SIGINFO - siginfo_t *new_info; - new_info = g_malloc (sizeof (siginfo_t)); - memcpy (new_info, info, sizeof (siginfo_t)); - g_queue_push_head (signals_info, new_info); + if (cur_sg < (sig_atomic_t)G_N_ELEMENTS (static_sg)) { + memcpy (&static_sg[cur_sg++], info, sizeof (siginfo_t)); + } + /* XXX: discard more than 64 simultaneous signals */ #endif switch (signo) { @@ -196,7 +201,6 @@ print_signals_info (void) msg_info ("got signal: '%s'; received from pid: %P; uid: %ul", g_strsignal (inf->si_signo), inf->si_pid, (gulong)inf->si_uid); } - g_free (inf); } } #endif @@ -1401,6 +1405,10 @@ main (gint argc, gchar **argv, gchar **env) sigemptyset (&signals.sa_mask); sigsuspend (&signals.sa_mask); #ifdef HAVE_SA_SIGINFO + for (i = 0; i < cur_sg; i ++) { + g_queue_push_head (signals_info, &static_sg[i]); + } + cur_sg = 0; print_signals_info (); #endif if (do_terminate) { |