Implement the wayland_socket config option for realms

This commit is contained in:
David McKinney 2021-01-15 09:01:52 -05:00 committed by Bruce Leidl
parent ef04bc1786
commit a77a7cc07b
3 changed files with 17 additions and 6 deletions

View File

@ -65,6 +65,9 @@ pub struct RealmConfig {
#[serde(rename="use-wayland")] #[serde(rename="use-wayland")]
pub use_wayland: Option<bool>, pub use_wayland: Option<bool>,
#[serde(rename="wayland-socket")]
pub wayland_socket: Option<String>,
#[serde(rename="use-kvm")] #[serde(rename="use-kvm")]
pub use_kvm: Option<bool>, pub use_kvm: Option<bool>,
@ -188,6 +191,7 @@ impl RealmConfig {
use_sound: Some(true), use_sound: Some(true),
use_x11: Some(true), use_x11: Some(true),
use_wayland: Some(true), use_wayland: Some(true),
wayland_socket: Some("wayland-0".to_string()),
use_kvm: Some(false), use_kvm: Some(false),
use_gpu: Some(false), use_gpu: Some(false),
use_gpu_card0: Some(false), use_gpu_card0: Some(false),
@ -217,6 +221,7 @@ impl RealmConfig {
use_sound: None, use_sound: None,
use_x11: None, use_x11: None,
use_wayland: None, use_wayland: None,
wayland_socket: None,
use_kvm: None, use_kvm: None,
use_gpu: None, use_gpu: None,
use_gpu_card0: None, use_gpu_card0: None,
@ -246,8 +251,6 @@ impl RealmConfig {
self.bool_value(|c| c.use_kvm) self.bool_value(|c| c.use_kvm)
} }
/// If `true` render node device /dev/dri/renderD128 will be added to realm. /// If `true` render node device /dev/dri/renderD128 will be added to realm.
/// ///
/// This enables hardware graphics acceleration in realm. /// This enables hardware graphics acceleration in realm.
@ -319,6 +322,12 @@ impl RealmConfig {
self.bool_value(|c| c.use_wayland) self.bool_value(|c| c.use_wayland)
} }
/// The name of the wayland socket to use if `self.wayland()` is `true`
/// defaults to wayland-0, will appear in the realm as wayland-0 regardless of value
pub fn wayland_socket(&self) -> &str {
self.str_value(|c| c.wayland_socket.as_ref()).unwrap_or("wayland-0")
}
/// If `true` the realm will have access to the network through the zone specified /// If `true` the realm will have access to the network through the zone specified
/// by `self.network_zone()` /// by `self.network_zone()`
pub fn network(&self) -> bool { pub fn network(&self) -> bool {

View File

@ -140,7 +140,9 @@ impl <'a> RealmLauncher <'a> {
} }
if config.wayland() { if config.wayland() {
writeln!(s, "BindReadOnly=/run/user/1000/wayland-0:/run/user/host/wayland-0")?; // This socket will always be mounted in the realm as wayland-0, regardless of the
// value of wayland_socket()
writeln!(s, "BindReadOnly=/run/user/1000/{}:/run/user/host/wayland-0", config.wayland_socket())?;
} }
for bind in config.extra_bindmounts() { for bind in config.extra_bindmounts() {
@ -206,7 +208,6 @@ impl <'a> RealmLauncher <'a> {
for dev in &self.devices { for dev in &self.devices {
writeln!(s, "DeviceAllow={}", dev).unwrap(); writeln!(s, "DeviceAllow={}", dev).unwrap();
} }
REALM_SERVICE_TEMPLATE.replace("$REALM_NAME", self.realm.name()) REALM_SERVICE_TEMPLATE.replace("$REALM_NAME", self.realm.name())
.replace("$ROOTFS", &rootfs) .replace("$ROOTFS", &rootfs)
.replace("$NETNS_ARG", &netns_arg) .replace("$NETNS_ARG", &netns_arg)
@ -226,4 +227,5 @@ impl From<fmt::Error> for crate::Error {
fn from(e: fmt::Error) -> Self { fn from(e: fmt::Error) -> Self {
format_err!("Error formatting string: {}", e).into() format_err!("Error formatting string: {}", e).into()
} }
} }

View File

@ -91,7 +91,7 @@ impl RealmManager {
pub fn launch_terminal(&self, realm: &Realm) -> Result<()> { pub fn launch_terminal(&self, realm: &Realm) -> Result<()> {
info!("opening terminal in realm '{}'", realm.name()); info!("opening terminal in realm '{}'", realm.name());
let title_arg = format!("Realm: {}", realm.name()); let title_arg = format!("Realm: {}", realm.name());
let args = &["/usr/bin/gnome-terminal".to_owned(), "--title".to_owned(), title_arg]; let args = &["/usr/bin/x-terminal-emulator".to_owned(), "--title".to_owned(), title_arg];
Systemd::machinectl_shell(realm, args, "user", true, true)?; Systemd::machinectl_shell(realm, args, "user", true, true)?;
Ok(()) Ok(())
} }