The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal
@ 2026-12-01 13:05 Raphael Bauer
  2026-12-01 23:26 ` Alejandro Colomar
  0 siblings, 1 reply; 3+ messages in thread
From: Raphael Bauer @ 2026-12-01 13:05 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2348 bytes --]

Hi Alejandro,

When two threads of a process wait in sigtimedwait() for the same signal 
and that signal is sent to the process (here by alarm()), one thread 
accepts it, and the other fails with EINTR at that same moment instead 
of failing with EAGAIN at its timeout. No signal handler is installed. 
The EINTR entry in sigwaitinfo.2 (the page for sigtimedwait(2)) names 
only a signal handler as the cause, and I found nothing else in that 
page or in signal(7) that covers this case. I read this in man-pages 
6.13 as installed; the current page in man-pages.git has the same wording.

I can't tell whether the page or the kernel should change, so I'm 
copying LKML. Could you, or someone on LKML, say which it is?

Reproducer: both threads block SIGALRM and wait for it with a timeout of 
2.5 s; main calls alarm(1).

#define _GNU_SOURCE
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

static pthread_barrier_t barrier;

static void *waiter(void *name)
{
         sigset_t set;
         struct timespec timeout = { 2, 500000000 };     /* 2.5 s */
         int sig;

         sigemptyset(&set);
         sigaddset(&set, SIGALRM);
         pthread_barrier_wait(&barrier);
         sig = sigtimedwait(&set, NULL, &timeout);
         printf("%-6s: sigtimedwait() = %d%s%s\n", (char *) name, sig,
                sig == -1 ? ", errno " : "", sig == -1 ? 
strerrorname_np(errno) : "");
         return NULL;
}

int main(void)
{
         sigset_t set;
         pthread_t thread;

         sigemptyset(&set);
         sigaddset(&set, SIGALRM);
         sigprocmask(SIG_BLOCK, &set, NULL);     /* inherited by the 
thread */

         pthread_barrier_init(&barrier, NULL, 2);
         pthread_create(&thread, NULL, waiter, "thread");
         alarm(1);
         waiter("main");
         pthread_join(thread, NULL);
         return 0;
}

Output on SUSE Linux Enterprise Server 16.0 (kernel 
6.12.0-160000.5-default), the same in each of 10 runs; both lines appear 
after 1.0 s, and 14 is SIGALRM:

main  : sigtimedwait() = 14
thread: sigtimedwait() = -1, errno EINTR

Without the alarm(1), both threads fail with EAGAIN after 2.5 s. I have 
not tried other kernels.

Thanks,
Raphael Bauer

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal
  2026-12-01 13:05 sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal Raphael Bauer
@ 2026-12-01 23:26 ` Alejandro Colomar
  2026-12-04 17:13   ` Eric W. Biederman
  0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2026-12-01 23:26 UTC (permalink / raw)
  To: Raphael Bauer
  Cc: linux-man, linux-kernel, Oleg Nesterov, Tejun Heo, Matt Fleming,
	Eric W. Biederman, Arnd Bergmann, Thomas Gleixner, Peter Zijlstra

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

Hi Raphael,

> Date: 2026-12-01 14:05:28+0100
> From: Raphael Bauer <raphael.bauer@atsec.com>
>
> Hi Alejandro,
> 
> When two threads of a process wait in sigtimedwait() for the same signal and
> that signal is sent to the process (here by alarm()), one thread accepts it,
> and the other fails with EINTR at that same moment instead of failing with
> EAGAIN at its timeout. No signal handler is installed. The EINTR entry in
> sigwaitinfo.2 (the page for sigtimedwait(2)) names only a signal handler as
> the cause, and I found nothing else in that page or in signal(7) that covers
> this case. I read this in man-pages 6.13 as installed; the current page in
> man-pages.git has the same wording.
> 
> I can't tell whether the page or the kernel should change, so I'm copying
> LKML.

I have CCd a few people that have been involved in implementing
sigtimedwait(2) --according to git-blame(1)--.

> Could you, or someone on LKML, say which it is?

I don't know much about this API, so can't answer.  But unless someone
considers this a bug, I guess we should document what happens at the
moment (it's good to CC them just in case).

Would you mind preparing a patch for the manual page?

> 
> Reproducer: both threads block SIGALRM and wait for it with a timeout of 2.5
> s; main calls alarm(1).
> 
> #define _GNU_SOURCE
> #include <errno.h>
> #include <pthread.h>
> #include <signal.h>
> #include <stdio.h>
> #include <string.h>
> #include <time.h>
> #include <unistd.h>
> 
> static pthread_barrier_t barrier;
> 
> static void *waiter(void *name)
> {
>         sigset_t set;
>         struct timespec timeout = { 2, 500000000 };     /* 2.5 s */
>         int sig;
> 
>         sigemptyset(&set);
>         sigaddset(&set, SIGALRM);
>         pthread_barrier_wait(&barrier);
>         sig = sigtimedwait(&set, NULL, &timeout);
>         printf("%-6s: sigtimedwait() = %d%s%s\n", (char *) name, sig,
>                sig == -1 ? ", errno " : "", sig == -1 ?
> strerrorname_np(errno) : "");
>         return NULL;
> }
> 
> int main(void)
> {
>         sigset_t set;
>         pthread_t thread;
> 
>         sigemptyset(&set);
>         sigaddset(&set, SIGALRM);
>         sigprocmask(SIG_BLOCK, &set, NULL);     /* inherited by the thread
> */
> 
>         pthread_barrier_init(&barrier, NULL, 2);
>         pthread_create(&thread, NULL, waiter, "thread");
>         alarm(1);
>         waiter("main");
>         pthread_join(thread, NULL);
>         return 0;
> }
> 
> Output on SUSE Linux Enterprise Server 16.0 (kernel
> 6.12.0-160000.5-default), the same in each of 10 runs; both lines appear
> after 1.0 s, and 14 is SIGALRM:
> 
> main  : sigtimedwait() = 14
> thread: sigtimedwait() = -1, errno EINTR

Thanks!  Please keep this reproducer in the commit message of the patch,
if you send one.  (Indent it so that git(1) doesn't consider the
'#include' lines to be comments.)


Have a lovely night!
Alex

> 
> Without the alarm(1), both threads fail with EAGAIN after 2.5 s. I have not
> tried other kernels.
> 
> Thanks,
> Raphael Bauer




-- 
<https://www.alejandro-colomar.es>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal
  2026-12-01 23:26 ` Alejandro Colomar
@ 2026-12-04 17:13   ` Eric W. Biederman
  0 siblings, 0 replies; 3+ messages in thread
From: Eric W. Biederman @ 2026-12-04 17:13 UTC (permalink / raw)
  To: Alejandro Colomar
  Cc: Raphael Bauer, linux-man, linux-kernel, Oleg Nesterov, Tejun Heo,
	Matt Fleming, Arnd Bergmann, Thomas Gleixner, Peter Zijlstra

Alejandro Colomar <alx+linux-man@kernel.org> writes:

> Hi Raphael,
>
>> Date: 2026-12-01 14:05:28+0100
>> From: Raphael Bauer <raphael.bauer@atsec.com>
>>
>> Hi Alejandro,
>> 
>> When two threads of a process wait in sigtimedwait() for the same signal and
>> that signal is sent to the process (here by alarm()), one thread accepts it,
>> and the other fails with EINTR at that same moment instead of failing with
>> EAGAIN at its timeout. No signal handler is installed. The EINTR entry in
>> sigwaitinfo.2 (the page for sigtimedwait(2)) names only a signal handler as
>> the cause, and I found nothing else in that page or in signal(7) that covers
>> this case. I read this in man-pages 6.13 as installed; the current page in
>> man-pages.git has the same wording.
>> 
>> I can't tell whether the page or the kernel should change, so I'm copying
>> LKML.
>
> I have CCd a few people that have been involved in implementing
> sigtimedwait(2) --according to git-blame(1)--.
>
>> Could you, or someone on LKML, say which it is?
>
> I don't know much about this API, so can't answer.  But unless someone
> considers this a bug, I guess we should document what happens at the
> moment (it's good to CC them just in case).

There is an issue with the test program.  It only blocks SIG_ALARM.

Any other signal can come in and cause the other thread to say -EINTR.

So this looks like it could be exactly the documented behavior in the
manpage.

I don't see anything obvious that would generate another signal, but
some more sleuthing needs to be done to rule out another signal before
we can say anything.

If there is no other signal then it is likely a bug in the kernel as all
of the wakeups I see only wake up a single thread.

I suspect a quick run of the test program under gdb or strace (following
all of the threads) would show what is going on.

Eric

>> Reproducer: both threads block SIGALRM and wait for it with a timeout of 2.5s;
>> main calls alarm(1).
>> 
>> #define _GNU_SOURCE
>> #include <errno.h>
>> #include <pthread.h>
>> #include <signal.h>
>> #include <stdio.h>
>> #include <string.h>
>> #include <time.h>
>> #include <unistd.h>
>> 
>> static pthread_barrier_t barrier;
>> 
>> static void *waiter(void *name)
>> {
>>         sigset_t set;
>>         struct timespec timeout = { 2, 500000000 };     /* 2.5 s */
>>         int sig;
>> 
>>         sigemptyset(&set);
>>         sigaddset(&set, SIGALRM);
>>         pthread_barrier_wait(&barrier);
>>         sig = sigtimedwait(&set, NULL, &timeout);
>>         printf("%-6s: sigtimedwait() = %d%s%s\n", (char *) name, sig,
>>                sig == -1 ? ", errno " : "", sig == -1 ?
>> strerrorname_np(errno) : "");
>>         return NULL;
>> }
>> 
>> int main(void)
>> {
>>         sigset_t set;
>>         pthread_t thread;
>> 
>>         sigemptyset(&set);
>>         sigaddset(&set, SIGALRM);
>>         sigprocmask(SIG_BLOCK, &set, NULL);     /* inherited by the thread
>> */
>> 
>>         pthread_barrier_init(&barrier, NULL, 2);
>>         pthread_create(&thread, NULL, waiter, "thread");
>>         alarm(1);
>>         waiter("main");
>>         pthread_join(thread, NULL);
>>         return 0;
>> }
>> 
>> Output on SUSE Linux Enterprise Server 16.0 (kernel
>> 6.12.0-160000.5-default), the same in each of 10 runs; both lines appear
>> after 1.0 s, and 14 is SIGALRM:
>> 
>> main  : sigtimedwait() = 14
>> thread: sigtimedwait() = -1, errno EINTR
>
> Thanks!  Please keep this reproducer in the commit message of the patch,
> if you send one.  (Indent it so that git(1) doesn't consider the
> '#include' lines to be comments.)
>
>
> Have a lovely night!
> Alex
>
>> 
>> Without the alarm(1), both threads fail with EAGAIN after 2.5 s. I have not
>> tried other kernels.
>> 
>> Thanks,
>> Raphael Bauer

Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 17:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 13:05 sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal Raphael Bauer
2026-12-01 23:26 ` Alejandro Colomar
2026-12-04 17:13   ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox