cli: add command to restart the compositor in place
This commit is contained in:
parent
fd1e260877
commit
2edfb29f2b
8 changed files with 186 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ mod input;
|
||||||
mod log;
|
mod log;
|
||||||
mod quit;
|
mod quit;
|
||||||
mod randr;
|
mod randr;
|
||||||
|
mod reexec;
|
||||||
mod run_privileged;
|
mod run_privileged;
|
||||||
pub mod screenshot;
|
pub mod screenshot;
|
||||||
mod seat_test;
|
mod seat_test;
|
||||||
|
|
@ -19,7 +20,8 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
cli::{
|
cli::{
|
||||||
color_management::ColorManagementArgs, damage_tracking::DamageTrackingArgs,
|
color_management::ColorManagementArgs, damage_tracking::DamageTrackingArgs,
|
||||||
idle::IdleCmd, input::InputArgs, randr::RandrArgs, xwayland::XwaylandArgs,
|
idle::IdleCmd, input::InputArgs, randr::RandrArgs, reexec::ReexecArgs,
|
||||||
|
xwayland::XwaylandArgs,
|
||||||
},
|
},
|
||||||
compositor::start_compositor,
|
compositor::start_compositor,
|
||||||
format::{Format, ref_formats},
|
format::{Format, ref_formats},
|
||||||
|
|
@ -81,6 +83,9 @@ pub enum Cmd {
|
||||||
Xwayland(XwaylandArgs),
|
Xwayland(XwaylandArgs),
|
||||||
/// Inspect/modify the color-management settings.
|
/// Inspect/modify the color-management settings.
|
||||||
ColorManagement(ColorManagementArgs),
|
ColorManagement(ColorManagementArgs),
|
||||||
|
/// Replace the compositor by another process. (Only for development.)
|
||||||
|
#[clap(hide = true)]
|
||||||
|
Reexec(ReexecArgs),
|
||||||
#[cfg(feature = "it")]
|
#[cfg(feature = "it")]
|
||||||
RunTests,
|
RunTests,
|
||||||
}
|
}
|
||||||
|
|
@ -241,5 +246,6 @@ pub fn main() {
|
||||||
Cmd::ColorManagement(a) => color_management::main(cli.global, a),
|
Cmd::ColorManagement(a) => color_management::main(cli.global, a),
|
||||||
#[cfg(feature = "it")]
|
#[cfg(feature = "it")]
|
||||||
Cmd::RunTests => crate::it::run_tests(),
|
Cmd::RunTests => crate::it::run_tests(),
|
||||||
|
Cmd::Reexec(a) => reexec::main(cli.global, a),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
80
src/cli/reexec.rs
Normal file
80
src/cli/reexec.rs
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
|
cli::GlobalArgs,
|
||||||
|
tools::tool_client::{Handle, ToolClient, with_tool_client},
|
||||||
|
utils::errorfmt::ErrorFmt,
|
||||||
|
wire::{jay_compositor, jay_reexec},
|
||||||
|
},
|
||||||
|
clap::Args,
|
||||||
|
std::rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Args, Debug)]
|
||||||
|
pub struct ReexecArgs {
|
||||||
|
/// The path to the new executable.
|
||||||
|
///
|
||||||
|
/// If this is not given, uses the path of **this** executable instead.
|
||||||
|
path: Option<String>,
|
||||||
|
/// The arguments to pass to the new executable.
|
||||||
|
args: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(global: GlobalArgs, reexec_args: ReexecArgs) {
|
||||||
|
with_tool_client(global.log_level.into(), |tc| async move {
|
||||||
|
let rexec = Rc::new(Reexec { tc: tc.clone() });
|
||||||
|
rexec.run(reexec_args).await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Reexec {
|
||||||
|
tc: Rc<ToolClient>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Reexec {
|
||||||
|
async fn run(&self, args: ReexecArgs) {
|
||||||
|
let tc = &self.tc;
|
||||||
|
let comp = tc.jay_compositor().await;
|
||||||
|
let reexec = tc.id();
|
||||||
|
tc.send(jay_compositor::Reexec {
|
||||||
|
self_id: comp,
|
||||||
|
id: reexec,
|
||||||
|
});
|
||||||
|
if let Some(path) = &args.path {
|
||||||
|
for arg in &args.args {
|
||||||
|
tc.send(jay_reexec::Arg {
|
||||||
|
self_id: reexec,
|
||||||
|
arg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tc.send(jay_reexec::Exec {
|
||||||
|
self_id: reexec,
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let exe = match std::env::current_exe() {
|
||||||
|
Ok(e) => e,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Could not determine the executable path: {}", ErrorFmt(e));
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let Some(exe) = exe.to_str() else {
|
||||||
|
log::error!("Executable path is not a string: {:?}", exe);
|
||||||
|
std::process::exit(1);
|
||||||
|
};
|
||||||
|
tc.send(jay_reexec::Arg {
|
||||||
|
self_id: reexec,
|
||||||
|
arg: "run",
|
||||||
|
});
|
||||||
|
tc.send(jay_reexec::Exec {
|
||||||
|
self_id: reexec,
|
||||||
|
path: exe,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
jay_reexec::Failed::handle(tc, reexec, (), |_, msg| {
|
||||||
|
log::error!("Exec failed: {}", msg.msg);
|
||||||
|
std::process::exit(1);
|
||||||
|
});
|
||||||
|
tc.round_trip().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,7 @@ pub mod jay_log_file;
|
||||||
pub mod jay_output;
|
pub mod jay_output;
|
||||||
pub mod jay_pointer;
|
pub mod jay_pointer;
|
||||||
pub mod jay_randr;
|
pub mod jay_randr;
|
||||||
|
pub mod jay_reexec;
|
||||||
pub mod jay_render_ctx;
|
pub mod jay_render_ctx;
|
||||||
pub mod jay_screencast;
|
pub mod jay_screencast;
|
||||||
pub mod jay_screenshot;
|
pub mod jay_screenshot;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ use {
|
||||||
jay_output::JayOutput,
|
jay_output::JayOutput,
|
||||||
jay_pointer::JayPointer,
|
jay_pointer::JayPointer,
|
||||||
jay_randr::JayRandr,
|
jay_randr::JayRandr,
|
||||||
|
jay_reexec::JayReexec,
|
||||||
jay_render_ctx::JayRenderCtx,
|
jay_render_ctx::JayRenderCtx,
|
||||||
jay_screencast::JayScreencast,
|
jay_screencast::JayScreencast,
|
||||||
jay_screenshot::JayScreenshot,
|
jay_screenshot::JayScreenshot,
|
||||||
|
|
@ -73,7 +74,7 @@ impl Global for JayCompositorGlobal {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version(&self) -> u32 {
|
fn version(&self) -> u32 {
|
||||||
16
|
17
|
||||||
}
|
}
|
||||||
|
|
||||||
fn required_caps(&self) -> ClientCaps {
|
fn required_caps(&self) -> ClientCaps {
|
||||||
|
|
@ -456,6 +457,19 @@ impl JayCompositorRequestHandler for JayCompositor {
|
||||||
self.client.add_client_obj(&obj)?;
|
self.client.add_client_obj(&obj)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reexec(&self, req: Reexec, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||||
|
let obj = Rc::new(JayReexec {
|
||||||
|
id: req.id,
|
||||||
|
client: self.client.clone(),
|
||||||
|
tracker: Default::default(),
|
||||||
|
version: self.version,
|
||||||
|
args: Default::default(),
|
||||||
|
});
|
||||||
|
track!(self.client, obj);
|
||||||
|
self.client.add_client_obj(&obj)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object_base! {
|
object_base! {
|
||||||
|
|
|
||||||
67
src/ifs/jay_reexec.rs
Normal file
67
src/ifs/jay_reexec.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
|
client::{Client, ClientError},
|
||||||
|
leaks::Tracker,
|
||||||
|
object::{Object, Version},
|
||||||
|
utils::oserror::OsError,
|
||||||
|
wire::{JayReexecId, jay_reexec::*},
|
||||||
|
},
|
||||||
|
std::{cell::RefCell, rc::Rc},
|
||||||
|
thiserror::Error,
|
||||||
|
uapi::UstrPtr,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct JayReexec {
|
||||||
|
pub id: JayReexecId,
|
||||||
|
pub client: Rc<Client>,
|
||||||
|
pub tracker: Tracker<Self>,
|
||||||
|
pub version: Version,
|
||||||
|
pub args: RefCell<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JayReexec {
|
||||||
|
fn send_failed(&self, msg: &str) {
|
||||||
|
self.client.event(Failed {
|
||||||
|
self_id: self.id,
|
||||||
|
msg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JayReexecRequestHandler for JayReexec {
|
||||||
|
type Error = JayReexecError;
|
||||||
|
|
||||||
|
fn arg(&self, req: Arg<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||||
|
self.args.borrow_mut().push(req.arg.to_owned());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exec(&self, req: Exec<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||||
|
let args = self.args.borrow();
|
||||||
|
let mut args2 = UstrPtr::new();
|
||||||
|
args2.push(req.path);
|
||||||
|
for arg in &*args {
|
||||||
|
args2.push(&**arg);
|
||||||
|
}
|
||||||
|
if let Err(e) = uapi::execvp(req.path, &args2) {
|
||||||
|
self.send_failed(&OsError(e.0).to_string());
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object_base! {
|
||||||
|
self = JayReexec;
|
||||||
|
version = self.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Object for JayReexec {}
|
||||||
|
|
||||||
|
simple_add_obj!(JayReexec);
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum JayReexecError {
|
||||||
|
#[error(transparent)]
|
||||||
|
ClientError(Box<ClientError>),
|
||||||
|
}
|
||||||
|
efrom!(JayReexecError, ClientError);
|
||||||
|
|
@ -332,7 +332,7 @@ impl ToolClient {
|
||||||
self_id: s.registry,
|
self_id: s.registry,
|
||||||
name: s.jay_compositor.0,
|
name: s.jay_compositor.0,
|
||||||
interface: JayCompositor.name(),
|
interface: JayCompositor.name(),
|
||||||
version: s.jay_compositor.1.min(16),
|
version: s.jay_compositor.1.min(17),
|
||||||
id: id.into(),
|
id: id.into(),
|
||||||
});
|
});
|
||||||
self.jay_compositor.set(Some(id));
|
self.jay_compositor.set(Some(id));
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,10 @@ request get_color_management (since = 14) {
|
||||||
id: id(jay_color_management),
|
id: id(jay_color_management),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request reexec (since = 17) {
|
||||||
|
id: id(jay_reexec),
|
||||||
|
}
|
||||||
|
|
||||||
# events
|
# events
|
||||||
|
|
||||||
event client_id {
|
event client_id {
|
||||||
|
|
|
||||||
11
wire/jay_reexec.txt
Normal file
11
wire/jay_reexec.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
request arg {
|
||||||
|
arg: str,
|
||||||
|
}
|
||||||
|
|
||||||
|
request exec {
|
||||||
|
path: str,
|
||||||
|
}
|
||||||
|
|
||||||
|
event failed {
|
||||||
|
msg: str,
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue