diff options
author | mark@chromium.org <mark@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-10-03 19:54:28 +0000 |
---|---|---|
committer | mark@chromium.org <mark@chromium.org@4c0a9323-5329-0410-9bdc-e9ce6186880e> | 2011-10-03 19:54:28 +0000 |
commit | e7b75dbcc3a668ab64b0daa263a6e336fe59f8e3 (patch) | |
tree | 3eeed5293d061d833ef36efbb311f64fc308bb91 /src/client/mac | |
parent | Fix some compilation warnings and other errors due to API changes (diff) | |
download | breakpad-e7b75dbcc3a668ab64b0daa263a6e336fe59f8e3.tar.xz |
Use a bootstrap subset port for the inspector, tying the subset to the
lifetime of the task to be monitored, the invoking task. This allows the
bootstrap server (in launchd) to automatically clean up the Mach server
registration when the task being monitored exits, avoiding leaks of
com.Breakpad.Inspector(pid) ports in "launchctl bslist".
BUG=chromium:28547
TEST=Handler should still crash catches, but inspector ports should no longer
show up in "launchctl bslist". They should show up under a subset port in
"launchctl bstree" instead. "launchctl bstree" must be invoked as root.
Review URL: http://breakpad.appspot.com/306001
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@842 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/client/mac')
-rw-r--r-- | src/client/mac/Framework/OnDemandServer.mm | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/client/mac/Framework/OnDemandServer.mm b/src/client/mac/Framework/OnDemandServer.mm index 38685460..03f54c44 100644 --- a/src/client/mac/Framework/OnDemandServer.mm +++ b/src/client/mac/Framework/OnDemandServer.mm @@ -32,8 +32,11 @@ #if DEBUG #define PRINT_MACH_RESULT(result_, message_) \ printf(message_"%s (%d)\n", mach_error_string(result_), result_ ); + #define PRINT_BOOTSTRAP_RESULT(result_, message_) \ + printf(message_"%s (%d)\n", bootstrap_strerror(result_), result_ ); #else #define PRINT_MACH_RESULT(result_, message_) + #define PRINT_BOOTSTRAP_RESULT(result_, message_) #endif //============================================================================== @@ -67,15 +70,29 @@ kern_return_t OnDemandServer::Initialize(const char *server_command, bool unregister_on_cleanup) { unregister_on_cleanup_ = unregister_on_cleanup; - kern_return_t kr = - bootstrap_create_server(bootstrap_port, - const_cast<char*>(server_command), - geteuid(), // server uid - true, - &server_port_); + mach_port_t self_task = mach_task_self(); + mach_port_t bootstrap_port; + kern_return_t kr = task_get_bootstrap_port(self_task, &bootstrap_port); if (kr != KERN_SUCCESS) { - PRINT_MACH_RESULT(kr, "bootstrap_create_server() : "); + PRINT_MACH_RESULT(kr, "task_get_bootstrap_port(): "); + return kr; + } + + mach_port_t bootstrap_subset_port; + kr = bootstrap_subset(bootstrap_port, self_task, &bootstrap_subset_port); + if (kr != KERN_SUCCESS) { + PRINT_BOOTSTRAP_RESULT(kr, "bootstrap_subset(): "); + return kr; + } + + kr = bootstrap_create_server(bootstrap_subset_port, + const_cast<char*>(server_command), + geteuid(), // server uid + true, + &server_port_); + if (kr != KERN_SUCCESS) { + PRINT_BOOTSTRAP_RESULT(kr, "bootstrap_create_server(): "); return kr; } @@ -86,15 +103,14 @@ kern_return_t OnDemandServer::Initialize(const char *server_command, kr = bootstrap_create_service(server_port_, const_cast<char*>(service_name), &service_port_); - if (kr != KERN_SUCCESS) { - PRINT_MACH_RESULT(kr, "bootstrap_create_service() : "); + PRINT_BOOTSTRAP_RESULT(kr, "bootstrap_create_service(): "); // perhaps the service has already been created - try to look it up kr = bootstrap_look_up(bootstrap_port, (char*)service_name, &service_port_); if (kr != KERN_SUCCESS) { - PRINT_MACH_RESULT(kr, "bootstrap_look_up() : "); + PRINT_BOOTSTRAP_RESULT(kr, "bootstrap_look_up(): "); Unregister(); // clean up server port return kr; } |