From 43243b5fdcf1e0c0e016cabe190f1ab29b984871 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 9 Jul 2011 01:01:36 +0200 Subject: [PATCH] pthread_sigmask: Work around Cygwin bug. * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Test for the Cygwin bug. * lib/pthread_sigmask.c (pthread_sigmask): Fix the return value from the system's pthread_sigmask function. * doc/posix-functions/pthread_sigmask.texi: Mention the Cygwin bug. --- ChangeLog | 9 ++++++ doc/posix-functions/pthread_sigmask.texi | 4 +++ lib/pthread_sigmask.c | 4 +++ m4/pthread_sigmask.m4 | 40 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/ChangeLog b/ChangeLog index 80ae091b79..cebc6f627a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2011-07-08 Bruno Haible + + pthread_sigmask: Work around Cygwin bug. + * m4/pthread_sigmask.m4 (gl_FUNC_PTHREAD_SIGMASK): Test for the Cygwin + bug. + * lib/pthread_sigmask.c (pthread_sigmask): Fix the return value from + the system's pthread_sigmask function. + * doc/posix-functions/pthread_sigmask.texi: Mention the Cygwin bug. + 2011-07-08 Bruno Haible pthread_sigmask: Work around bug in single-threaded implementation. diff --git a/doc/posix-functions/pthread_sigmask.texi b/doc/posix-functions/pthread_sigmask.texi index 62f0a761cd..58b6295827 100644 --- a/doc/posix-functions/pthread_sigmask.texi +++ b/doc/posix-functions/pthread_sigmask.texi @@ -19,6 +19,10 @@ MacOS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6. This function does nothing and always returns 0 in programs that are not linked with @code{-lpthread} on some platforms: FreeBSD 6.4, HP-UX 11.31, Solaris 9. +@item +When it fails, this functions returns -1 instead of the error number on +some platforms: +Cygwin 1.7.5. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/pthread_sigmask.c b/lib/pthread_sigmask.c index b53b15dd71..06ee7fc420 100644 --- a/lib/pthread_sigmask.c +++ b/lib/pthread_sigmask.c @@ -42,6 +42,10 @@ pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask) return (sigprocmask (how, new_mask, old_mask) < 0 ? errno : 0); } } +# endif +# if PTHREAD_SIGMASK_FAILS_WITH_ERRNO + if (ret == -1) + return errno; # endif return ret; #else diff --git a/m4/pthread_sigmask.m4 b/m4/pthread_sigmask.m4 index f8b3e8a416..c65a4ce350 100644 --- a/m4/pthread_sigmask.m4 +++ b/m4/pthread_sigmask.m4 @@ -119,6 +119,46 @@ changequote([,])dnl ;; esac fi + + dnl On Cygwin 1.7.5, the pthread_sigmask() has a wrong return value + dnl convention: Upon failure, it returns -1 and sets errno. + AC_CACHE_CHECK([whether pthread_sigmask returns error numbers], + [gl_cv_func_pthread_sigmask_return_works], + [ + gl_save_LIBS="$LIBS" + LIBS="$LIBS $LIB_PTHREAD_SIGMASK" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +int main () +{ + sigset_t set; + sigemptyset (&set); + if (pthread_sigmask (1729, &set, NULL) == -1) + return 1; + return 0; +}]])], + [gl_cv_func_pthread_sigmask_return_works=yes], + [gl_cv_func_pthread_sigmask_return_works=no], + [case "$host_os" in + cygwin*) + gl_cv_func_pthread_sigmask_return_works="guessing no";; + *) + gl_cv_func_pthread_sigmask_return_works="guessing yes";; + esac + ]) + LIBS="$gl_save_LIBS" + ]) + case "$gl_cv_func_pthread_sigmask_return_works" in + *no) + REPLACE_PTHREAD_SIGMASK=1 + AC_DEFINE([PTHREAD_SIGMASK_FAILS_WITH_ERRNO], [1], + [Define to 1 if pthread_mask(), when it fails, returns -1 and sets errno.]) + ;; + esac + fi ]) -- 2.30.2