]> git.ipfire.org Git - thirdparty/glibc.git/commit
nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029)
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 6 Apr 2022 15:24:42 +0000 (12:24 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 15 Apr 2022 12:52:54 +0000 (09:52 -0300)
commit290db09546b260a30137d03ce97a857e6f15b648
treea4ebf5132cd6602ad2f9419f3b805ca3ad8f7875
parent0c03cb54c808173d8e7ba96f6152dfcf627ac496
nptl: Handle spurious EINTR when thread cancellation is disabled (BZ#29029)

Some Linux interfaces never restart after being interrupted by a signal
handler, regardless of the use of SA_RESTART [1].  It means that for
pthread cancellation, if the target thread disables cancellation with
pthread_setcancelstate and calls such interfaces (like poll or select),
it should not see spurious EINTR failures due the internal SIGCANCEL.

However recent changes made pthread_cancel to always sent the internal
signal, regardless of the target thread cancellation status or type.
To fix it, the previous semantic is restored, where the cancel signal
is only sent if the target thread has cancelation enabled in
asynchronous mode.

The cancel state and cancel type is moved back to cancelhandling
and atomic operation are used to synchronize between threads.  The
patch essentially revert the following commits:

  8c1c0aae20 nptl: Move cancel type out of cancelhandling
  2b51742531 nptl: Move cancel state out of cancelhandling
  26cfbb7162 nptl: Remove CANCELING_BITMASK

However I changed the atomic operation to follow the internal C11
semantic and removed the MACRO usage, it simplifies a bit the
resulting code (and removes another usage of the old atomic macros).

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
and powerpc64-linux-gnu.

[1] https://man7.org/linux/man-pages/man7/signal.7.html

Reviewed-by: Florian Weimer <fweimer@redhat.com>
Tested-by: Aurelien Jarno <aurelien@aurel32.net>
(cherry-picked from commit 404656009b459658138ed1bd18f3c6cf3863e6a6)
16 files changed:
NEWS
manual/process.texi
nptl/allocatestack.c
nptl/cancellation.c
nptl/cleanup_defer.c
nptl/descr.h
nptl/libc-cleanup.c
nptl/pthread_cancel.c
nptl/pthread_join_common.c
nptl/pthread_setcancelstate.c
nptl/pthread_setcanceltype.c
nptl/pthread_testcancel.c
sysdeps/nptl/dl-tls_init_tp.c
sysdeps/nptl/pthreadP.h
sysdeps/pthread/Makefile
sysdeps/pthread/tst-cancel29.c [new file with mode: 0644]