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
This commit is contained in:
Greg Clayton 2011-10-28 01:24:12 +00:00
parent 52c7d20241
commit 708c1ab6f5
3 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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: ");

View File

@ -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" : "");