From e7b75dbcc3a668ab64b0daa263a6e336fe59f8e3 Mon Sep 17 00:00:00 2001 From: "mark@chromium.org" Date: Mon, 3 Oct 2011 19:54:28 +0000 Subject: 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 --- src/client/mac/Framework/OnDemandServer.mm | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src') 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(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(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(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; } -- cgit v1.2.1