From: Timo Sirainen Date: Wed, 1 Apr 2009 16:52:46 +0000 (-0400) Subject: lib-signals: Changed callback API to return siginfo_t. X-Git-Tag: 1.2.rc1~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1c7fa51b35231f375998f66d5756f214519218f8;p=thirdparty%2Fdovecot%2Fcore.git lib-signals: Changed callback API to return siginfo_t. --HG-- branch : HEAD --- diff --git a/src/auth/auth-cache.c b/src/auth/auth-cache.c index cf7a647124..1b1192cee2 100644 --- a/src/auth/auth-cache.c +++ b/src/auth/auth-cache.c @@ -92,7 +92,7 @@ auth_cache_node_destroy(struct auth_cache *cache, struct auth_cache_node *node) 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 @@ static void sig_auth_cache_clear(int signo ATTR_UNUSED, void *context) 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; diff --git a/src/auth/main.c b/src/auth/main.c index 0735c005c2..7bc8e31395 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -38,12 +38,12 @@ static struct module *modules = NULL; 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); } diff --git a/src/auth/mech-winbind.c b/src/auth/mech-winbind.c index 2579854730..6a9b1867fb 100644 --- a/src/auth/mech-winbind.c +++ b/src/auth/mech-winbind.c @@ -88,7 +88,7 @@ static void winbind_wait_pid(struct winbind_helper *winbind) 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); diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index 9f3b4b1aa6..619874ef25 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -70,12 +70,12 @@ static pool_t plugin_pool; 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); } diff --git a/src/dict/main.c b/src/dict/main.c index 7666820e50..cca7894312 100644 --- a/src/dict/main.c +++ b/src/dict/main.c @@ -23,12 +23,12 @@ static struct io *log_io; 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); } diff --git a/src/imap/main.c b/src/imap/main.c index fae6a844a8..a154097c94 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -52,12 +52,12 @@ void (*hook_client_created)(struct client **client) = NULL; 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); } diff --git a/src/lib/child-wait.c b/src/lib/child-wait.c index d931d8713f..05afb542c1 100644 --- a/src/lib/child-wait.c +++ b/src/lib/child-wait.c @@ -69,7 +69,7 @@ void child_wait_remove_pid(struct child_wait *wait, pid_t pid) } 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; diff --git a/src/lib/lib-signals.c b/src/lib/lib-signals.c index be271cb607..787b4f8a30 100644 --- a/src/lib/lib-signals.c +++ b/src/lib/lib-signals.c @@ -27,7 +27,7 @@ static int sig_pipe_fd[2] = { -1, -1 }; 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 @@ static void sig_handler(int signo) 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_handler(int signo) } } -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 sig_ignore(int signo ATTR_UNUSED) 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 @@ static void lib_signals_set(int signo, bool ignore) 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 @@ void lib_signals_ignore(int signo, bool restart_syscalls) 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); diff --git a/src/lib/lib-signals.h b/src/lib/lib-signals.h index ae98405310..59ff38c1f2 100644 --- a/src/lib/lib-signals.h +++ b/src/lib/lib-signals.h @@ -3,7 +3,7 @@ #include -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. */ diff --git a/src/login-common/main.c b/src/login-common/main.c index 980f1abdea..f88924ff0b 100644 --- a/src/login-common/main.c +++ b/src/login-common/main.c @@ -67,12 +67,12 @@ void main_unref(void) } } -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); } diff --git a/src/master/child-process.c b/src/master/child-process.c index c80c59352b..383effa3b2 100644 --- a/src/master/child-process.c +++ b/src/master/child-process.c @@ -176,7 +176,7 @@ log_coredump(string_t *str, enum process_type process_type, int status) #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_init(void) 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) diff --git a/src/master/main.c b/src/master/main.c index 0b5c626bc7..a9aff73b1e 100644 --- a/src/master/main.c +++ b/src/master/main.c @@ -166,22 +166,22 @@ static void settings_reload(void) } } -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); diff --git a/src/pop3/main.c b/src/pop3/main.c index 60c1ef9eb4..bcbf088d92 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -52,12 +52,12 @@ bool lock_session = FALSE; 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); } diff --git a/src/util/maildirlock.c b/src/util/maildirlock.c index 98fa747682..c52bdb3ba8 100644 --- a/src/util/maildirlock.c +++ b/src/util/maildirlock.c @@ -24,7 +24,7 @@ static struct dotlock_settings dotlock_settings = { 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); }