summaryrefslogtreecommitdiff
path: root/src/systemd/unit.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemd/unit.rs')
-rw-r--r--src/systemd/unit.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/systemd/unit.rs b/src/systemd/unit.rs
index 3be7fa5..22752cb 100644
--- a/src/systemd/unit.rs
+++ b/src/systemd/unit.rs
@@ -6,7 +6,9 @@ use std::io;
#[derive(Debug, PartialEq, Eq)]
pub struct Unit {
pub name: String,
- pub type_: String
+ pub type_: String,
+ pub active_state: String,
+ pub sub_state: String,
}
pub fn parse_key_value(line: &str) -> Option<(String, String)> {
@@ -28,11 +30,15 @@ fn make_unit(info: HashMap<String, String>) -> Option<Unit> {
fn from_id(id: &str) -> Option<String> {
id.rsplit('.').next().map(|t| t.to_owned())
};
- let id = info.get("Id").map(|id| id.clone());
+ fn cloned(s: &String) -> String { s.clone() }
+ let id = info.get("Id").map(cloned);
let type_ = id.as_ref().and_then(|id| from_id(&id));
+ let active_state = info.get("ActiveState").map(cloned);
+ let sub_state = info.get("SubState").map(cloned);
- if let (Some(id), Some(type_)) = (id, type_) {
- Some(Unit { name: id, type_: type_ })
+ if let (Some(id), Some(type_), Some(active_state), Some(sub_state)) =
+ (id, type_, active_state, sub_state) {
+ Some(Unit { name: id, type_: type_, active_state: active_state, sub_state: sub_state })
} else {
None
}
@@ -41,9 +47,14 @@ fn make_unit(info: HashMap<String, String>) -> Option<Unit> {
#[test]
fn test_make_unit() {
let s = |s: &str| -> String { s.to_owned() };
- let info = [(s("Id"), s("Test.service"))]
+ let info = [
+ (s("Id"), s("Test.service")),
+ (s("ActiveState"), s("active")),
+ (s("SubState"), s("running")),
+ ]
.iter().cloned().collect::<HashMap<String, String>>();
- assert_eq!(Some(Unit { name: s("Test.service"), type_: s("service") }), make_unit(info));
+ let actual = make_unit(info).unwrap();;
+ assert_eq!(s("Test.service"), actual.name);
let info = HashMap::new();
assert_eq!(None, make_unit(info));