raise: Fix double declaration with modules 'sigprocmask' and 'sigpipe'.
authorBruno Haible <bruno@clisp.org>
Tue, 27 Sep 2011 22:49:04 +0000 (00:49 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 27 Sep 2011 22:49:55 +0000 (00:49 +0200)
* 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 <tmacchant5@yahoo.co.jp>.

ChangeLog
lib/raise.c
lib/signal.in.h
lib/sigprocmask.c
m4/raise.m4

index 473b1c4..c0ab928 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2011-09-26  Bruno Haible  <bruno@clisp.org>
+
+       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 <tmacchant5@yahoo.co.jp>.
+
 2011-09-26  Gijs van Tulder  <gvtulder@gmail.com>
 
        base64-tests: avoid memory leak
index 980c9fd..aee33e8 100644 (file)
@@ -50,24 +50,30 @@ raise_nothrow (int sig)
 
   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 <unistd.h>
 
+# define rpl_raise raise
+
+#endif
+
 int
-raise (int sig)
+rpl_raise (int sig)
 {
-  return kill (getpid (), 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
+}
index b0e192f..e18e0b2 100644 (file)
@@ -178,6 +178,10 @@ _GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
 #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 @@ _GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
 # 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
index 6ccac5a..e75c757 100644 (file)
@@ -330,27 +330,19 @@ rpl_signal (int sig, handler_t handler)
 }
 
 #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
index 977e3d9..0ceed77 100644 (file)
@@ -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 @@ AC_DEFUN([gl_FUNC_RAISE],
     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
 ])