diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c7dbfc7ac..b7296bb5f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-03-28 Jon TURNEY + + * thread.cc (semaphore::init, destroy, close): Standards conformance + fix. On a failure, return -1 and set errno. + * thread.h (semaphore::terminate): Save errno since semaphore::close() + may now modify it. + 2011-03-27 Yaakov Selkowitz * cygwin.din (strchrnul): Export. diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 628d1d13f..891b43fb9 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3076,10 +3076,16 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value) { /* opengroup calls this undefined */ if (is_good_object (sem)) - return EBUSY; + { + set_errno(EBUSY); + return -1; + } if (value > SEM_VALUE_MAX) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } *sem = new semaphore (pshared, value); @@ -3087,7 +3093,8 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value) { delete (*sem); *sem = NULL; - return EAGAIN; + set_errno(EAGAIN); + return -1; } return 0; } @@ -3096,11 +3103,17 @@ int semaphore::destroy (sem_t *sem) { if (!is_good_object (sem)) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* It's invalid to destroy a semaphore not opened with sem_init. */ if ((*sem)->fd != -1) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* FIXME - new feature - test for busy against threads... */ @@ -3113,11 +3126,17 @@ int semaphore::close (sem_t *sem) { if (!is_good_object (sem)) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* It's invalid to close a semaphore not opened with sem_open. */ if ((*sem)->fd == -1) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } delete (*sem); delete sem; diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 62bd1b959..bea8e2aa3 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -21,6 +21,7 @@ details. */ #include #include "security.h" #include +#include "cygerrno.h" enum cw_sig_wait { @@ -641,6 +642,7 @@ public: } static void terminate () { + save_errno save; semaphores.for_each (&semaphore::_terminate); }