Index: b/configure.ac =================================================================== --- b/configure.ac +++ b/configure.ac @@ -294,6 +294,64 @@ ]) LIBS=$gl_saved_libs + AC_MSG_CHECKING([whether the sem_init created accessable semapore for child process]) + AC_RUN_IFELSE([AC_LANG_SOURCE([[#include +#include +#include +static sem_t sceptre_buffer; +static sem_t *sceptre = &sceptre_buffer; +int main() +{ +int res; + // create semaphore + if(sem_init (sceptre, 0, 1)<0) { + return 1; + } + do { + // unlock + res = sem_wait (sceptre); + } while (res < 0 && errno == EINTR); + if(res) { + return 1; + } + pid_t pid; + pid = fork (); + if (pid == (pid_t)-1) + { + return 1; + } + else if (pid) + { + int status; + waitpid(-1,&status,0); + if(status) { + return 1; + } + } else { + // lock in child + if(sem_post (sceptre) != 0) + { + return 1; + } + return 0; + } + return 0; +}]])], + [have_working_sem_init=yes], + [have_working_sem_init=no], + [ +changequote(,)dnl + case "$host_os" in + aix* ) have_working_sem_init=no ;; + *) have_working_sem_init=yes ;; + esac +changequote([,])dnl + ]) + AC_MSG_RESULT($have_working_sem_init) +if test x"$have_working_sem_init" = xno ; then + AC_DEFINE(HAVE_BROKEN_SEM_INIT,1,[Define if sem_init can not create accessable semapore for child process.]) +fi + # # Set NETLIBS Index: b/src/npth.c =================================================================== --- b/src/npth.c +++ b/src/npth.c @@ -181,6 +181,7 @@ sem_init. */ errno = 0; +#ifndef HAVE_BROKEN_SEM_INIT /* The semaphore is not shared and binary. */ res = sem_init (sceptre, 0, 1); if (res < 0) @@ -204,6 +205,10 @@ #endif } } +#else + if (try_sem_open (&sceptre)) + return errno; +#endif LEAVE(); return 0; Index: b/tests/Makefile.am =================================================================== --- b/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,7 +28,7 @@ ## Process this file with automake to produce Makefile.in -TESTS = t-mutex t-thread +TESTS = t-mutex t-thread t-fork # We explicitly require POSIX.1-2001 so that pthread_rwlock_t is # available when build with c99. Index: b/tests/t-fork.c =================================================================== --- /dev/null +++ b/tests/t-fork.c @@ -0,0 +1,49 @@ +/* t-mutex.c + * Copyright 2011, 2012 g10 Code GmbH + * + * This file is free software; as a special exception the author gives + * unlimited permission to copy and/or distribute it, with or without + * modifications, as long as this notice is preserved. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include "t-support.h" + + +int +main (int argc, char *argv[]) +{ + int rc; + + rc = npth_init (); + fail_if_err (rc); + npth_unprotect (); + npth_protect (); + pid_t pid; + npth_sigev_init (); + npth_sigev_add (SIGHUP); + npth_sigev_fini (); + pid = fork (); + if (pid == (pid_t)-1) + { + fail_msg ("fork failed"); + exit (1); + } + else if (pid) + { + int status; + info_msg("forked"); + waitpid(-1,&status,0); + if(status) { + exit(1); + } + } else { + npth_unprotect (); + info_msg("child exit"); + exit(0); + } + return 0; +}