view lib/pthread_sigmask.c @ 15383:2fb7d8364951

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.
author Bruno Haible <bruno@clisp.org>
date Sat, 09 Jul 2011 01:01:36 +0200
parents 16995a7f1514
children 2187b5650eca
line wrap: on
line source

/* POSIX compatible signal blocking for threads.
   Copyright (C) 2011 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <config.h>

/* Specification.  */
#include <signal.h>

#include <errno.h>
#include <stddef.h>

int
pthread_sigmask (int how, const sigset_t *new_mask, sigset_t *old_mask)
#undef pthread_sigmask
{
#if HAVE_PTHREAD_SIGMASK
  int ret = pthread_sigmask (how, new_mask, old_mask);
# if PTHREAD_SIGMASK_INEFFECTIVE
  if (ret == 0)
    {
      /* Detect whether pthread_sigmask is currently ineffective.
         Don't cache the information: libpthread.so could be dynamically
         loaded after the program started and after pthread_sigmask was
         called for the first time.  */
      if (pthread_sigmask (1729, NULL, NULL) == 0)
        {
          /* pthread_sigmask is currently ineffective.  The program is not
             linked to -lpthread.  So use sigprocmask instead.  */
          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
  int ret = sigprocmask (how, new_mask, old_mask);
  return (ret < 0 ? errno : 0);
#endif
}