X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=sig.c;h=99d3dd34d7ca20c1018e8984d2a362906e07a42a;hp=2f6f7ddb30ac13e531d9847134a0c9606ed315e0;hb=fafaa26953e4f452c6b91de4e24ec5ad2a8f6700;hpb=f33cf243ae1cb5657cccb7c43c99093936093b4a diff --git a/sig.c b/sig.c index 2f6f7dd..99d3dd3 100644 --- a/sig.c +++ b/sig.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2010 Andre Noll + * Copyright (C) 2004-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -64,12 +64,27 @@ err_out: exit(EXIT_FAILURE); } -/* - * just write one integer to signal pipe - */ +/* Write the signal number to the signal pipe, abort on errors. */ static void generic_signal_handler(int s) { - write(signal_pipe[1], &s, sizeof(int)); + /* + * Signal handlers that make system calls must save a copy of errno on + * entry to the handler and restore it on exit, to prevent the + * possibility of overwriting a errno value that had previously been + * set in the main program. + */ + int save_errno = errno; + ssize_t ret = write(signal_pipe[1], &s, sizeof(int)); + + if (ret == sizeof(int)) { + errno = save_errno; + return; + } + if (ret < 0) + DSS_EMERG_LOG(("%s\n", strerror(errno))); + else + DSS_EMERG_LOG(("short write to signal pipe\n")); + exit(EXIT_FAILURE); } /**