]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Fix tsan warning: signal handler spoils errno
authorTom de Vries <tdevries@suse.de>
Fri, 13 Dec 2024 17:36:34 +0000 (18:36 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 13 Dec 2024 17:36:34 +0000 (18:36 +0100)
When building gdb with -fsanitize=thread and running test-case
gdb.base/bg-exec-sigint-bp-cond.exp, I run into:
...
==================^M
WARNING: ThreadSanitizer: signal handler spoils errno (pid=25422)^M
    #0 handler_wrapper gdb/posix-hdep.c:66^M
    #1 decltype ({parm#2}({parm#3}...)) gdb::handle_eintr<>() \
         gdbsupport/eintr.h:67^M
    #2 gdb::waitpid(int, int*, int) gdbsupport/eintr.h:78^M
    #3 run_under_shell gdb/cli/cli-cmds.c:926^M
...

Likewise in:
- tui_sigwinch_handler with test-case gdb.python/tui-window.exp, and
- handle_sighup with test-case gdb.base/quit-live.exp.

Fix this by saving the original errno, and restoring it before returning [1].

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html

gdb/event-top.c
gdb/posix-hdep.c
gdb/tui/tui-win.c

index 45ad7b990faa7a741784892f0d1d6fc0e7ac2f68..102304cb4ec7333c566708387e90ddedd2b3b219 100644 (file)
@@ -1480,6 +1480,7 @@ async_do_nothing (gdb_client_data arg)
 static void
 handle_sighup (int sig)
 {
+  scoped_restore restore_errno = make_scoped_restore (&errno);
   mark_async_signal_handler (sighup_token);
   signal (sig, handle_sighup);
 }
index a0d5c585ebc79a97240d2d83f79edecdd4403b97..d7d17e6b2f43e8a2658d3d66b850bee2baa52619 100644 (file)
@@ -64,6 +64,7 @@ static c_c_handler_ftype *current_handler;
 static void
 handler_wrapper (int num)
 {
+  scoped_restore restore_errno = make_scoped_restore (&errno);
   signal (num, handler_wrapper);
   if (current_handler != SIG_IGN)
     current_handler (num);
index e9a8e4651ea76101f5fcd0f1c3418f85b07dbb26..414d4699bea7e1cffd8a22439d739e4101abc40c 100644 (file)
@@ -527,6 +527,7 @@ static struct async_signal_handler *tui_sigwinch_token;
 static void
 tui_sigwinch_handler (int signal)
 {
+  scoped_restore restore_errno = make_scoped_restore (&errno);
   mark_async_signal_handler (tui_sigwinch_token);
   tui_set_win_resized_to (true);
 }