mac: Make UseSystemDefaultHandler() clear handlers on failure

If the task’s exception handler for EXC_CRASH, EXC_RESOURCE, and
EXC_GUARD exceptions cannot be set, clear the handler instead.

Nothing considered this function’s return value, and the only viable
fallback action on failure would have been to do what the function now
does, so its return type is changed to void.

R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1386943002 .
This commit is contained in:
Mark Mentovai 2015-10-05 17:12:04 -04:00
parent ca2925e2a0
commit c95b30464a
2 changed files with 9 additions and 10 deletions

View File

@ -128,22 +128,19 @@ class CrashpadClient {
//!
//! On OS X, this sets the tasks exception port as in UseHandler(), but the
//! exception handler used is obtained from SystemCrashReporterHandler(). If
//! the systems crash reporter handler cannot be determined, the tasks
//! exception ports for crash-type exceptions are cleared.
//! the systems crash reporter handler cannot be determined or set, the
//! tasks exception ports for crash-type exceptions are cleared.
//!
//! Use of this function is strongly discouraged.
//!
//! \warning After a successful call to this function, Crashpad will no longer
//! monitor the process for crashes until a subsequent call to
//! UseHandler().
//! \warning After a call to this function, Crashpad will no longer monitor
//! the process for crashes until a subsequent call to UseHandler().
//!
//! \note This is provided as a static function to allow it to be used in
//! situations where a CrashpadClient object is not otherwise available.
//! This may be useful when a child process inherits its parents Crashpad
//! handler, but wants to sever this tie.
//!
//! \return `true` on success, `false` on failure with a message logged.
static bool UseSystemDefaultHandler();
static void UseSystemDefaultHandler();
#endif
private:

View File

@ -221,13 +221,15 @@ bool CrashpadClient::UseHandler() {
}
// static
bool CrashpadClient::UseSystemDefaultHandler() {
void CrashpadClient::UseSystemDefaultHandler() {
base::mac::ScopedMachSendRight
system_crash_reporter_handler(SystemCrashReporterHandler());
// Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL
// to clear the current exception ports.
return SetCrashExceptionPorts(system_crash_reporter_handler);
if (!SetCrashExceptionPorts(system_crash_reporter_handler)) {
SetCrashExceptionPorts(MACH_PORT_NULL);
}
}
} // namespace crashpad