From 78856474fbd3025f3ff4727c575f8794d2aa1515 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 19 Aug 2015 13:47:57 +0000 Subject: [PATCH] On Linux, clear the signal mask of the launched inferior Summary: Due to fork()/execve(), the launched inferior inherits the signal mask of its parent (lldb-server). But because lldb-server modifies its signal mask (It blocks SIGCHLD, for example), the inferior starts with some signals being initially blocked. One consequence is that TestCallThatRestarts.ExprCommandThatRestartsTestCase (test/expression_command/call-restarts) fails because sigchld_handler() in lotta-signals.c is not called, due to the SIGCHLD signal being blocked. To prevent the signal masking done by lldb-server from affecting the created inferior, the signal mask of the inferior is now cleared before the execve(). Patch by: Yacine Belkadi Reviewers: ovyalov, labath Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D12138 llvm-svn: 245436 --- .../Plugins/Process/Linux/NativeProcessLinux.cpp | 12 +++++++++++- .../call-restarts/TestCallThatRestarts.py | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 7203da27640e..84e020d5be2b 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -554,7 +554,8 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error) eDupStderrFailed, eChdirFailed, eExecFailed, - eSetGidFailed + eSetGidFailed, + eSetSigMaskFailed }; // Child process. @@ -632,6 +633,12 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error) } } + // Clear the signal mask to prevent the child from being affected by + // any masking done by the parent. + sigset_t set; + if (sigemptyset(&set) != 0 || pthread_sigmask(SIG_SETMASK, &set, nullptr) != 0) + exit(eSetSigMaskFailed); + // Execute. We should never return... execve(argv[0], const_cast(argv), @@ -689,6 +696,9 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error) case eSetGidFailed: error.SetErrorString("Child setgid failed."); break; + case eSetSigMaskFailed: + error.SetErrorString("Child failed to set signal mask."); + break; default: error.SetErrorString("Child returned unknown exit status."); break; diff --git a/lldb/test/expression_command/call-restarts/TestCallThatRestarts.py b/lldb/test/expression_command/call-restarts/TestCallThatRestarts.py index ba8890a04ce6..c79d855b8508 100644 --- a/lldb/test/expression_command/call-restarts/TestCallThatRestarts.py +++ b/lldb/test/expression_command/call-restarts/TestCallThatRestarts.py @@ -29,7 +29,6 @@ class ExprCommandThatRestartsTestCase(TestBase): @dwarf_test @skipIfFreeBSD # llvm.org/pr19246: intermittent failure - @expectedFailureLinux("llvm.org/pr19246") @skipIfDarwin # llvm.org/pr19246: intermittent failure @skipIfWindows # Test relies on signals, unsupported on Windows def test_with_dwarf(self):