-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(posix): implement stdio pipe interface
- Loading branch information
1 parent
a6a886b
commit 504a928
Showing
6 changed files
with
578 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
patches/chromium/chore_posix_support_remapping_fds_when_launching_service_process.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: deepak1556 <hop2deep@gmail.com> | ||
Date: Wed, 17 Aug 2022 22:04:47 +0900 | ||
Subject: chore(posix): support remapping fds when launching service process | ||
|
||
Allows configuring base::LaunchOptions::fds_to_remap when launching the child process. | ||
An example use of this option, UtilityProcess API allows reading the output From | ||
stdout and stderr of child process by creating a pipe, whose write end is remapped | ||
to STDOUT_FILENO and STDERR_FILENO allowing the parent process to read from the pipe. | ||
|
||
diff --git a/content/browser/service_process_host_impl.cc b/content/browser/service_process_host_impl.cc | ||
index f232eb49fa86e202d1a8ac3f0ca1e7c3ca28baf1..4b6fb0d26e54983790613a96113c7a8181ece4fd 100644 | ||
--- a/content/browser/service_process_host_impl.cc | ||
+++ b/content/browser/service_process_host_impl.cc | ||
@@ -184,6 +184,9 @@ void LaunchServiceProcess(mojo::GenericPendingReceiver receiver, | ||
host->SetExtraCommandLineSwitches(std::move(options.extra_switches)); | ||
if (options.child_flags) | ||
host->set_child_flags(*options.child_flags); | ||
+#if BUILDFLAG(IS_POSIX) | ||
+ host->SetAdditionalFds(std::move(options.fds_to_remap)); | ||
+#endif | ||
host->Start(); | ||
host->GetChildProcess()->BindServiceInterface(std::move(receiver)); | ||
} | ||
diff --git a/content/browser/utility_process_host.cc b/content/browser/utility_process_host.cc | ||
index b96072fd917fce5cd8abb16a4ef705aea4dfe132..37a207eab8508ddc27227053a963a43f897a6dd0 100644 | ||
--- a/content/browser/utility_process_host.cc | ||
+++ b/content/browser/utility_process_host.cc | ||
@@ -153,6 +153,12 @@ void UtilityProcessHost::SetExtraCommandLineSwitches( | ||
extra_switches_ = std::move(switches); | ||
} | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+void UtilityProcessHost::SetAdditionalFds(base::FileHandleMappingVector mapping) { | ||
+ fds_to_remap_ = std::move(mapping); | ||
+} | ||
+#endif | ||
+ | ||
mojom::ChildProcess* UtilityProcessHost::GetChildProcess() { | ||
return static_cast<ChildProcessHostImpl*>(process_->GetHost()) | ||
->child_process(); | ||
@@ -357,6 +363,15 @@ bool UtilityProcessHost::StartProcess() { | ||
} | ||
#endif // BUILDFLAG(IS_CHROMEOS_LACROS) | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+ if (!fds_to_remap_.empty()) { | ||
+ for (const auto& remapped_fd : fds_to_remap_) { | ||
+ file_data->additional_remapped_fds.emplace( | ||
+ remapped_fd.second, remapped_fd.first); | ||
+ } | ||
+ } | ||
+#endif | ||
+ | ||
std::unique_ptr<UtilitySandboxedProcessLauncherDelegate> delegate = | ||
std::make_unique<UtilitySandboxedProcessLauncherDelegate>( | ||
sandbox_type_, env_, *cmd_line); | ||
diff --git a/content/browser/utility_process_host.h b/content/browser/utility_process_host.h | ||
index efacea697ca7ba48e2dfbd61b28b543018b697d8..7f27414311b38028ff0a84fad875cd6828d36359 100644 | ||
--- a/content/browser/utility_process_host.h | ||
+++ b/content/browser/utility_process_host.h | ||
@@ -118,6 +118,10 @@ class CONTENT_EXPORT UtilityProcessHost | ||
// Provides extra switches to append to the process's command line. | ||
void SetExtraCommandLineSwitches(std::vector<std::string> switches); | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+ void SetAdditionalFds(base::FileHandleMappingVector mapping); | ||
+#endif | ||
+ | ||
// Returns a control interface for the running child process. | ||
mojom::ChildProcess* GetChildProcess(); | ||
|
||
@@ -159,6 +163,12 @@ class CONTENT_EXPORT UtilityProcessHost | ||
// Extra command line switches to append. | ||
std::vector<std::string> extra_switches_; | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+ // Specifies file descriptors to propagate into the child process | ||
+ // based on the mapping. | ||
+ base::FileHandleMappingVector fds_to_remap_; | ||
+#endif | ||
+ | ||
// Indicates whether the process has been successfully launched yet, or if | ||
// launch failed. | ||
enum class LaunchState { | ||
diff --git a/content/public/browser/service_process_host.cc b/content/public/browser/service_process_host.cc | ||
index 75535e4d07051861a9f5e7ca6e18c017caf2ec8a..dba3e628d66a7970a6144b486e3c00904617e025 100644 | ||
--- a/content/public/browser/service_process_host.cc | ||
+++ b/content/public/browser/service_process_host.cc | ||
@@ -46,6 +46,14 @@ ServiceProcessHost::Options::WithExtraCommandLineSwitches( | ||
return *this; | ||
} | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+ServiceProcessHost::Options& ServiceProcessHost::Options::WithAdditionalFds( | ||
+ base::FileHandleMappingVector mapping) { | ||
+ fds_to_remap = std::move(mapping); | ||
+ return *this; | ||
+} | ||
+#endif | ||
+ | ||
ServiceProcessHost::Options& ServiceProcessHost::Options::WithProcessCallback( | ||
base::OnceCallback<void(const base::Process&)> callback) { | ||
process_callback = std::move(callback); | ||
diff --git a/content/public/browser/service_process_host.h b/content/public/browser/service_process_host.h | ||
index 3fd103b0d8486ed8fa5a6dd720b4de9aa189a178..72af3938499e1b01013a437d25b6298988bc9d44 100644 | ||
--- a/content/public/browser/service_process_host.h | ||
+++ b/content/public/browser/service_process_host.h | ||
@@ -13,6 +13,7 @@ | ||
#include "base/callback.h" | ||
#include "base/command_line.h" | ||
#include "base/observer_list_types.h" | ||
+#include "base/process/launch.h" | ||
#include "base/process/process_handle.h" | ||
#include "base/strings/string_piece.h" | ||
#include "build/chromecast_buildflags.h" | ||
@@ -89,6 +90,12 @@ class CONTENT_EXPORT ServiceProcessHost { | ||
// Specifies extra command line switches to append before launch. | ||
Options& WithExtraCommandLineSwitches(std::vector<std::string> switches); | ||
|
||
+#if BUILDFLAG(IS_POSIX) | ||
+ // Specifies file descriptors to propagate into the child process | ||
+ // based on the mapping. | ||
+ Options& WithAdditionalFds(base::FileHandleMappingVector mapping); | ||
+#endif | ||
+ | ||
// Specifies a callback to be invoked with service process once it's | ||
// launched. Will be on UI thread. | ||
Options& WithProcessCallback( | ||
@@ -102,6 +109,9 @@ class CONTENT_EXPORT ServiceProcessHost { | ||
std::u16string display_name; | ||
absl::optional<int> child_flags; | ||
std::vector<std::string> extra_switches; | ||
+#if BUILDFLAG(IS_POSIX) | ||
+ base::FileHandleMappingVector fds_to_remap; | ||
+#endif | ||
base::OnceCallback<void(const base::Process&)> process_callback; | ||
}; | ||
|
Oops, something went wrong.