X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=signal.c;h=972d9d129a03f8060cda1a8dd2d98e3b181b2875;hp=b2317c9b3a51fefca4c490681424a2f8709563b2;hb=42ddd68159d7eff0f3e7c225665c97f9abd59425;hpb=8c24d4e777f21a8773adfd028af26b967d1880ec diff --git a/signal.c b/signal.c index b2317c9b..972d9d12 100644 --- a/signal.c +++ b/signal.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004-2012 Andre Noll + * Copyright (C) 2004-2014 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -11,6 +11,9 @@ #include "para.h" #include "error.h" #include "fd.h" +#include "list.h" +#include "sched.h" +#include "signal.h" static int signal_pipe[2]; @@ -51,15 +54,22 @@ err_out: exit(EXIT_FAILURE); } -/* - * just write one integer to signal pipe - */ +/* Write the signal number to signal pipe. */ static void generic_signal_handler(int s) { + /* + * 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)) + if (ret == sizeof(int)) { + errno = save_errno; return; + } if (ret < 0) PARA_EMERG_LOG("%s\n", strerror(errno)); else