Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8882:9f3968f49ceb HEAD
lib-signals: Changed callback API to return siginfo_t.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 01 Apr 2009 12:52:46 -0400 |
parents | 774b0e8138bd |
children | 5361cb6afe9e |
files | src/auth/auth-cache.c src/auth/main.c src/auth/mech-winbind.c src/deliver/deliver.c src/dict/main.c src/imap/main.c src/lib/child-wait.c src/lib/lib-signals.c src/lib/lib-signals.h src/login-common/main.c src/master/child-process.c src/master/main.c src/pop3/main.c src/util/maildirlock.c |
diffstat | 14 files changed, 61 insertions(+), 51 deletions(-) [+] |
line wrap: on
line diff
--- a/src/auth/auth-cache.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/auth/auth-cache.c Wed Apr 01 12:52:46 2009 -0400 @@ -92,7 +92,7 @@ i_free(node); } -static void sig_auth_cache_clear(int signo ATTR_UNUSED, void *context) +static void sig_auth_cache_clear(const siginfo_t *si ATTR_UNUSED, void *context) { struct auth_cache *cache = context; @@ -100,7 +100,7 @@ auth_cache_clear(cache); } -static void sig_auth_cache_stats(int signo ATTR_UNUSED, void *context) +static void sig_auth_cache_stats(const siginfo_t *si ATTR_UNUSED, void *context) { struct auth_cache *cache = context; unsigned int total_count;
--- a/src/auth/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/auth/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -38,12 +38,12 @@ static struct auth *auth; static struct auth_worker_client *worker_client; -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); }
--- a/src/auth/mech-winbind.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/auth/mech-winbind.c Wed Apr 01 12:52:46 2009 -0400 @@ -88,7 +88,7 @@ winbind->pid = -1; } -static void sigchld_handler(int signo ATTR_UNUSED, +static void sigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { winbind_wait_pid(&winbind_ntlm_context);
--- a/src/deliver/deliver.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/deliver/deliver.c Wed Apr 01 12:52:46 2009 -0400 @@ -70,12 +70,12 @@ static ARRAY_DEFINE(lda_envs, const char *); static ARRAY_DEFINE(plugin_envs, const char *); -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(current_ioloop); }
--- a/src/dict/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/dict/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -23,12 +23,12 @@ static struct module *modules; static struct dict_server *dict_server; -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); }
--- a/src/imap/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/imap/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -52,12 +52,12 @@ string_t *capability_string; -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); }
--- a/src/lib/child-wait.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/lib/child-wait.c Wed Apr 01 12:52:46 2009 -0400 @@ -69,7 +69,7 @@ } static void -sigchld_handler(int signo ATTR_UNUSED, void *context ATTR_UNUSED) +sigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { struct child_wait_status status;
--- a/src/lib/lib-signals.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/lib/lib-signals.c Wed Apr 01 12:52:46 2009 -0400 @@ -27,7 +27,7 @@ static bool signals_initialized = FALSE; static struct io *io_sig = NULL; -static void sig_handler(int signo) +static void sig_handler(int signo, siginfo_t *si, void *context ATTR_UNUSED) { struct signal_handler *h; bool delayed_sent = FALSE; @@ -39,12 +39,12 @@ called at any time. don't do anything that's unsafe. */ for (h = signal_handlers[signo]; h != NULL; h = h->next) { if (!h->delayed) - h->handler(signo, h->context); + h->handler(si, h->context); else if (!delayed_sent) { int saved_errno = errno; - unsigned char signo_byte = signo; - if (write(sig_pipe_fd[1], &signo_byte, 1) != 1) + if (write(sig_pipe_fd[1], si, + sizeof(*si)) != sizeof(*si)) i_error("write(sigpipe) failed: %m"); delayed_sent = TRUE; errno = saved_errno; @@ -52,7 +52,8 @@ } } -static void sig_ignore(int signo ATTR_UNUSED) +static void sig_ignore(int signo ATTR_UNUSED, siginfo_t *si ATTR_UNUSED, + void *context ATTR_UNUSED) { /* if we used SIG_IGN instead of this function, the system call might be restarted */ @@ -60,35 +61,39 @@ static void signal_read(void *context ATTR_UNUSED) { - unsigned char signal_buf[512]; - unsigned char signal_mask[MAX_SIGNAL_VALUE+1]; + siginfo_t signal_buf[10]; + siginfo_t signals[MAX_SIGNAL_VALUE+1]; ssize_t i, ret; - unsigned int signo; + int signo; ret = read(sig_pipe_fd[0], signal_buf, sizeof(signal_buf)); if (ret > 0) { - memset(signal_mask, 0, sizeof(signal_mask)); + if (ret % sizeof(siginfo_t) != 0) + i_fatal("read(sigpipe) returned partial data"); + ret /= sizeof(siginfo_t); - /* move them to mask first to avoid calling same handler - multiple times */ + /* get rid of duplicate signals */ + memset(signals, 0, sizeof(signals)); for (i = 0; i < ret; i++) { - signo = signal_buf[i]; + signo = signal_buf[i].si_signo; if (signo > MAX_SIGNAL_VALUE) { i_panic("sigpipe contains signal %d > %d", signo, MAX_SIGNAL_VALUE); } - signal_mask[signo] = 1; + signals[signo] = signal_buf[i]; } /* call the delayed handlers */ for (signo = 0; signo < MAX_SIGNAL_VALUE; signo++) { - if (signal_mask[signo] > 0) { + if (signals[signo].si_signo > 0) { struct signal_handler *h = signal_handlers[signo]; for (; h != NULL; h = h->next) { - if (h->delayed) - h->handler(signo, h->context); + if (h->delayed) { + h->handler(&signals[signo], + h->context); + } } } } @@ -106,8 +111,8 @@ if (sigemptyset(&act.sa_mask) < 0) i_fatal("sigemptyset(): %m"); - act.sa_flags = 0; - act.sa_handler = ignore ? sig_ignore : sig_handler; + act.sa_flags = SA_SIGINFO; + act.sa_sigaction = ignore ? sig_ignore : sig_handler; if (sigaction(signo, &act, NULL) < 0) i_fatal("sigaction(%d): %m", signo); } @@ -162,8 +167,13 @@ if (sigemptyset(&act.sa_mask) < 0) i_fatal("sigemptyset(): %m"); - act.sa_flags = restart_syscalls ? SA_RESTART : 0; - act.sa_handler = restart_syscalls ? SIG_IGN : sig_ignore; + if (restart_syscalls) { + act.sa_flags = SA_RESTART; + act.sa_handler = SIG_IGN; + } else { + act.sa_flags = SA_SIGINFO; + act.sa_sigaction = sig_ignore; + } if (sigaction(signo, &act, NULL) < 0) i_fatal("sigaction(%d): %m", signo);
--- a/src/lib/lib-signals.h Wed Apr 01 12:48:17 2009 -0400 +++ b/src/lib/lib-signals.h Wed Apr 01 12:52:46 2009 -0400 @@ -3,7 +3,7 @@ #include <signal.h> -typedef void signal_handler_t(int signo, void *context); +typedef void signal_handler_t(const siginfo_t *si, void *context); /* Set signal handler for specific signal. If delayed is TRUE, the handler will be called later, ie. not as a real signal handler. */
--- a/src/login-common/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/login-common/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -67,12 +67,12 @@ } } -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); }
--- a/src/master/child-process.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/master/child-process.c Wed Apr 01 12:52:46 2009 -0400 @@ -176,7 +176,7 @@ #endif } -static void sigchld_handler(int signo ATTR_UNUSED, +static void sigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { struct child_process *process; @@ -272,7 +272,7 @@ void child_processes_flush(void) { /* make sure we log if child processes died unexpectedly */ - sigchld_handler(SIGCHLD, NULL); + sigchld_handler(NULL, NULL); } void child_processes_deinit(void)
--- a/src/master/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/master/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -166,22 +166,22 @@ } } -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); } -static void sig_reload_settings(int signo ATTR_UNUSED, +static void sig_reload_settings(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { settings_reload(); } -static void sig_reopen_logs(int signo ATTR_UNUSED, +static void sig_reopen_logs(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { set_logfile(settings_root->defaults);
--- a/src/pop3/main.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/pop3/main.c Wed Apr 01 12:52:46 2009 -0400 @@ -52,12 +52,12 @@ const char *uidl_format, *logout_format; enum uidl_keys uidl_keymask; -static void sig_die(int signo, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) { /* warn about being killed because of some signal, except SIGINT (^C) which is too common at least while testing :) */ - if (signo != SIGINT) - i_warning("Killed with signal %d", signo); + if (si->si_signo != SIGINT) + i_warning("Killed with signal %d", si->si_signo); io_loop_stop(ioloop); }
--- a/src/util/maildirlock.c Wed Apr 01 12:48:17 2009 -0400 +++ b/src/util/maildirlock.c Wed Apr 01 12:52:46 2009 -0400 @@ -24,7 +24,7 @@ static struct ioloop *ioloop; -static void sig_die(int signo ATTR_UNUSED, void *context ATTR_UNUSED) +static void sig_die(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED) { io_loop_stop(ioloop); }