| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/service_process_util_posix.h" | 5 #include "chrome/common/service_process_util_posix.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <launch.h> | 8 #include <launch.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 return IPC::ChannelHandle(socket_path); | 113 return IPC::ChannelHandle(socket_path); |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool ForceServiceProcessShutdown(const std::string& /* version */, | 116 bool ForceServiceProcessShutdown(const std::string& /* version */, |
| 117 base::ProcessId /* process_id */) { | 117 base::ProcessId /* process_id */) { |
| 118 base::mac::ScopedNSAutoreleasePool pool; | 118 base::mac::ScopedNSAutoreleasePool pool; |
| 119 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); | 119 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
| 120 CFErrorRef err = NULL; | 120 CFErrorRef err = NULL; |
| 121 bool ret = Launchd::GetInstance()->RemoveJob(label, &err); | 121 bool ret = Launchd::GetInstance()->RemoveJob(label, &err); |
| 122 if (!ret) { | 122 if (!ret) { |
| 123 LOG(ERROR) << "ForceServiceProcessShutdown: " << err; | 123 LOG(ERROR) << "ForceServiceProcessShutdown: " << err << " " |
| 124 << base::SysCFStringRefToUTF8(label); |
| 124 CFRelease(err); | 125 CFRelease(err); |
| 125 } | 126 } |
| 126 return ret; | 127 return ret; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { | 130 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { |
| 130 base::mac::ScopedNSAutoreleasePool pool; | 131 base::mac::ScopedNSAutoreleasePool pool; |
| 131 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); | 132 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
| 132 scoped_nsobject<NSDictionary> launchd_conf(base::mac::CFToNSCast( | 133 scoped_nsobject<NSDictionary> launchd_conf(base::mac::CFToNSCast( |
| 133 Launchd::GetInstance()->CopyJobDictionary(label))); | 134 Launchd::GetInstance()->CopyJobDictionary(label))); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 *pid = [ns_pid intValue]; | 171 *pid = [ns_pid intValue]; |
| 171 } | 172 } |
| 172 } | 173 } |
| 173 return true; | 174 return true; |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool ServiceProcessState::Initialize() { | 177 bool ServiceProcessState::Initialize() { |
| 177 CFErrorRef err = NULL; | 178 CFErrorRef err = NULL; |
| 178 CFDictionaryRef dict = | 179 CFDictionaryRef dict = |
| 179 Launchd::GetInstance()->CopyDictionaryByCheckingIn(&err); | 180 Launchd::GetInstance()->CopyDictionaryByCheckingIn(&err); |
| 180 | |
| 181 if (!dict) { | 181 if (!dict) { |
| 182 LOG(ERROR) << "CopyLaunchdDictionaryByCheckingIn: " << err; | 182 LOG(ERROR) << "ServiceProcess must be launched by launchd. " |
| 183 << "CopyLaunchdDictionaryByCheckingIn: " << err; |
| 183 CFRelease(err); | 184 CFRelease(err); |
| 184 return false; | 185 return false; |
| 185 } | 186 } |
| 186 state_->launchd_conf_.reset(dict); | 187 state_->launchd_conf_.reset(dict); |
| 187 return true; | 188 return true; |
| 188 } | 189 } |
| 189 | 190 |
| 190 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 191 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
| 191 CHECK(state_); | 192 CHECK(state_); |
| 192 NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf_); | 193 NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf_); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 CFErrorRef err = NULL; | 439 CFErrorRef err = NULL; |
| 439 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { | 440 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { |
| 440 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err); | 441 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err); |
| 441 LOG(ERROR) << "RemoveJob " << err; | 442 LOG(ERROR) << "RemoveJob " << err; |
| 442 // Exiting with zero, so launchd doesn't restart the process. | 443 // Exiting with zero, so launchd doesn't restart the process. |
| 443 exit(0); | 444 exit(0); |
| 444 } | 445 } |
| 445 } | 446 } |
| 446 } | 447 } |
| 447 } | 448 } |
| OLD | NEW |