]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-signals: Changed callback API to return siginfo_t.
authorTimo Sirainen <tss@iki.fi>
Wed, 1 Apr 2009 16:52:46 +0000 (12:52 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 1 Apr 2009 16:52:46 +0000 (12:52 -0400)
--HG--
branch : HEAD

14 files changed:
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

index cf7a6471240d27b170fc9300175166ee72fe1640..1b1192cee28e50b10546aa8fe5353299cb07e98c 100644 (file)
@@ -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;
index 0735c005c2ff230cc812da2c866c291cf66b094b..7bc8e313950d87e7d78949e7b55a76942c8627aa 100644 (file)
@@ -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);
 }
 
index 2579854730f13427b7125d14bb9235ac542da817..6a9b1867fbceb4e947c86a433b5b62d40d4f1f46 100644 (file)
@@ -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);
index 9f3b4b1aa659dbe9b2d2d802f4c3acefdf175543..619874ef25eada33c66004ba2e4f9257876e578b 100644 (file)
@@ -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);
 }
 
index 7666820e502d0ec2a3d84e8ea67021cf5cb23ad7..cca7894312a44b58ec07a9f44fa9b30afd5d6698 100644 (file)
@@ -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);
 }
 
index fae6a844a81a1549b0d940fc3483384dabf72db9..a154097c94b2ae716967308e6708cc8d00329ce2 100644 (file)
@@ -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);
 }
 
index d931d8713fe3c09c1e96bd34fd4f0beaea50cc1c..05afb542c19d100a2d7e927619bf1398f9d40857 100644 (file)
@@ -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;
 
index be271cb607b31ea8e6ec22baf0fc4e2dbbd5b301..787b4f8a308190569e680eec506cb83ba463df19 100644 (file)
@@ -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);
index ae9840531097991204045299f385cc5e8a8f52a4..59ff38c1f26467eaf821a1ba5e4d7d658d3f3a4c 100644 (file)
@@ -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. */
index 980f1abdeabdedf141768a282b0dfed08ff4805b..f88924ff0b520d4198d5afd825004a3dba22136a 100644 (file)
@@ -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);
 }
 
index c80c59352b4e1e3b35a72423f2d68c6353b3d429..383effa3b278bd017ebac036b3173c0e732fe39a 100644 (file)
@@ -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)
index 0b5c626bc7883bdddc337cc3746ab78d2f1c3eb9..a9aff73b1ea81a7eb0c267372dfe78a7bce70949 100644 (file)
@@ -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);
index 60c1ef9eb4cba2385ba87db11d853c9097817271..bcbf088d92d268e40ee989f48c8cd34e905cedb6 100644 (file)
@@ -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);
 }
 
index 98fa747682659b1dffc584f5d3342d150f842dac..c52bdb3ba880cc4c0d86417cba045f97e31d2c6e 100644 (file)
@@ -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);
 }