OLD | NEW |
1 // Copyright (c) 2010 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> |
| 11 |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" |
12 #include "base/mac/foundation_util.h" | 15 #include "base/mac/foundation_util.h" |
13 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
14 #include "base/mac/scoped_nsautorelease_pool.h" | 17 #include "base/mac/scoped_nsautorelease_pool.h" |
15 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/process_util.h" |
16 #include "base/scoped_nsobject.h" | 20 #include "base/scoped_nsobject.h" |
| 21 #include "base/stringprintf.h" |
17 #include "base/string_util.h" | 22 #include "base/string_util.h" |
18 #include "base/sys_string_conversions.h" | 23 #include "base/sys_string_conversions.h" |
19 #include "base/threading/thread_restrictions.h" | 24 #include "base/threading/thread_restrictions.h" |
20 #include "base/version.h" | 25 #include "base/version.h" |
21 #include "chrome/common/child_process_host.h" | 26 #include "chrome/common/child_process_host.h" |
22 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/chrome_version_info.h" | 29 #include "chrome/common/chrome_version_info.h" |
25 #include "third_party/GTM/Foundation/GTMServiceManagement.h" | 30 #include "chrome/common/launchd_mac.h" |
26 | 31 |
27 namespace { | 32 namespace { |
28 | 33 |
29 NSString* GetServiceProcessLaunchDFileName() { | 34 #define kServiceProcessSessionType "Background" |
30 NSString *bundle_id = [base::mac::MainAppBundle() bundleIdentifier]; | 35 |
31 NSString *label = [bundle_id stringByAppendingPathExtension:@"plist"]; | 36 CFStringRef CopyServiceProcessLaunchDName() { |
32 return label; | 37 base::mac::ScopedNSAutoreleasePool pool; |
| 38 NSBundle* bundle = base::mac::MainAppBundle(); |
| 39 return CFStringCreateCopy(kCFAllocatorDefault, |
| 40 base::mac::NSToCFCast([bundle bundleIdentifier])); |
33 } | 41 } |
34 | 42 |
35 NSString* GetServiceProcessLaunchDLabel() { | 43 NSString* GetServiceProcessLaunchDLabel() { |
36 NSString *bundle_id = [base::mac::MainAppBundle() bundleIdentifier]; | 44 scoped_nsobject<NSString> name( |
37 NSString *label = [bundle_id stringByAppendingString:@".service_process"]; | 45 base::mac::CFToNSCast(CopyServiceProcessLaunchDName())); |
| 46 NSString *label = [name stringByAppendingString:@".service_process"]; |
38 FilePath user_data_dir; | 47 FilePath user_data_dir; |
39 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 48 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
40 std::string user_data_dir_path = user_data_dir.value(); | 49 std::string user_data_dir_path = user_data_dir.value(); |
41 NSString *ns_path = base::SysUTF8ToNSString(user_data_dir_path); | 50 NSString *ns_path = base::SysUTF8ToNSString(user_data_dir_path); |
42 ns_path = [ns_path stringByReplacingOccurrencesOfString:@" " | 51 ns_path = [ns_path stringByReplacingOccurrencesOfString:@" " |
43 withString:@"_"]; | 52 withString:@"_"]; |
44 label = [label stringByAppendingString:ns_path]; | 53 label = [label stringByAppendingString:ns_path]; |
45 return label; | 54 return label; |
46 } | 55 } |
47 | 56 |
48 NSString* GetServiceProcessLaunchDSocketKey() { | 57 NSString* GetServiceProcessLaunchDSocketKey() { |
49 return @"ServiceProcessSocket"; | 58 return @"ServiceProcessSocket"; |
50 } | 59 } |
51 | 60 |
52 NSString* GetServiceProcessLaunchDSocketEnvVar() { | 61 NSString* GetServiceProcessLaunchDSocketEnvVar() { |
53 NSString *label = GetServiceProcessLaunchDLabel(); | 62 NSString *label = GetServiceProcessLaunchDLabel(); |
54 NSString *env_var = [label stringByReplacingOccurrencesOfString:@"." | 63 NSString *env_var = [label stringByReplacingOccurrencesOfString:@"." |
55 withString:@"_"]; | 64 withString:@"_"]; |
56 env_var = [env_var stringByAppendingString:@"_SOCKET"]; | 65 env_var = [env_var stringByAppendingString:@"_SOCKET"]; |
57 env_var = [env_var uppercaseString]; | 66 env_var = [env_var uppercaseString]; |
58 return env_var; | 67 return env_var; |
59 } | 68 } |
60 | 69 |
61 // Creates the path that it returns. Must be called on the FILE thread. | 70 bool GetParentFSRef(const FSRef& child, FSRef* parent) { |
62 NSURL* GetUserAgentPath() { | 71 return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr; |
63 NSArray* library_paths = NSSearchPathForDirectoriesInDomains( | |
64 NSLibraryDirectory, NSUserDomainMask, true); | |
65 DCHECK_EQ([library_paths count], 1U); | |
66 NSString* library_path = [library_paths objectAtIndex:0]; | |
67 NSString* launch_agents_path = | |
68 [library_path stringByAppendingPathComponent:@"LaunchAgents"]; | |
69 | |
70 NSError* err; | |
71 if (![[NSFileManager defaultManager] createDirectoryAtPath:launch_agents_path | |
72 withIntermediateDirectories:YES | |
73 attributes:nil | |
74 error:&err]) { | |
75 LOG(ERROR) << "GetUserAgentPath: " << err; | |
76 } | |
77 | |
78 NSString* plist_file_path = | |
79 [launch_agents_path | |
80 stringByAppendingPathComponent:GetServiceProcessLaunchDFileName()]; | |
81 return [NSURL fileURLWithPath:plist_file_path isDirectory:NO]; | |
82 } | 72 } |
83 | 73 |
84 } | 74 class ExecFilePathWatcherDelegate : public FilePathWatcher::Delegate { |
| 75 public: |
| 76 ExecFilePathWatcherDelegate() : process_state_(NULL) { } |
| 77 bool Init(const FilePath& path, ServiceProcessState *process_state); |
| 78 virtual ~ExecFilePathWatcherDelegate() { } |
| 79 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; |
| 80 |
| 81 private: |
| 82 FSRef executable_fsref_; |
| 83 ServiceProcessState* process_state_; |
| 84 }; |
| 85 |
| 86 } // namespace |
85 | 87 |
86 // Gets the name of the service process IPC channel. | 88 // Gets the name of the service process IPC channel. |
87 IPC::ChannelHandle GetServiceProcessChannel() { | 89 IPC::ChannelHandle GetServiceProcessChannel() { |
| 90 base::mac::ScopedNSAutoreleasePool pool; |
88 std::string socket_path; | 91 std::string socket_path; |
89 scoped_nsobject<NSDictionary> dictionary( | 92 scoped_nsobject<NSDictionary> dictionary( |
90 base::mac::CFToNSCast(GTMCopyLaunchdExports())); | 93 base::mac::CFToNSCast(Launchd::GetInstance()->CopyExports())); |
91 NSString *ns_socket_path = | 94 NSString *ns_socket_path = |
92 [dictionary objectForKey:GetServiceProcessLaunchDSocketEnvVar()]; | 95 [dictionary objectForKey:GetServiceProcessLaunchDSocketEnvVar()]; |
93 if (ns_socket_path) { | 96 if (ns_socket_path) { |
94 socket_path = base::SysNSStringToUTF8(ns_socket_path); | 97 socket_path = base::SysNSStringToUTF8(ns_socket_path); |
95 } | 98 } |
96 return IPC::ChannelHandle(socket_path); | 99 return IPC::ChannelHandle(socket_path); |
97 } | 100 } |
98 | 101 |
99 bool ForceServiceProcessShutdown(const std::string& /* version */, | 102 bool ForceServiceProcessShutdown(const std::string& /* version */, |
100 base::ProcessId /* process_id */) { | 103 base::ProcessId /* process_id */) { |
101 NSString* label = GetServiceProcessLaunchDLabel(); | 104 base::mac::ScopedNSAutoreleasePool pool; |
| 105 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
102 CFErrorRef err = NULL; | 106 CFErrorRef err = NULL; |
103 bool ret = GTMSMJobRemove(reinterpret_cast<CFStringRef>(label), &err); | 107 bool ret = Launchd::GetInstance()->RemoveJob(label, &err); |
104 if (!ret) { | 108 if (!ret) { |
105 LOG(ERROR) << "ForceServiceProcessShutdown: " << err; | 109 LOG(ERROR) << "ForceServiceProcessShutdown: " << err; |
106 CFRelease(err); | 110 CFRelease(err); |
107 } | 111 } |
108 return ret; | 112 return ret; |
109 } | 113 } |
110 | 114 |
111 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { | 115 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { |
112 CFStringRef label = | 116 base::mac::ScopedNSAutoreleasePool pool; |
113 reinterpret_cast<CFStringRef>(GetServiceProcessLaunchDLabel()); | 117 CFStringRef label = base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
114 scoped_nsobject<NSDictionary> launchd_conf( | 118 scoped_nsobject<NSDictionary> launchd_conf(base::mac::CFToNSCast( |
115 base::mac::CFToNSCast(GTMSMJobCopyDictionary(label))); | 119 Launchd::GetInstance()->CopyJobDictionary(label))); |
116 if (!launchd_conf.get()) { | 120 if (!launchd_conf.get()) { |
117 return false; | 121 return false; |
118 } | 122 } |
119 // Anything past here will return true in that there does appear | 123 // Anything past here will return true in that there does appear |
120 // to be a service process of some sort registered with launchd. | 124 // to be a service process of some sort registered with launchd. |
121 if (version) { | 125 if (version) { |
122 *version = "0"; | 126 *version = "0"; |
123 NSString *exe_path = [launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; | 127 NSString *exe_path = [launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; |
124 if (exe_path) { | 128 if (exe_path) { |
125 NSString *bundle_path = [[[exe_path stringByDeletingLastPathComponent] | 129 NSString *bundle_path = [[[exe_path stringByDeletingLastPathComponent] |
(...skipping 27 matching lines...) Expand all Loading... |
153 } | 157 } |
154 } | 158 } |
155 return true; | 159 return true; |
156 } | 160 } |
157 | 161 |
158 bool ServiceProcessState::Initialize() { | 162 bool ServiceProcessState::Initialize() { |
159 if (!InitializeState()) { | 163 if (!InitializeState()) { |
160 return false; | 164 return false; |
161 } | 165 } |
162 CFErrorRef err = NULL; | 166 CFErrorRef err = NULL; |
163 state_->launchd_conf_.reset(GTMSMJobCheckIn(&err)); | 167 CFDictionaryRef dict = |
164 if (!state_->launchd_conf_.get()) { | 168 Launchd::GetInstance()->CopyDictionaryByCheckingIn(&err); |
165 LOG(ERROR) << "InitializePlatformState: " << err; | 169 |
| 170 if (!dict) { |
| 171 LOG(ERROR) << "CopyLaunchdDictionaryByCheckingIn: " << err; |
166 CFRelease(err); | 172 CFRelease(err); |
167 return false; | 173 return false; |
168 } | 174 } |
| 175 state_->launchd_conf_.reset(dict); |
169 return true; | 176 return true; |
170 } | 177 } |
171 | 178 |
172 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 179 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
173 CHECK(state_); | 180 CHECK(state_); |
174 NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf_); | 181 NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf_); |
175 NSDictionary* socket_dict = | 182 NSDictionary* socket_dict = |
176 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; | 183 [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; |
177 NSArray* sockets = | 184 NSArray* sockets = |
178 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; | 185 [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // relaunch the service automatically in any other case than exiting | 266 // relaunch the service automatically in any other case than exiting |
260 // cleanly with a 0 return code. | 267 // cleanly with a 0 return code. |
261 NSDictionary *keep_alive = | 268 NSDictionary *keep_alive = |
262 [NSDictionary | 269 [NSDictionary |
263 dictionaryWithObject:[NSNumber numberWithBool:NO] | 270 dictionaryWithObject:[NSNumber numberWithBool:NO] |
264 forKey:@ LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT]; | 271 forKey:@ LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT]; |
265 NSDictionary *auto_launchd_plist = | 272 NSDictionary *auto_launchd_plist = |
266 [[NSDictionary alloc] initWithObjectsAndKeys: | 273 [[NSDictionary alloc] initWithObjectsAndKeys: |
267 [NSNumber numberWithBool:YES], @ LAUNCH_JOBKEY_RUNATLOAD, | 274 [NSNumber numberWithBool:YES], @ LAUNCH_JOBKEY_RUNATLOAD, |
268 keep_alive, @ LAUNCH_JOBKEY_KEEPALIVE, | 275 keep_alive, @ LAUNCH_JOBKEY_KEEPALIVE, |
269 @"Background", @ LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE, | 276 @ kServiceProcessSessionType, @ LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE, |
270 nil]; | 277 nil]; |
271 [launchd_plist addEntriesFromDictionary:auto_launchd_plist]; | 278 [launchd_plist addEntriesFromDictionary:auto_launchd_plist]; |
272 } | 279 } |
273 return reinterpret_cast<CFDictionaryRef>(launchd_plist); | 280 return reinterpret_cast<CFDictionaryRef>(launchd_plist); |
274 } | 281 } |
275 | 282 |
276 // Writes the launchd property list into the user's LaunchAgents directory, | 283 // Writes the launchd property list into the user's LaunchAgents directory, |
277 // creating that directory if needed. This will cause the service process to be | 284 // creating that directory if needed. This will cause the service process to be |
278 // auto launched on the next user login. | 285 // auto launched on the next user login. |
279 bool ServiceProcessState::AddToAutoRun() { | 286 bool ServiceProcessState::AddToAutoRun() { |
280 // We're creating directories and writing a file. | 287 // We're creating directories and writing a file. |
281 base::ThreadRestrictions::AssertIOAllowed(); | 288 base::ThreadRestrictions::AssertIOAllowed(); |
282 DCHECK(autorun_command_line_.get()); | 289 DCHECK(autorun_command_line_.get()); |
283 | 290 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName()); |
284 base::mac::ScopedNSAutoreleasePool pool; | 291 base::mac::ScopedCFTypeRef<CFDictionaryRef> plist( |
285 scoped_nsobject<NSDictionary> plist( | 292 CreateServiceProcessLaunchdPlist(autorun_command_line_.get(), true)); |
286 base::mac::CFToNSCast(CreateServiceProcessLaunchdPlist( | 293 return Launchd::GetInstance()->WritePlistToFile(Launchd::User, |
287 autorun_command_line_.get(), true))); | 294 Launchd::Agent, |
288 NSURL* plist_url = GetUserAgentPath(); | 295 name, |
289 return [plist writeToURL:plist_url atomically:YES]; | 296 plist); |
290 } | 297 } |
291 | 298 |
292 bool ServiceProcessState::RemoveFromAutoRun() { | 299 bool ServiceProcessState::RemoveFromAutoRun() { |
293 // We're killing a file. | 300 // We're killing a file. |
294 base::ThreadRestrictions::AssertIOAllowed(); | 301 base::ThreadRestrictions::AssertIOAllowed(); |
| 302 base::mac::ScopedCFTypeRef<CFStringRef> name(CopyServiceProcessLaunchDName()); |
| 303 return Launchd::GetInstance()->DeletePlist(Launchd::User, |
| 304 Launchd::Agent, |
| 305 name); |
| 306 } |
295 | 307 |
| 308 void ServiceProcessState::StateData::WatchExecutable() { |
296 base::mac::ScopedNSAutoreleasePool pool; | 309 base::mac::ScopedNSAutoreleasePool pool; |
297 NSURL* plist_url = GetUserAgentPath(); | 310 NSDictionary* ns_launchd_conf = base::mac::CFToNSCast(launchd_conf_); |
298 SInt32 error = 0; | 311 NSString* exe_path = [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_PROGRAM]; |
299 if (!CFURLDestroyResource(reinterpret_cast<CFURLRef>(plist_url), &error)) { | 312 if (!exe_path) { |
300 LOG(ERROR) << "RemoveFromAutoRun: " << error; | 313 LOG(ERROR) << "No " LAUNCH_JOBKEY_PROGRAM; |
| 314 return; |
| 315 } |
| 316 |
| 317 FilePath executable_path = FilePath([exe_path fileSystemRepresentation]); |
| 318 scoped_ptr<ExecFilePathWatcherDelegate> delegate( |
| 319 new ExecFilePathWatcherDelegate); |
| 320 if (!delegate->Init(executable_path, state_)) { |
| 321 LOG(ERROR) << "executable_watcher_.Init " << executable_path.value(); |
| 322 return; |
| 323 } |
| 324 if (!executable_watcher_.Watch(executable_path, delegate.release())) { |
| 325 LOG(ERROR) << "executable_watcher_.watch " << executable_path.value(); |
| 326 return; |
| 327 } |
| 328 } |
| 329 |
| 330 bool ExecFilePathWatcherDelegate::Init(const FilePath& path, |
| 331 ServiceProcessState *process_state) { |
| 332 if (!process_state || |
| 333 !base::mac::FSRefFromPath(path.value(), &executable_fsref_)) { |
301 return false; | 334 return false; |
302 } | 335 } |
| 336 process_state_ = process_state; |
303 return true; | 337 return true; |
304 } | 338 } |
| 339 |
| 340 void ExecFilePathWatcherDelegate::OnFilePathChanged(const FilePath& path) { |
| 341 base::mac::ScopedNSAutoreleasePool pool; |
| 342 bool needs_shutdown = false; |
| 343 bool needs_restart = false; |
| 344 bool good_bundle = false; |
| 345 |
| 346 FSRef macos_fsref; |
| 347 if (GetParentFSRef(executable_fsref_, &macos_fsref)) { |
| 348 FSRef contents_fsref; |
| 349 if (GetParentFSRef(macos_fsref, &contents_fsref)) { |
| 350 FSRef bundle_fsref; |
| 351 if (GetParentFSRef(contents_fsref, &bundle_fsref)) { |
| 352 base::mac::ScopedCFTypeRef<CFURLRef> bundle_url( |
| 353 CFURLCreateFromFSRef(kCFAllocatorDefault, &bundle_fsref)); |
| 354 if (bundle_url.get()) { |
| 355 base::mac::ScopedCFTypeRef<CFBundleRef> bundle( |
| 356 CFBundleCreate(kCFAllocatorDefault, bundle_url)); |
| 357 // Check to see if the bundle still has a minimal structure. |
| 358 good_bundle = CFBundleGetIdentifier(bundle) != NULL; |
| 359 } |
| 360 } |
| 361 } |
| 362 } |
| 363 if (!good_bundle) { |
| 364 needs_shutdown = true; |
| 365 } else { |
| 366 Boolean in_trash; |
| 367 OSErr err = FSDetermineIfRefIsEnclosedByFolder(kOnAppropriateDisk, |
| 368 kTrashFolderType, |
| 369 &executable_fsref_, |
| 370 &in_trash); |
| 371 if (err == noErr && in_trash) { |
| 372 needs_shutdown = true; |
| 373 } else { |
| 374 bool was_moved = true; |
| 375 FSRef path_ref; |
| 376 if (base::mac::FSRefFromPath(path.value(), &path_ref)) { |
| 377 if (FSCompareFSRefs(&path_ref, &executable_fsref_) == noErr) { |
| 378 was_moved = false; |
| 379 } |
| 380 } |
| 381 if (was_moved) { |
| 382 needs_restart = true; |
| 383 } |
| 384 } |
| 385 } |
| 386 if (needs_shutdown || needs_restart) { |
| 387 // First deal with the plist. |
| 388 base::mac::ScopedCFTypeRef<CFStringRef> name( |
| 389 CopyServiceProcessLaunchDName()); |
| 390 if (needs_restart) { |
| 391 base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> plist( |
| 392 Launchd::GetInstance()->CreatePlistFromFile(Launchd::User, |
| 393 Launchd::Agent, |
| 394 name)); |
| 395 if (plist.get()) { |
| 396 NSMutableDictionary* ns_plist = base::mac::CFToNSCast(plist); |
| 397 std::string new_path = base::mac::PathFromFSRef(executable_fsref_); |
| 398 NSString* ns_new_path = base::SysUTF8ToNSString(new_path); |
| 399 [ns_plist setObject:ns_new_path forKey:@ LAUNCH_JOBKEY_PROGRAM]; |
| 400 scoped_nsobject<NSMutableArray> args( |
| 401 [[ns_plist objectForKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS] |
| 402 mutableCopy]); |
| 403 [args replaceObjectAtIndex:0 withObject:ns_new_path]; |
| 404 [ns_plist setObject:args forKey:@ LAUNCH_JOBKEY_PROGRAMARGUMENTS]; |
| 405 if (!Launchd::GetInstance()->WritePlistToFile(Launchd::User, |
| 406 Launchd::Agent, |
| 407 name, |
| 408 plist)) { |
| 409 LOG(ERROR) << "Unable to rewrite plist."; |
| 410 needs_shutdown = true; |
| 411 } |
| 412 } else { |
| 413 LOG(ERROR) << "Unable to read plist."; |
| 414 needs_shutdown = true; |
| 415 } |
| 416 } |
| 417 if (needs_shutdown) { |
| 418 if (!process_state_->RemoveFromAutoRun()) { |
| 419 LOG(ERROR) << "Unable to RemoveFromAutoRun."; |
| 420 } |
| 421 } |
| 422 |
| 423 // Then deal with the process. |
| 424 CFStringRef session_type = CFSTR(kServiceProcessSessionType); |
| 425 if (needs_restart) { |
| 426 if (!Launchd::GetInstance()->RestartJob(Launchd::User, |
| 427 Launchd::Agent, |
| 428 name, |
| 429 session_type)) { |
| 430 LOG(ERROR) << "RestartLaunchdJob"; |
| 431 needs_shutdown = true; |
| 432 } |
| 433 } |
| 434 if (needs_shutdown) { |
| 435 CFStringRef label = |
| 436 base::mac::NSToCFCast(GetServiceProcessLaunchDLabel()); |
| 437 CFErrorRef err = NULL; |
| 438 if (!Launchd::GetInstance()->RemoveJob(label, &err)) { |
| 439 base::mac::ScopedCFTypeRef<CFErrorRef> scoped_err(err); |
| 440 LOG(ERROR) << "RemoveJob " << err; |
| 441 // Exiting with zero, so launchd doesn't restart the process. |
| 442 exit(0); |
| 443 } |
| 444 } |
| 445 } |
| 446 } |
OLD | NEW |