dovecot-1.2: lib-signals: Changed callback API to return siginfo_t.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 1 19:52:51 EEST 2009
details: http://hg.dovecot.org/dovecot-1.2/rev/9f3968f49ceb
changeset: 8882:9f3968f49ceb
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 01 12:52:46 2009 -0400
description:
lib-signals: Changed callback API to return siginfo_t.
diffstat:
14 files changed, 63 insertions(+), 53 deletions(-)
src/auth/auth-cache.c | 4 +--
src/auth/main.c | 6 ++--
src/auth/mech-winbind.c | 2 -
src/deliver/deliver.c | 6 ++--
src/dict/main.c | 6 ++--
src/imap/main.c | 6 ++--
src/lib/child-wait.c | 2 -
src/lib/lib-signals.c | 54 ++++++++++++++++++++++++++------------------
src/lib/lib-signals.h | 2 -
src/login-common/main.c | 6 ++--
src/master/child-process.c | 4 +--
src/master/main.c | 10 ++++----
src/pop3/main.c | 6 ++--
src/util/maildirlock.c | 2 -
diffs (truncated from 353 to 300 lines):
diff -r 774b0e8138bd -r 9f3968f49ceb src/auth/auth-cache.c
--- 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 @@ auth_cache_node_destroy(struct auth_cach
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 sig
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 -r 774b0e8138bd -r 9f3968f49ceb src/auth/main.c
--- 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 *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 -r 774b0e8138bd -r 9f3968f49ceb src/auth/mech-winbind.c
--- 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 @@ static void winbind_wait_pid(struct winb
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 -r 774b0e8138bd -r 9f3968f49ceb src/deliver/deliver.c
--- 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(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 -r 774b0e8138bd -r 9f3968f49ceb src/dict/main.c
--- 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 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 -r 774b0e8138bd -r 9f3968f49ceb src/imap/main.c
--- 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 @@ void (*hook_client_created)(struct clien
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 -r 774b0e8138bd -r 9f3968f49ceb src/lib/child-wait.c
--- 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 @@ void child_wait_remove_pid(struct child_
}
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 -r 774b0e8138bd -r 9f3968f49ceb src/lib/lib-signals.c
--- 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 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_UN
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));
-
- /* move them to mask first to avoid calling same handler
- multiple times */
+ if (ret % sizeof(siginfo_t) != 0)
+ i_fatal("read(sigpipe) returned partial data");
+ ret /= sizeof(siginfo_t);
+
+ /* 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, b
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
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 -r 774b0e8138bd -r 9f3968f49ceb src/lib/lib-signals.h
--- 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. */
diff -r 774b0e8138bd -r 9f3968f49ceb src/login-common/main.c
--- 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 @@ 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 -r 774b0e8138bd -r 9f3968f49ceb src/master/child-process.c
--- 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 @@ log_coredump(string_t *str, enum process
#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)
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 -r 774b0e8138bd -r 9f3968f49ceb src/master/main.c
--- 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 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)
More information about the dovecot-cvs
mailing list