From 8f97c045b8e65784071fd097fc32a1f16b855b3b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 30 Oct 2015 16:05:43 +0100 Subject: [PATCH] Fix sigwait and pthread_kill return values in case of error * signal.cc (sigwait): Fix return value to reflect errno in case of error according to POSIX. Never return EINTR. * thread.cc (pthread_kill): Return errno if sig_send failed. Signed-off-by: Corinna Vinschen --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/release/2.3.0 | 4 ++++ winsup/cygwin/signal.cc | 10 ++++++++-- winsup/cygwin/thread.cc | 6 +++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 337a1d2d6..3fb4372ac 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2015-10-30 Corinna Vinschen + + * signal.cc (sigwait): Fix return value to reflect errno in case of + error according to POSIX. Never return EINTR. + * thread.cc (pthread_kill): Return errno if sig_send failed. + 2015-10-29 Qian Hong * init.cc (munge_threadfunc): Check that we're actually replacing diff --git a/winsup/cygwin/release/2.3.0 b/winsup/cygwin/release/2.3.0 index c6f70aa4b..1cad81b62 100644 --- a/winsup/cygwin/release/2.3.0 +++ b/winsup/cygwin/release/2.3.0 @@ -53,3 +53,7 @@ Bug Fixes - Fix a potential SEGV on (at least) Wine. Addresses: https://cygwin.com/ml/cygwin/2015-10/msg00018.html + +- Fix sigwait(3) to return errno instead of -1 and never to return with EINTR. + +- Fix pthread_kill(3) to return errno instead of -1. diff --git a/winsup/cygwin/signal.cc b/winsup/cygwin/signal.cc index 4897417d4..8dfd4ab63 100644 --- a/winsup/cygwin/signal.cc +++ b/winsup/cygwin/signal.cc @@ -557,10 +557,16 @@ siginterrupt (int sig, int flag) extern "C" int sigwait (const sigset_t *set, int *sig_ptr) { - int sig = sigwaitinfo (set, NULL); + int sig; + + do + { + sig = sigwaitinfo (set, NULL); + } + while (sig == -1 && get_errno () == EINTR); if (sig > 0) *sig_ptr = sig; - return sig > 0 ? 0 : -1; + return sig > 0 ? 0 : get_errno (); } extern "C" int diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index d9b62111f..ff8459015 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3056,7 +3056,11 @@ pthread_kill (pthread_t thread, int sig) if (!thread->valid) rval = ESRCH; else if (sig) - rval = sig_send (NULL, si, thread->cygtls); + { + rval = sig_send (NULL, si, thread->cygtls); + if (rval == -1) + rval = get_errno (); + } else switch (WaitForSingleObject (thread->win32_obj_id, 0)) {