Commit 53ab7dd4 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

[Fuchsia] Set name suffix for web_engine processes.

Previously all web_engine processes had the same name, which made it
hard to distinguish between processes. Now each process started by
web_engine will have the name suffixed with process type, e.g.
web_engine_exe:renderer.

Change-Id: Ic1fa0f4f7bc87f4789d0d6d85d71d836d89df99f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769996
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Auto-Submit: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690787}
parent 065f3ec5
...@@ -254,6 +254,10 @@ struct BASE_EXPORT LaunchOptions { ...@@ -254,6 +254,10 @@ struct BASE_EXPORT LaunchOptions {
// child process' namespace. Paths installed by |paths_to_clone| will be // child process' namespace. Paths installed by |paths_to_clone| will be
// overridden by these entries. // overridden by these entries.
std::vector<PathToTransfer> paths_to_transfer; std::vector<PathToTransfer> paths_to_transfer;
// Suffix that will be added to the process name. When specified process name
// will be set to "<binary_name><process_suffix>".
std::string process_name_suffix;
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
#if defined(OS_POSIX) #if defined(OS_POSIX)
......
...@@ -91,6 +91,12 @@ fdio_spawn_action_t FdioSpawnActionAddHandle(uint32_t id, zx_handle_t handle) { ...@@ -91,6 +91,12 @@ fdio_spawn_action_t FdioSpawnActionAddHandle(uint32_t id, zx_handle_t handle) {
return action; return action;
} }
fdio_spawn_action_t FdioSpawnActionSetName(const char* name) {
fdio_spawn_action_t action = FdioSpawnAction(FDIO_SPAWN_ACTION_SET_NAME);
action.name.data = name;
return action;
}
} // namespace } // namespace
// static // static
...@@ -206,6 +212,15 @@ Process LaunchProcess(const std::vector<std::string>& argv, ...@@ -206,6 +212,15 @@ Process LaunchProcess(const std::vector<std::string>& argv,
FdioSpawnActionCloneFd(src_target.first, src_target.second)); FdioSpawnActionCloneFd(src_target.first, src_target.second));
} }
// If |process_name_suffix| is specified then set process name as
// "<file_name><suffix>", otherwise leave the default value.
std::string process_name;
if (!options.process_name_suffix.empty()) {
process_name = base::FilePath(argv[0]).BaseName().value() +
options.process_name_suffix;
spawn_actions.push_back(FdioSpawnActionSetName(process_name.c_str()));
}
zx::process process_handle; zx::process process_handle;
// fdio_spawn_etc() will write a null-terminated scring to |error_message| in // fdio_spawn_etc() will write a null-terminated scring to |error_message| in
// case of failure, so we avoid unnecessarily initializing it here. // case of failure, so we avoid unnecessarily initializing it here.
......
...@@ -476,6 +476,22 @@ TEST_F(ProcessUtilTest, HandlesToTransferClosedOnBadPathToMapFailure) { ...@@ -476,6 +476,22 @@ TEST_F(ProcessUtilTest, HandlesToTransferClosedOnBadPathToMapFailure) {
EXPECT_EQ(ZX_ERR_BAD_HANDLE, zx_handle_close(handles[0].get())); EXPECT_EQ(ZX_ERR_BAD_HANDLE, zx_handle_close(handles[0].get()));
ignore_result(handles[0].release()); ignore_result(handles[0].release());
} }
TEST_F(ProcessUtilTest, FuchsiaProcessNameSuffix) {
LaunchOptions options;
options.process_name_suffix = "#test";
Process process(SpawnChildWithOptions("SimpleChildProcess", options));
char name[256] = {};
size_t name_size = sizeof(name);
zx_status_t status =
zx_object_get_property(process.Handle(), ZX_PROP_NAME, name, name_size);
ASSERT_EQ(status, ZX_OK);
EXPECT_EQ(std::string(name),
CommandLine::ForCurrentProcess()->GetProgram().BaseName().value() +
"#test");
}
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
// On Android SpawnProcess() doesn't use LaunchProcess() and doesn't support // On Android SpawnProcess() doesn't use LaunchProcess() and doesn't support
......
...@@ -6,14 +6,41 @@ ...@@ -6,14 +6,41 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/strings/stringprintf.h"
#include "content/browser/child_process_launcher.h" #include "content/browser/child_process_launcher.h"
#include "content/public/browser/child_process_launcher_utils.h" #include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h" #include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "services/service_manager/embedder/result_codes.h" #include "services/service_manager/embedder/result_codes.h"
#include "services/service_manager/embedder/switches.h"
namespace content { namespace content {
namespace internal { namespace internal {
namespace {
const char* ProcessNameFromSandboxType(
service_manager::SandboxType sandbox_type) {
switch (sandbox_type) {
case service_manager::SANDBOX_TYPE_NO_SANDBOX:
return nullptr;
case service_manager::SANDBOX_TYPE_WEB_CONTEXT:
return "context";
case service_manager::SANDBOX_TYPE_RENDERER:
return "renderer";
case service_manager::SANDBOX_TYPE_UTILITY:
return "utility";
case service_manager::SANDBOX_TYPE_GPU:
return "gpu";
case service_manager::SANDBOX_TYPE_NETWORK:
return "network";
default:
NOTREACHED() << sandbox_type;
return nullptr;
}
}
} // namespace
void ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread( void ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread(
base::Process process, base::Process process,
const ChildProcessLauncherPriority& priority) { const ChildProcessLauncherPriority& priority) {
...@@ -68,6 +95,12 @@ bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( ...@@ -68,6 +95,12 @@ bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread(
command_line()); command_line());
sandbox_policy_.UpdateLaunchOptionsForSandbox(options); sandbox_policy_.UpdateLaunchOptionsForSandbox(options);
// Set process name suffix to make it easier to identify the process.
const char* process_type =
ProcessNameFromSandboxType(delegate_->GetSandboxType());
if (process_type)
options->process_name_suffix = base::StringPrintf(":%s", process_type);
return true; return true;
} }
......
...@@ -84,6 +84,8 @@ void ContextProviderImpl::Create( ...@@ -84,6 +84,8 @@ void ContextProviderImpl::Create(
} }
base::LaunchOptions launch_options; base::LaunchOptions launch_options;
launch_options.process_name_suffix = ":context";
service_manager::SandboxPolicyFuchsia sandbox_policy; service_manager::SandboxPolicyFuchsia sandbox_policy;
sandbox_policy.Initialize(service_manager::SANDBOX_TYPE_WEB_CONTEXT); sandbox_policy.Initialize(service_manager::SANDBOX_TYPE_WEB_CONTEXT);
sandbox_policy.SetServiceDirectory(std::move(service_directory)); sandbox_policy.SetServiceDirectory(std::move(service_directory));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment