mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: sem_wait and EINTR
Date: Thu, 6 Dec 2018 18:33:37 +0100	[thread overview]
Message-ID: <20181206173337.GD32233@voyager> (raw)
In-Reply-To: <20181206170359.GC32233@voyager>

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

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

[-- Attachment #2: 0003-Add-workaround-for-old-linux-bug.patch --]
[-- Type: text/x-diff, Size: 2021 bytes --]

From 816abf54fbbb02923331b69b62333b8a0edb4181 Mon Sep 17 00:00:00 2001
From: Markus Wichmann <nullplan@gmx.net>
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


  reply	other threads:[~2018-12-06 17:33 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-05 19:16 Orivej Desh
2018-12-05 19:47 ` Markus Wichmann
2018-12-05 21:27   ` Ondřej Jirman
2018-12-05 21:58     ` Rich Felker
2018-12-06  2:43       ` Orivej Desh
2018-12-06  3:17         ` Rich Felker
2018-12-06 15:57           ` Markus Wichmann
2018-12-06 16:23             ` Rich Felker
2018-12-06 17:03               ` Markus Wichmann
2018-12-06 17:33                 ` Markus Wichmann [this message]
2018-12-06 20:31                   ` Orivej Desh
2018-12-09  2:51                   ` Rich Felker
2018-12-09  6:50                     ` Markus Wichmann
2018-12-12  0:32                       ` Rich Felker
2018-12-12  5:15                         ` Markus Wichmann
2018-12-14 19:45                           ` Rich Felker
2018-12-15  9:45                             ` Markus Wichmann
2018-12-05 22:03 ` Rich Felker
2018-12-06  2:43   ` Orivej Desh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181206173337.GD32233@voyager \
    --to=nullplan@gmx.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).