# HG changeset patch # User Bruno Haible # Date 1317163744 -7200 # Node ID 13eba3ca057f7a7a7ef120cf09f86bbec2845048 # Parent 4e6468fa3ee86318b3f4ec1c9d7d5a2b6cd699dc raise: Fix double declaration with modules 'sigprocmask' and 'sigpipe'. * lib/signal.in.h (GNULIB_defined_signal_blocking): New macro. (raise): Remove older, duplicated declaration. (_gl_raise_SIGPIPE): New declaration. * lib/sigprocmask.c (_gl_raise_SIGPIPE): New function. (rpl_raise): Remove function. * lib/raise.c (rpl_raise, raise): Merge into a single function. Handle a gnulib-defined SIGPIPE here. * m4/raise.m4 (gl_FUNC_RAISE): Set REPLACE_RAISE also if the module 'sigprocmask' has detected missing signal-blocking and the module 'sigpipe' is enabled. Reported by Tatsuro MATSUOKA . diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-09-26 Bruno Haible + + raise: Fix double declaration with modules 'sigprocmask' and 'sigpipe'. + * lib/signal.in.h (GNULIB_defined_signal_blocking): New macro. + (raise): Remove older, duplicated declaration. + (_gl_raise_SIGPIPE): New declaration. + * lib/sigprocmask.c (_gl_raise_SIGPIPE): New function. + (rpl_raise): Remove function. + * lib/raise.c (rpl_raise, raise): Merge into a single function. Handle + a gnulib-defined SIGPIPE here. + * m4/raise.m4 (gl_FUNC_RAISE): Set REPLACE_RAISE also if the module + 'sigprocmask' has detected missing signal-blocking and the module + 'sigpipe' is enabled. + Reported by Tatsuro MATSUOKA . + 2011-09-26 Gijs van Tulder base64-tests: avoid memory leak diff --git a/lib/raise.c b/lib/raise.c --- a/lib/raise.c +++ b/lib/raise.c @@ -50,24 +50,30 @@ return result; } -# define raise raise_nothrow +# else +# define raise_nothrow raise # endif -int -rpl_raise (int sig) -{ - return raise_nothrow (sig); -} - #else /* An old Unix platform. */ # include -int -raise (int sig) -{ - return kill (getpid (), sig); -} +# define rpl_raise raise #endif + +int +rpl_raise (int sig) +{ +#if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE + if (sig == SIGPIPE) + return _gl_raise_SIGPIPE (); +#endif + +#if HAVE_RAISE + return raise_nothrow (sig); +#else + return kill (getpid (), sig); +#endif +} diff --git a/lib/signal.in.h b/lib/signal.in.h --- a/lib/signal.in.h +++ b/lib/signal.in.h @@ -178,6 +178,10 @@ #if @GNULIB_SIGPROCMASK@ # if !@HAVE_POSIX_SIGNALBLOCKING@ +# ifndef GNULIB_defined_signal_blocking +# define GNULIB_defined_signal_blocking 1 +# endif + /* Maximum signal number + 1. */ # ifndef NSIG # define NSIG 32 @@ -303,18 +307,10 @@ # endif _GL_CXXALIASWARN (signal); -/* Raise signal SIG. */ # if !@HAVE_POSIX_SIGNALBLOCKING@ && GNULIB_defined_SIGPIPE -# if !(defined __cplusplus && defined GNULIB_NAMESPACE) -# undef raise -# define raise rpl_raise -# endif -_GL_FUNCDECL_RPL (raise, int, (int sig)); -_GL_CXXALIAS_RPL (raise, int, (int sig)); -# else -_GL_CXXALIAS_SYS (raise, int, (int sig)); +/* Raise signal SIGPIPE. */ +_GL_EXTERN_C int _gl_raise_SIGPIPE (void); # endif -_GL_CXXALIASWARN (raise); #elif defined GNULIB_POSIXCHECK # undef sigaddset diff --git a/lib/sigprocmask.c b/lib/sigprocmask.c --- a/lib/sigprocmask.c +++ b/lib/sigprocmask.c @@ -330,27 +330,19 @@ } #if GNULIB_defined_SIGPIPE -/* Raise the signal SIG. */ +/* Raise the signal SIGPIPE. */ int -rpl_raise (int sig) -# undef raise +_gl_raise_SIGPIPE (void) { - switch (sig) + if (blocked_set & (1U << SIGPIPE)) + pending_array[SIGPIPE] = 1; + else { - case SIGPIPE: - if (blocked_set & (1U << sig)) - pending_array[sig] = 1; - else - { - handler_t handler = SIGPIPE_handler; - if (handler == SIG_DFL) - exit (128 + SIGPIPE); - else if (handler != SIG_IGN) - (*handler) (sig); - } - return 0; - default: /* System defined signal */ - return raise (sig); + handler_t handler = SIGPIPE_handler; + if (handler == SIG_DFL) + exit (128 + SIGPIPE); + else if (handler != SIG_IGN) + (*handler) (SIGPIPE); } } #endif diff --git a/m4/raise.m4 b/m4/raise.m4 --- a/m4/raise.m4 +++ b/m4/raise.m4 @@ -1,4 +1,4 @@ -# raise.m4 serial 1 +# raise.m4 serial 2 dnl Copyright (C) 2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -16,6 +16,17 @@ if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then REPLACE_RAISE=1 fi + m4_ifdef([gl_SIGNALBLOCKING], [ + gl_SIGNALBLOCKING + if test $HAVE_POSIX_SIGNALBLOCKING = 0; then + m4_ifdef([gl_SIGNAL_SIGPIPE], [ + gl_SIGNAL_SIGPIPE + if test $gl_cv_header_signal_h_SIGPIPE != yes; then + REPLACE_RAISE=1 + fi + ], [:]) + fi + ]) fi ])