mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Raphael Bauer <raphael.bauer@atsec.com>
To: Alejandro Colomar <alx+linux-man@kernel.org>
Cc: linux-man@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: sigwaitinfo.2: sigtimedwait() fails with EINTR, without a signal handler, when another thread accepts a process-directed signal
Date: Tue, 1 Dec 2026 14:05:28 +0100	[thread overview]
Message-ID: <e5bf3143-20f3-4eff-80de-bff8d40ffd93@atsec.com> (raw)


[-- 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 --]

                 reply	other threads:[~2026-12-01 13:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=e5bf3143-20f3-4eff-80de-bff8d40ffd93@atsec.com \
    --to=raphael.bauer@atsec.com \
    --cc=alx+linux-man@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-man@vger.kernel.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®