From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13515 Path: news.gmane.org!.POSTED!not-for-mail From: Markus Wichmann Newsgroups: gmane.linux.lib.musl.general Subject: Re: sem_wait and EINTR Date: Thu, 6 Dec 2018 18:33:37 +0100 Message-ID: <20181206173337.GD32233@voyager> References: <20181205191605.72492698@orivej.orivej.org> <20181205194759.GA32233@voyager> <20181205212716.sx6ra2xqhuei735q@core.my.home> <20181205215826.GX23599@brightrain.aerifal.cx> <20181206024340.202e0fc4@orivej.orivej.org> <20181206031756.GZ23599@brightrain.aerifal.cx> <20181206155756.GB32233@voyager> <20181206162336.GB23599@brightrain.aerifal.cx> <20181206170359.GC32233@voyager> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="6TrnltStXW4iwmi0" X-Trace: blaine.gmane.org 1544117527 25264 195.159.176.226 (6 Dec 2018 17:32:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2018 17:32:07 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-13531-gllmg-musl=m.gmane.org@lists.openwall.com Thu Dec 06 18:32:03 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gUxVL-0006PM-0s for gllmg-musl@m.gmane.org; Thu, 06 Dec 2018 18:32:03 +0100 Original-Received: (qmail 13799 invoked by uid 550); 6 Dec 2018 17:34:11 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 13781 invoked from network); 6 Dec 2018 17:34:11 -0000 Content-Disposition: inline In-Reply-To: <20181206170359.GC32233@voyager> X-Provags-ID: V03:K1:iPNf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a Xref: news.gmane.org gmane.linux.lib.musl.general:13515 Archived-At: --6TrnltStXW4iwmi0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, is the attached patch acceptable? A word about the bitfields: I generally dislike them for most things, but I didn't want to destroy the alignment struct __libc had going on, and these other flags really only are 0 or 1. Patch is untested for want of an old kernel. Ciao, Markus --6TrnltStXW4iwmi0 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0003-Add-workaround-for-old-linux-bug.patch" >From 816abf54fbbb02923331b69b62333b8a0edb4181 Mon Sep 17 00:00:00 2001 From: Markus Wichmann Date: Thu, 6 Dec 2018 18:30:26 +0100 Subject: [PATCH 3/3] Add workaround for old linux bug. --- src/internal/libc.h | 4 +--- src/signal/sigaction.c | 2 ++ src/thread/sem_timedwait.c | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/internal/libc.h b/src/internal/libc.h index ac97dc7e..2e6737d9 100644 --- a/src/internal/libc.h +++ b/src/internal/libc.h @@ -18,9 +18,7 @@ struct tls_module { }; struct __libc { - int can_do_threads; - int threaded; - int secure; + unsigned can_do_threads:1, threaded:1, secure:1, handling_sigs:1; volatile int threads_minus_1; size_t *auxv; struct tls_module *tls_head; diff --git a/src/signal/sigaction.c b/src/signal/sigaction.c index af47195e..5f02b99b 100644 --- a/src/signal/sigaction.c +++ b/src/signal/sigaction.c @@ -43,6 +43,8 @@ int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigact SIGPT_SET, 0, _NSIG/8); unmask_done = 1; } + if (!(sa->sa_flags & SA_RESTART)) + libc.handling_sigs = 1; } /* Changing the disposition of SIGABRT to anything but * SIG_DFL requires a lock, so that it cannot be changed diff --git a/src/thread/sem_timedwait.c b/src/thread/sem_timedwait.c index 8132eb1b..e76ae9de 100644 --- a/src/thread/sem_timedwait.c +++ b/src/thread/sem_timedwait.c @@ -22,7 +22,10 @@ int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) pthread_cleanup_push(cleanup, (void *)(sem->__val+1)); r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]); pthread_cleanup_pop(1); - if (r && r != EINTR) { + /* Linux pre-2.6.22 bug: Sometimes SYS_futex returns with EINTR when it should not. + * Workaround: Retry on EINTR unless someone installed handlers before. + */ + if (r && (r != EINTR || libc.handling_sigs)) { errno = r; return -1; } -- 2.19.1 --6TrnltStXW4iwmi0--