mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Extracted common parts of the starting content process
This commit is contained in:
parent
25f93b699f
commit
609884cc5e
1 changed files with 49 additions and 20 deletions
|
@ -28,6 +28,8 @@ use script_traits::{ConstellationControlMsg, InitialScriptState, MozBrowserEvent
|
||||||
use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg, SWManagerMsg, SWManagerSenders};
|
use script_traits::{LayoutControlMsg, LayoutMsg, NewLayoutInfo, ScriptMsg, SWManagerMsg, SWManagerSenders};
|
||||||
use script_traits::{ScriptThreadFactory, TimerEventRequest, WindowSizeData};
|
use script_traits::{ScriptThreadFactory, TimerEventRequest, WindowSizeData};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::env;
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::io::Error as IOError;
|
use std::io::Error as IOError;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::mpsc::{Sender, channel};
|
use std::sync::mpsc::{Sender, channel};
|
||||||
|
@ -485,7 +487,18 @@ impl UnprivilegedPipelineContent {
|
||||||
use gaol::sandbox::{self, Sandbox, SandboxMethods};
|
use gaol::sandbox::{self, Sandbox, SandboxMethods};
|
||||||
use ipc_channel::ipc::IpcOneShotServer;
|
use ipc_channel::ipc::IpcOneShotServer;
|
||||||
use sandboxing::content_process_sandbox_profile;
|
use sandboxing::content_process_sandbox_profile;
|
||||||
use std::env;
|
|
||||||
|
impl CommandMethods for sandbox::Command {
|
||||||
|
fn arg<T>(&mut self, arg: T)
|
||||||
|
where T: AsRef<OsStr> {
|
||||||
|
self.arg(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn env<T, U>(&mut self, key: T, val: U)
|
||||||
|
where T: AsRef<OsStr>, U: AsRef<OsStr> {
|
||||||
|
self.env(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Note that this function can panic, due to process creation,
|
// Note that this function can panic, due to process creation,
|
||||||
// avoiding this panic would require a mechanism for dealing
|
// avoiding this panic would require a mechanism for dealing
|
||||||
|
@ -497,15 +510,7 @@ impl UnprivilegedPipelineContent {
|
||||||
// If there is a sandbox, use the `gaol` API to create the child process.
|
// If there is a sandbox, use the `gaol` API to create the child process.
|
||||||
let child_process = if opts::get().sandbox {
|
let child_process = if opts::get().sandbox {
|
||||||
let mut command = sandbox::Command::me().expect("Failed to get current sandbox.");
|
let mut command = sandbox::Command::me().expect("Failed to get current sandbox.");
|
||||||
command.arg("--content-process").arg(token);
|
self.setup_common(&mut command, token);
|
||||||
|
|
||||||
if let Ok(value) = env::var("RUST_BACKTRACE") {
|
|
||||||
command.env("RUST_BACKTRACE", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(value) = env::var("RUST_LOG") {
|
|
||||||
command.env("RUST_LOG", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
let profile = content_process_sandbox_profile();
|
let profile = content_process_sandbox_profile();
|
||||||
ChildProcess::Sandboxed(Sandbox::new(profile).start(&mut command)
|
ChildProcess::Sandboxed(Sandbox::new(profile).start(&mut command)
|
||||||
|
@ -514,16 +519,7 @@ impl UnprivilegedPipelineContent {
|
||||||
let path_to_self = env::current_exe()
|
let path_to_self = env::current_exe()
|
||||||
.expect("Failed to get current executor.");
|
.expect("Failed to get current executor.");
|
||||||
let mut child_process = process::Command::new(path_to_self);
|
let mut child_process = process::Command::new(path_to_self);
|
||||||
child_process.arg("--content-process");
|
self.setup_common(&mut child_process, token);
|
||||||
child_process.arg(token);
|
|
||||||
|
|
||||||
if let Ok(value) = env::var("RUST_BACKTRACE") {
|
|
||||||
child_process.env("RUST_BACKTRACE", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(value) = env::var("RUST_LOG") {
|
|
||||||
child_process.env("RUST_LOG", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
ChildProcess::Unsandboxed(child_process.spawn()
|
ChildProcess::Unsandboxed(child_process.spawn()
|
||||||
.expect("Failed to start unsandboxed child process!"))
|
.expect("Failed to start unsandboxed child process!"))
|
||||||
|
@ -541,6 +537,19 @@ impl UnprivilegedPipelineContent {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setup_common<C: CommandMethods>(&self, command: &mut C, token: String) {
|
||||||
|
C::arg(command, "--content-process");
|
||||||
|
C::arg(command, token);
|
||||||
|
|
||||||
|
if let Ok(value) = env::var("RUST_BACKTRACE") {
|
||||||
|
C::env(command, "RUST_BACKTRACE", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(value) = env::var("RUST_LOG") {
|
||||||
|
C::env(command, "RUST_LOG", value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn constellation_chan(&self) -> IpcSender<ScriptMsg> {
|
pub fn constellation_chan(&self) -> IpcSender<ScriptMsg> {
|
||||||
self.constellation_chan.clone()
|
self.constellation_chan.clone()
|
||||||
}
|
}
|
||||||
|
@ -560,3 +569,23 @@ impl UnprivilegedPipelineContent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait CommandMethods {
|
||||||
|
fn arg<T>(&mut self, arg: T)
|
||||||
|
where T: AsRef<OsStr>;
|
||||||
|
|
||||||
|
fn env<T, U>(&mut self, key: T, val: U)
|
||||||
|
where T: AsRef<OsStr>, U: AsRef<OsStr>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommandMethods for process::Command {
|
||||||
|
fn arg<T>(&mut self, arg: T)
|
||||||
|
where T: AsRef<OsStr> {
|
||||||
|
self.arg(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn env<T, U>(&mut self, key: T, val: U)
|
||||||
|
where T: AsRef<OsStr>, U: AsRef<OsStr> {
|
||||||
|
self.env(key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue