Index: chrome/common/service_process_util_mac.mm |
diff --git a/chrome/common/service_process_util_mac.mm b/chrome/common/service_process_util_mac.mm |
index bf68feb65b5fe8ebeac7955c7583efa38b34c9f5..3bb8b9cff2a40989aed9607c6d00c23ebfbabbb9 100644 |
--- a/chrome/common/service_process_util_mac.mm |
+++ b/chrome/common/service_process_util_mac.mm |
@@ -27,6 +27,7 @@ |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
#include "chrome/common/mac/launchd.h" |
+#include "ipc/unix_domain_socket_util.h" |
using ::base::FilePathWatcher; |
@@ -55,10 +56,6 @@ NSString* GetServiceProcessLaunchDLabel() { |
return label; |
} |
-NSString* GetServiceProcessLaunchDSocketKey() { |
- return @"ServiceProcessSocket"; |
-} |
- |
bool GetParentFSRef(const FSRef& child, FSRef* parent) { |
return FSGetCatalogInfo(&child, 0, NULL, NULL, NULL, parent) == noErr; |
} |
@@ -84,29 +81,23 @@ class ExecFilePathWatcherCallback { |
FSRef executable_fsref_; |
}; |
-} // namespace |
- |
-NSString* GetServiceProcessLaunchDSocketEnvVar() { |
- NSString *label = GetServiceProcessLaunchDLabel(); |
- NSString *env_var = [label stringByReplacingOccurrencesOfString:@"." |
- withString:@"_"]; |
- env_var = [env_var stringByAppendingString:@"_SOCKET"]; |
- env_var = [env_var uppercaseString]; |
- return env_var; |
+base::FilePath GetServiceProcessSocketName() { |
+ base::FilePath socket_name; |
+ PathService::Get(base::DIR_TEMP, &socket_name); |
+ std::string pipe_name = GetServiceProcessScopedName("srv"); |
+ socket_name = socket_name.Append(pipe_name); |
+ if (socket_name.value().size() < IPC::kMaxSocketNameLength) |
+ return socket_name; |
+ // Fallback to /tmp if $TMPDIR is too long. |
Robert Sesek
2015/03/05 22:34:02
When would this happen?
Vitaly Buka (NO REVIEWS)
2015/03/05 23:22:13
kMaxSocketNameLength is 104
name generated on my
|
+ return base::FilePath("/tmp").Append(pipe_name); |
} |
-// Gets the name of the service process IPC channel. |
+} // namespace |
+ |
IPC::ChannelHandle GetServiceProcessChannel() { |
- base::mac::ScopedNSAutoreleasePool pool; |
- std::string socket_path; |
- base::scoped_nsobject<NSDictionary> dictionary( |
- base::mac::CFToNSCast(Launchd::GetInstance()->CopyExports())); |
- NSString *ns_socket_path = |
- [dictionary objectForKey:GetServiceProcessLaunchDSocketEnvVar()]; |
- if (ns_socket_path) { |
- socket_path = base::SysNSStringToUTF8(ns_socket_path); |
- } |
- return IPC::ChannelHandle(socket_path); |
+ base::FilePath socket_name = GetServiceProcessSocketName(); |
+ VLOG(1) << "ServiceProcessChannel: " << socket_name.value(); |
+ return IPC::ChannelHandle(socket_name.value()); |
} |
bool ForceServiceProcessShutdown(const std::string& /* version */, |
@@ -185,22 +176,13 @@ bool ServiceProcessState::Initialize() { |
} |
IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
- DCHECK(state_); |
- NSDictionary *ns_launchd_conf = base::mac::CFToNSCast(state_->launchd_conf); |
- NSDictionary* socket_dict = |
- [ns_launchd_conf objectForKey:@ LAUNCH_JOBKEY_SOCKETS]; |
- NSArray* sockets = |
- [socket_dict objectForKey:GetServiceProcessLaunchDSocketKey()]; |
- DCHECK_EQ([sockets count], 1U); |
- int socket = [[sockets objectAtIndex:0] intValue]; |
- base::FileDescriptor fd(socket, false); |
- return IPC::ChannelHandle(std::string(), fd); |
+ return ::GetServiceProcessChannel(); |
} |
bool CheckServiceProcessReady() { |
std::string version; |
pid_t pid; |
- if (!GetServiceProcessData(&version, &pid)) { |
+ if (!GetServiceProcessData(&version, &pid) || pid == -1) { |
return false; |
} |
Version service_version(version); |
@@ -243,20 +225,13 @@ CFDictionaryRef CreateServiceProcessLaunchdPlist(base::CommandLine* cmd_line, |
[ns_args addObject:base::SysUTF8ToNSString(*iter)]; |
} |
- NSDictionary *socket = |
- [NSDictionary dictionaryWithObject:GetServiceProcessLaunchDSocketEnvVar() |
- forKey:@ LAUNCH_JOBSOCKETKEY_SECUREWITHKEY]; |
- NSDictionary *sockets = |
- [NSDictionary dictionaryWithObject:socket |
- forKey:GetServiceProcessLaunchDSocketKey()]; |
- |
// See the man page for launchd.plist. |
NSMutableDictionary *launchd_plist = |
[[NSMutableDictionary alloc] initWithObjectsAndKeys: |
GetServiceProcessLaunchDLabel(), @ LAUNCH_JOBKEY_LABEL, |
program, @ LAUNCH_JOBKEY_PROGRAM, |
ns_args, @ LAUNCH_JOBKEY_PROGRAMARGUMENTS, |
- sockets, @ LAUNCH_JOBKEY_SOCKETS, |
+ [NSNumber numberWithBool:YES], @ LAUNCH_JOBKEY_RUNATLOAD, |
Robert Sesek
2015/03/05 22:34:02
This is changing the RunAtLoad to be from only whe
Robert Sesek
2015/03/05 22:34:02
You can use @YES
Vitaly Buka (NO REVIEWS)
2015/03/05 23:22:13
Done.
Vitaly Buka (NO REVIEWS)
2015/03/05 23:22:13
for_auto_launch means that this file is going to b
|
nil]; |
if (for_auto_launch) { |
@@ -270,7 +245,6 @@ CFDictionaryRef CreateServiceProcessLaunchdPlist(base::CommandLine* cmd_line, |
forKey:@ LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT]; |
NSDictionary *auto_launchd_plist = |
[[NSDictionary alloc] initWithObjectsAndKeys: |
- [NSNumber numberWithBool:YES], @ LAUNCH_JOBKEY_RUNATLOAD, |
keep_alive, @ LAUNCH_JOBKEY_KEEPALIVE, |
@ kServiceProcessSessionType, @ LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE, |
nil]; |