diff options
| author | Greg Clayton <gclayton@apple.com> | 2011-10-28 01:24:12 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2011-10-28 01:24:12 +0000 |
| commit | 708c1ab6f50a8bab47aeea27ee8fac93c0b571a0 (patch) | |
| tree | 1ea25e5e9215dab2afd04a06d8f0af88acc02c05 | |
| parent | 52c7d202410618f10c395ba830b2b6610ad2980e (diff) | |
| download | bcm5719-llvm-708c1ab6f50a8bab47aeea27ee8fac93c0b571a0.tar.gz bcm5719-llvm-708c1ab6f50a8bab47aeea27ee8fac93c0b571a0.zip | |
Python does some bad things to the signal masks in the current process and
then we spawn child processes (debugserver, etc) and those bad settings get
inherited. We stop this from happening by correctly mucking with the posix
spawn attributes.
llvm-svn: 143176
| -rw-r--r-- | lldb/source/Host/macosx/Host.mm | 9 | ||||
| -rw-r--r-- | lldb/tools/darwin-debug/darwin-debug.cpp | 10 | ||||
| -rw-r--r-- | lldb/tools/debugserver/source/MacOSX/MachProcess.cpp | 12 |
3 files changed, 27 insertions, 4 deletions
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index 0fd3bc82a78..4a30ccee495 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -1210,7 +1210,14 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info) // we return in the middle of this function. lldb_utility::CleanUp <posix_spawnattr_t *, int> posix_spawnattr_cleanup(&attr, posix_spawnattr_destroy); - short flags = 0; + sigset_t no_signals; + sigset_t all_signals; + sigemptyset (&no_signals); + sigfillset (&all_signals); + ::posix_spawnattr_setsigmask(&attr, &no_signals); + ::posix_spawnattr_setsigdefault(&attr, &all_signals); + + short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK; if (launch_info.GetFlags().Test (eLaunchFlagExec)) flags |= POSIX_SPAWN_SETEXEC; // Darwin specific posix_spawn flag diff --git a/lldb/tools/darwin-debug/darwin-debug.cpp b/lldb/tools/darwin-debug/darwin-debug.cpp index e698a647d45..4a91c3befa6 100644 --- a/lldb/tools/darwin-debug/darwin-debug.cpp +++ b/lldb/tools/darwin-debug/darwin-debug.cpp @@ -26,6 +26,7 @@ #include <getopt.h> #include <mach/machine.h> +#include <signal.h> #include <spawn.h> #include <stdio.h> #include <stdlib.h> @@ -117,12 +118,19 @@ posix_spawn_for_debug // since we want this program to turn into the program we want to debug, // and also have the new program start suspended (right at __dyld_start) // so we can debug it - short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETEXEC; + short flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETEXEC | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK; // Disable ASLR if we were asked to if (disable_aslr) flags |= _POSIX_SPAWN_DISABLE_ASLR; + sigset_t no_signals; + sigset_t all_signals; + sigemptyset (&no_signals); + sigfillset (&all_signals); + ::posix_spawnattr_setsigmask(&attr, &no_signals); + ::posix_spawnattr_setsigdefault(&attr, &all_signals); + // Set the flags we just made into our posix spawn attributes exit_with_errno (::posix_spawnattr_setflags (&attr, flags), "::posix_spawnattr_setflags (&attr, flags) error: "); diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp index 9f57788b9e0..58492bddd6c 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.cpp @@ -13,6 +13,7 @@ #include "DNB.h" #include <mach/mach.h> +#include <signal.h> #include <spawn.h> #include <sys/fcntl.h> #include <sys/types.h> @@ -1653,10 +1654,17 @@ MachProcess::PosixSpawnChildForPTraceDebugging if (err.Fail()) return INVALID_NUB_PROCESS; - flags = POSIX_SPAWN_START_SUSPENDED; + flags = POSIX_SPAWN_START_SUSPENDED | POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK; if (disable_aslr) flags |= _POSIX_SPAWN_DISABLE_ASLR; - + + sigset_t no_signals; + sigset_t all_signals; + sigemptyset (&no_signals); + sigfillset (&all_signals); + ::posix_spawnattr_setsigmask(&attr, &no_signals); + ::posix_spawnattr_setsigdefault(&attr, &all_signals); + err.SetError( ::posix_spawnattr_setflags (&attr, flags), DNBError::POSIX); if (err.Fail() || DNBLogCheckLogBit(LOG_PROCESS)) err.LogThreaded("::posix_spawnattr_setflags ( &attr, POSIX_SPAWN_START_SUSPENDED%s )", flags & _POSIX_SPAWN_DISABLE_ASLR ? " | _POSIX_SPAWN_DISABLE_ASLR" : ""); |

