Index: base/process/launch_posix.cc |
diff --git a/base/process/launch_posix.cc b/base/process/launch_posix.cc |
index 3708af6bac417b49e4015fed93eb49966ed78363..650744630a037e561d5670ad39d4171e4b5b83c3 100644 |
--- a/base/process/launch_posix.cc |
+++ b/base/process/launch_posix.cc |
@@ -77,23 +77,31 @@ void SetEnvironment(char** env) { |
#endif |
} |
+// List of signals that we want to block while forking and then reset |
+// to SIG_DFL in the child process. |
+// The previous signal handlers are likely to be meaningless in the child's |
+// context so we reset them to the defaults for now. http://crbug.com/44953 |
+// These signal handlers are set up at least in browser_main_posix.cc: |
+// BrowserMainPartsPosix::PreEarlyInitialization and stack_trace_posix.cc: |
+// EnableInProcessStackDumping. |
+const int kSignalsToReset[] = { |
jln (very slow on Chromium)
2013/07/31 23:54:55
This ignores the other implementation of ResetChil
mdempsky_google
2013/08/01 00:31:57
Uploaded a new patch that's slightly simpler and j
|
+ SIGHUP, |
+ SIGINT, |
+ SIGILL, |
+ SIGABRT, |
+ SIGFPE, |
+ SIGBUS, |
+ SIGSEGV, |
+ SIGSYS, |
+ SIGTERM, |
+}; |
+ |
#if !defined(OS_LINUX) || \ |
(!defined(__i386__) && !defined(__x86_64__) && !defined(__arm__)) |
void ResetChildSignalHandlersToDefaults() { |
- // The previous signal handlers are likely to be meaningless in the child's |
- // context so we reset them to the defaults for now. http://crbug.com/44953 |
- // These signal handlers are set up at least in browser_main_posix.cc: |
- // BrowserMainPartsPosix::PreEarlyInitialization and stack_trace_posix.cc: |
- // EnableInProcessStackDumping. |
- signal(SIGHUP, SIG_DFL); |
- signal(SIGINT, SIG_DFL); |
- signal(SIGILL, SIG_DFL); |
- signal(SIGABRT, SIG_DFL); |
- signal(SIGFPE, SIG_DFL); |
- signal(SIGBUS, SIG_DFL); |
- signal(SIGSEGV, SIG_DFL); |
- signal(SIGSYS, SIG_DFL); |
- signal(SIGTERM, SIG_DFL); |
+ for (size_t i = 0; i < arraysize(kSignalsToReset); i++) { |
+ signal(kSignalsToReset[i], SIG_DFL); |
+ } |
} |
#else |
@@ -394,6 +402,18 @@ bool LaunchProcess(const std::vector<std::string>& argv, |
if (options.environ) |
new_environ.reset(AlterEnvironment(*options.environ, GetEnvironment())); |
+ sigset_t sigs_to_block; |
+ sigemptyset(&sigs_to_block); |
+ for (size_t i = 0; i < arraysize(kSignalsToReset); i++) { |
+ sigaddset(&sigs_to_block, kSignalsToReset[i]); |
+ } |
+ |
+ sigset_t old_sigset; |
+ if (pthread_sigmask(SIG_BLOCK, &sigs_to_block, &old_sigset) != 0) { |
+ DPLOG(ERROR) << "pthread_sigmask"; |
+ return false; |
+ } |
+ |
pid_t pid; |
#if defined(OS_LINUX) |
if (options.clone_flags) { |
@@ -404,6 +424,12 @@ bool LaunchProcess(const std::vector<std::string>& argv, |
pid = fork(); |
} |
+ if (pid != 0) { |
+ if (pthread_sigmask(SIG_SETMASK, &old_sigset, NULL) != 0) { |
+ NOTREACHED(); |
+ } |
+ } |
+ |
if (pid < 0) { |
DPLOG(ERROR) << "fork"; |
return false; |