Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: chrome/common/service_process_util_mac.mm

Issue 982883003: Use fixed socket name instead of SecureSocketWithKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/service_process_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..128ed7c38ca79ff08d47c19a7567c1185fcb6ef3 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.
+ 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) {
Vitaly Buka (NO REVIEWS) 2015/03/06 01:51:08 this check was the reason why on demand didn't wor
return false;
}
Version service_version(version);
@@ -243,37 +225,26 @@ 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,
- nil];
+ NSMutableDictionary* launchd_plist = [[NSMutableDictionary alloc]
+ initWithObjectsAndKeys:GetServiceProcessLaunchDLabel(),
+ @LAUNCH_JOBKEY_LABEL, program,
+ @LAUNCH_JOBKEY_PROGRAM, ns_args,
+ @LAUNCH_JOBKEY_PROGRAMARGUMENTS, @YES,
+ @LAUNCH_JOBKEY_RUNATLOAD, nil];
if (for_auto_launch) {
// We want the service process to be able to exit if there are no services
// enabled. With a value of NO in the SuccessfulExit key, launchd will
// relaunch the service automatically in any other case than exiting
// cleanly with a 0 return code.
- NSDictionary *keep_alive =
- [NSDictionary
+ NSDictionary* keep_alive = [NSDictionary
dictionaryWithObject:[NSNumber numberWithBool:NO]
- 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];
+ forKey:@LAUNCH_JOBKEY_KEEPALIVE_SUCCESSFULEXIT];
+ NSDictionary* auto_launchd_plist = [[NSDictionary alloc]
+ initWithObjectsAndKeys:keep_alive, @LAUNCH_JOBKEY_KEEPALIVE,
+ @kServiceProcessSessionType,
+ @LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE, nil];
[launchd_plist addEntriesFromDictionary:auto_launchd_plist];
}
return reinterpret_cast<CFDictionaryRef>(launchd_plist);
« no previous file with comments | « chrome/common/service_process_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698