diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-08-23 03:30:46 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-08-23 03:30:46 +0200 |
commit | 3d652087604ca1c6a66d9fa319645aeec1cf1b7b (patch) | |
tree | 0c54c322b6f053bdb4e898b6683c8190922f3539 | |
parent | m + colour on selected items in lists and tables (diff) | |
download | mds-3d652087604ca1c6a66d9fa319645aeec1cf1b7b.tar.gz mds-3d652087604ca1c6a66d9fa319645aeec1cf1b7b.tar.bz2 mds-3d652087604ca1c6a66d9fa319645aeec1cf1b7b.tar.xz |
signal handlers that return should not modify errno
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | doc/info/mds.texinfo | 22 | ||||
-rw-r--r-- | src/libmdsserver/macros.h | 17 | ||||
-rw-r--r-- | src/mds-base.c | 6 | ||||
-rw-r--r-- | src/mds-clipboard.c | 2 | ||||
-rw-r--r-- | src/mds-colour.c | 2 | ||||
-rw-r--r-- | src/mds-echo.c | 2 | ||||
-rw-r--r-- | src/mds-kkbd.c | 2 | ||||
-rw-r--r-- | src/mds-respawn.c | 4 | ||||
-rw-r--r-- | src/mds-vt.c | 4 |
9 files changed, 61 insertions, 0 deletions
diff --git a/doc/info/mds.texinfo b/doc/info/mds.texinfo index 03b2a1a..b2f1192 100644 --- a/doc/info/mds.texinfo +++ b/doc/info/mds.texinfo @@ -6460,6 +6460,28 @@ if no error occurs@footnote{@code{glibc} will not clear will be defined.}, and creates the alias @code{CLOCK_MONOTONIC_RAW} for @code{CLOCK_MONOTONIC} unless @code{CLOCK_MONOTONIC_RAW} is already defined. +The header file also ensure that all aliases for socket +protocol families and address families, for all definied +protocol families and address families. + +The header file @file{<libmdsserver/macros.h>}, also +provides to macros to help write signal handlers. +@table @code +@item SIGHANDLER_START +Normal signal handlers should place this macro +at the top of the function. It will save the value +of @code{errno}. +@item SIGHANDLER_END +Normal signal handlers should place this macro +at the bottom of the function, or just before +any @code{return}. It will restore the value of +@code{errno} saved by @code{SIGHANDLER_START}. +@end table +These macros should be used, because signal handlers +should not modify @code{errno}. The one occasion where +exiting a signal handler with a modified @code{errno} +is acceptable, is when the signal handler exits the +program without returning. diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index 89db22f..f17da94 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -752,5 +752,22 @@ #endif +/** + * Normal signal handlers should place this macro + * at the top of the function + */ +#define SIGHANDLER_START \ + int sighandler_saved_errno = errno + + +/** + * Normal signal handlers should place this macro + * at the bottom of the function, or just before + * any `return` + */ +#define SIGHANDLER_END \ + (errno = sighandler_saved_errno) + + #endif diff --git a/src/mds-base.c b/src/mds-base.c index 2220003..e9c7c8b 100644 --- a/src/mds-base.c +++ b/src/mds-base.c @@ -334,6 +334,7 @@ static void __attribute__((const)) received_noop(int signo) */ void __attribute__((weak)) received_reexec(int signo) { + SIGHANDLER_START; (void) signo; if (reexecing == 0) { @@ -341,6 +342,7 @@ void __attribute__((weak)) received_reexec(int signo) eprint("re-exec signal received."); signal_all(signo); } + SIGHANDLER_END; } @@ -354,6 +356,7 @@ void __attribute__((weak)) received_reexec(int signo) */ void __attribute__((weak)) received_terminate(int signo) { + SIGHANDLER_START; (void) signo; if (terminating == 0) { @@ -361,6 +364,7 @@ void __attribute__((weak)) received_terminate(int signo) eprint("terminate signal received."); signal_all(signo); } + SIGHANDLER_END; } @@ -375,12 +379,14 @@ void __attribute__((weak)) received_terminate(int signo) */ void __attribute__((weak)) received_danger(int signo) { + SIGHANDLER_START; (void) signo; if (danger == 0) { danger = 1; eprint("danger signal received."); } + SIGHANDLER_END; } diff --git a/src/mds-clipboard.c b/src/mds-clipboard.c index cbfed79..6c0a2ed 100644 --- a/src/mds-clipboard.c +++ b/src/mds-clipboard.c @@ -899,6 +899,7 @@ int clipboard_get_size(int level, const char* recv_client_id, const char* recv_m */ void received_info(int signo) { + SIGHANDLER_START; clipitem_t clipitem; size_t i, j, n; struct timespec now; @@ -937,5 +938,6 @@ void received_info(int signo) clipitem.content); } } + SIGHANDLER_END; } diff --git a/src/mds-colour.c b/src/mds-colour.c index c5151dc..b4b166d 100644 --- a/src/mds-colour.c +++ b/src/mds-colour.c @@ -477,6 +477,7 @@ int handle_set_colour(const char* recv_name, const char* recv_remove, const char */ void received_info(int signo) { + SIGHANDLER_START; size_t i; colour_list_entry_t* entry; (void) signo; @@ -489,6 +490,7 @@ void received_info(int signo) entry->value.bytes, entry->value.red, entry->value.green, entry->value.blue, entry->key_hash, entry->key); iprint("END DEFINED COLOURS"); + SIGHANDLER_END; } diff --git a/src/mds-echo.c b/src/mds-echo.c index a531812..c434656 100644 --- a/src/mds-echo.c +++ b/src/mds-echo.c @@ -351,9 +351,11 @@ int echo_message(void) */ void received_info(int signo) { + SIGHANDLER_START; (void) signo; iprintf("next message ID: %" PRIu32, message_id); iprintf("connected: %s", connected ? "yes" : "no"); iprintf("echo buffer size: %zu bytes", echo_buffer_size); + SIGHANDLER_END; } diff --git a/src/mds-kkbd.c b/src/mds-kkbd.c index 284c56b..1088385 100644 --- a/src/mds-kkbd.c +++ b/src/mds-kkbd.c @@ -1730,6 +1730,7 @@ void shrink_map(void) */ void received_info(int signo) { + SIGHANDLER_START; size_t i; (void) signo; iprintf("next message ID: %" PRIu32, message_id); @@ -1746,5 +1747,6 @@ void received_info(int signo) for (i = 0; i < mapping_size; i++) if ((int)i != mapping[i]) iprintf(" %zu -> %i", i, mapping[i]); + SIGHANDLER_END; } diff --git a/src/mds-respawn.c b/src/mds-respawn.c index 785eb67..0b68d08 100644 --- a/src/mds-respawn.c +++ b/src/mds-respawn.c @@ -225,9 +225,11 @@ static void spawn_server(size_t index) */ static void received_revive(int signo) { + SIGHANDLER_START; (void) signo; reviving = 1; eprint("revive signal received."); + SIGHANDLER_END; } @@ -545,6 +547,7 @@ int master_loop(void) */ void received_info(int signo) { + SIGHANDLER_START; server_state_t state; size_t i, n = servers; char** cmdline; @@ -577,5 +580,6 @@ void received_info(int signo) while (*cmdline) iprintf(" %z", *cmdline++); } + SIGHANDLER_END; } diff --git a/src/mds-vt.c b/src/mds-vt.c index 2449aba..0264904 100644 --- a/src/mds-vt.c +++ b/src/mds-vt.c @@ -716,8 +716,10 @@ void signal_all(int signo) */ void received_switch_vt(int signo) { + SIGHANDLER_START; int leaving = signo == (SIGRTMIN + 2); switching_vt = leaving ? 1 : -1; + SIGHANDLER_END; } @@ -881,6 +883,7 @@ void vt_construct_mode(int vt_switch_control, int vt_leave_signal, */ void received_info(int signo) { + SIGHANDLER_START; (void) signo; iprintf("next message ID: %" PRIu32, message_id); iprintf("connected: %s", connected ? "yes" : "no"); @@ -896,5 +899,6 @@ void received_info(int signo) iprintf("secondary thread started: %s", secondary_thread_started ? "yes" : "no"); iprintf("secondary thread failed: %s", secondary_thread_failed ? "yes" : "no"); iprintf("non-exclusive counter: %zi", nonexclusive_counter); + SIGHANDLER_END; } |