# HG changeset patch # User Timo Sirainen # Date 1146696878 -10800 # Node ID 5bc987dc62a86c24df834d0b6d1d89457e48c670 # Parent a767dd4fafb04ab3f7f20895c934cec045166d69 Added lib_signals_ignore_signal() and made lib_signals_set_handler() with NULL handler not restart syscall. diff -r a767dd4fafb0 -r 5bc987dc62a8 src/lib/lib-signals.c --- a/src/lib/lib-signals.c Thu May 04 01:02:55 2006 +0300 +++ b/src/lib/lib-signals.c Thu May 04 01:54:38 2006 +0300 @@ -51,6 +51,10 @@ } } +static void sig_ignore(int signo __attr_unused__) +{ +} + static void signal_read(void *context __attr_unused__) { unsigned char signal_buf[512]; @@ -110,7 +114,7 @@ if (sigemptyset(&act.sa_mask) < 0) i_fatal("sigemptyset(): %m"); act.sa_flags = 0; - act.sa_handler = handler != NULL ? sig_handler : SIG_IGN; + act.sa_handler = handler != NULL ? sig_handler : sig_ignore; if (sigaction(signo, &act, NULL) < 0) i_fatal("sigaction(%d): %m", signo); @@ -140,6 +144,26 @@ signal_handlers[signo] = h; } +void lib_signals_ignore_signal(int signo) +{ + struct sigaction act; + + if (signo < 0 || signo > MAX_SIGNAL_VALUE) { + i_panic("Trying to ignore signal %d, but max is %d", + signo, MAX_SIGNAL_VALUE); + } + + i_assert(signal_handlers[signo] == NULL); + + if (sigemptyset(&act.sa_mask) < 0) + i_fatal("sigemptyset(): %m"); + act.sa_flags = SA_RESTART; + act.sa_handler = SIG_IGN; + + if (sigaction(signo, &act, NULL) < 0) + i_fatal("sigaction(%d): %m", signo); +} + void lib_signals_unset_handler(int signo, signal_handler_t *handler, void *context) { diff -r a767dd4fafb0 -r 5bc987dc62a8 src/lib/lib-signals.h --- a/src/lib/lib-signals.h Thu May 04 01:02:55 2006 +0300 +++ b/src/lib/lib-signals.h Thu May 04 01:54:38 2006 +0300 @@ -10,6 +10,9 @@ the signal is ignored. */ void lib_signals_set_handler(int signo, bool delayed, signal_handler_t *handler, void *context); +/* Ignore given signal. The difference to lib_signals_set_handler() with NULL + handler is that this function tries to restart the system calls. */ +void lib_signals_ignore_signal(int signo); void lib_signals_unset_handler(int signo, signal_handler_t *handler, void *context);