implement RealmFromCitadelPid in realmsd
This commit is contained in:
parent
1136cee2f7
commit
c79ff22a98
36
Cargo.lock
generated
36
Cargo.lock
generated
@ -382,6 +382,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc32fast"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@ -614,6 +623,16 @@ dependencies = [
|
|||||||
"rustc_version",
|
"rustc_version",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.0.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-channel"
|
name = "futures-channel"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
@ -1098,6 +1117,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"nix 0.17.0",
|
"nix 0.17.0",
|
||||||
"posix-acl",
|
"posix-acl",
|
||||||
|
"procfs",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"sodiumoxide",
|
"sodiumoxide",
|
||||||
@ -1477,6 +1497,21 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "procfs"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0941606b9934e2d98a3677759a971756eb821f75764d0e0d26946d08e74d9104"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"byteorder",
|
||||||
|
"chrono",
|
||||||
|
"flate2",
|
||||||
|
"hex",
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pwhash"
|
name = "pwhash"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@ -1599,6 +1634,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"libcitadel",
|
"libcitadel",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_repr",
|
||||||
"zbus",
|
"zbus",
|
||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
@ -18,6 +18,7 @@ bincode = "1.2"
|
|||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
dbus = "0.6"
|
dbus = "0.6"
|
||||||
posix-acl = "1.0.0"
|
posix-acl = "1.0.0"
|
||||||
|
procfs = "0.12.0"
|
||||||
|
|
||||||
[dependencies.inotify]
|
[dependencies.inotify]
|
||||||
version = "0.8"
|
version = "0.8"
|
||||||
|
@ -12,7 +12,7 @@ pub struct RealmItem {
|
|||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
realmfs: String,
|
realmfs: String,
|
||||||
namespace: String,
|
namespace: u64,
|
||||||
status: u8,
|
status: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,4 +9,5 @@ libcitadel = { path = "../libcitadel" }
|
|||||||
zbus = "=2.0.0-beta.5"
|
zbus = "=2.0.0-beta.5"
|
||||||
zvariant = "2.7.0"
|
zvariant = "2.7.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_repr = "0.1.8"
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_started(&self, realm: &Realm) -> zbus::Result<()> {
|
fn on_started(&self, realm: &Realm) -> zbus::Result<()> {
|
||||||
let namespace = realm.pid_namespace().unwrap_or(String::new());
|
let pid_ns = realm.pid_ns().unwrap_or(0);
|
||||||
let status = realm_status(realm);
|
let status = realm_status(realm);
|
||||||
self.with_server(|server| server.realm_started(realm.name(), namespace.as_str(), status))
|
self.with_server(|server| server.realm_started(realm.name(), pid_ns, status))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_stopped(&self, realm: &Realm) -> zbus::Result<()> {
|
fn on_stopped(&self, realm: &Realm) -> zbus::Result<()> {
|
||||||
|
@ -1,15 +1,41 @@
|
|||||||
use libcitadel::{RealmManager, Realm, OverlayType, Result};
|
use libcitadel::{RealmManager, Realm, OverlayType, Result, PidLookupResult};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use zbus::{dbus_interface, ObjectServer,Connection};
|
use zbus::{dbus_interface, ObjectServer,Connection};
|
||||||
use zvariant::derive::Type;
|
use zvariant::derive::Type;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use serde::{Serialize,Deserialize};
|
use serde::{Serialize,Deserialize};
|
||||||
|
use serde_repr::Serialize_repr;
|
||||||
use crate::events::EventHandler;
|
use crate::events::EventHandler;
|
||||||
use libcitadel::terminal::Base16Scheme;
|
use libcitadel::terminal::Base16Scheme;
|
||||||
|
|
||||||
pub const REALMS_SERVER_OBJECT_PATH: &str = "/com/subgraph/realms";
|
pub const REALMS_SERVER_OBJECT_PATH: &str = "/com/subgraph/realms";
|
||||||
|
|
||||||
|
#[derive(Serialize_repr, Type, Debug, PartialEq)]
|
||||||
|
#[repr(u32)]
|
||||||
|
pub enum PidLookupResultCode {
|
||||||
|
Unknown = 1,
|
||||||
|
Realm = 2,
|
||||||
|
Citadel = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Type, Serialize)]
|
||||||
|
pub struct RealmFromCitadelPid {
|
||||||
|
code: PidLookupResultCode,
|
||||||
|
realm: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PidLookupResult> for RealmFromCitadelPid {
|
||||||
|
fn from(result: PidLookupResult) -> Self {
|
||||||
|
match result {
|
||||||
|
PidLookupResult::Unknown => RealmFromCitadelPid { code: PidLookupResultCode::Unknown, realm: String::new() },
|
||||||
|
PidLookupResult::Realm(realm) => RealmFromCitadelPid { code: PidLookupResultCode::Realm, realm: realm.name().to_string() },
|
||||||
|
PidLookupResult::Citadel => RealmFromCitadelPid { code: PidLookupResultCode::Citadel, realm: String::new() },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RealmsManagerServer {
|
pub struct RealmsManagerServer {
|
||||||
manager: Arc<RealmManager>,
|
manager: Arc<RealmManager>,
|
||||||
@ -223,11 +249,8 @@ impl RealmsManagerServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn realm_from_citadel_pid(&self, pid: u32) -> String {
|
fn realm_from_citadel_pid(&self, pid: u32) -> RealmFromCitadelPid {
|
||||||
match self.manager.realm_by_pid(pid) {
|
self.manager.realm_by_pid(pid).into()
|
||||||
Some(r) => r.name().to_string(),
|
|
||||||
None => String::new(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn realm_config(&self, name: &str) -> RealmConfig {
|
fn realm_config(&self, name: &str) -> RealmConfig {
|
||||||
@ -277,7 +300,7 @@ impl RealmsManagerServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[dbus_interface(signal)]
|
#[dbus_interface(signal)]
|
||||||
pub fn realm_started(&self, realm: &str, namespace: &str, status: u8) -> zbus::Result<()> { Ok(()) }
|
pub fn realm_started(&self, realm: &str, pid_ns: u64, status: u8) -> zbus::Result<()> { Ok(()) }
|
||||||
|
|
||||||
#[dbus_interface(signal)]
|
#[dbus_interface(signal)]
|
||||||
pub fn realm_stopped(&self, realm: &str, status: u8) -> zbus::Result<()> { Ok(()) }
|
pub fn realm_stopped(&self, realm: &str, status: u8) -> zbus::Result<()> { Ok(()) }
|
||||||
@ -319,7 +342,7 @@ struct RealmItem {
|
|||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
realmfs: String,
|
realmfs: String,
|
||||||
namespace: String,
|
pid_ns: u64,
|
||||||
status: u8,
|
status: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,9 +351,9 @@ impl RealmItem {
|
|||||||
let name = realm.name().to_string();
|
let name = realm.name().to_string();
|
||||||
let description = realm.notes().unwrap_or(String::new());
|
let description = realm.notes().unwrap_or(String::new());
|
||||||
let realmfs = realm.config().realmfs().to_string();
|
let realmfs = realm.config().realmfs().to_string();
|
||||||
let namespace = realm.pid_namespace().unwrap_or(String::new());
|
let pid_ns = realm.pid_ns().unwrap_or_default();
|
||||||
let status = realm_status(realm);
|
let status = realm_status(realm);
|
||||||
RealmItem { name, description, realmfs, namespace, status }
|
RealmItem { name, description, realmfs, pid_ns, status }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user