diff --git a/src/process1/src/manager/unit.rs b/src/process1/src/manager/unit.rs index f980742b8ebcb981326e2439622890dc6b1fa997..e5b47cc61afe29b215ab44a6a9a294cc83e5b8ce 100644 --- a/src/process1/src/manager/unit.rs +++ b/src/process1/src/manager/unit.rs @@ -15,20 +15,11 @@ use std::hash::Hasher; use walkdir::WalkDir; use std::path::Path; -use utils:: {time_util, path_lookup, unit_load}; +use utils:: {time_util, path_lookup, unit_config_parser}; enum UnitType { UnitService = 0, - UnitMount, - UnitSwap, - UnitSocket, UnitTarget, - UnitDevice, - UnitAutomount, - UnitTimer, - UnitPath, - UnitSlice, - UnitScope, UnitTypeMax, UnitTypeInvalid, UnitTypeErrnoMax, @@ -81,46 +72,26 @@ enum UnitFileState { pub struct Unit { unit_type: UnitType, load_state: UnitLoadState, - unit_file_state: UnitFileState, id: String, instance: Option, name: String, depencies: Vec, desc: String, documnetation: String, - fragment_path: String, - source_path: String, - fragment_mtine: u128, - source_mtime: u128, - dropin_mtime: u64, + config_file_path: String, + config_file_mtime: u128, - units_by_type: Vec, - has_requires_mounts_for: Vec, load_queue: Vec, - dbus_queue: Vec, cleanup_queue: Vec, - gc_queue: Vec, - cgroup_queue: Vec, pids: HashSet, sigchldgen: u64, - gc_marker: u64, deseialize_job: i32, load_error: i32, stop_when_unneeded: bool, - refuse_manual_start: bool, - allow_isolate: bool, - ignore_on_isolate: bool, - ignore_on_snapshot: bool, - condition_result: bool, - assert_result: bool, transient: bool, in_load_queue: bool, - in_dubs_queue: bool, - in_cleanup_queue: bool, - in_gc_queue: bool, default_dependencies: bool, - perpetual: bool, - conf: Option, + conf: Option, manager: Option>, } @@ -162,38 +133,18 @@ impl Unit { depencies: Vec::::new(), desc: String::from(""), documnetation: null_str!(""), - fragment_path: null_str!(""), - source_path: null_str!(""), - fragment_mtine: 0, - source_mtime: 0, - dropin_mtime: 0, - units_by_type: Vec::::new(), - has_requires_mounts_for: Vec::::new(), + config_file_path: null_str!(""), + config_file_mtime: 0, load_queue: Vec::::new(), - dbus_queue: Vec::::new(), cleanup_queue: Vec::::new(), - gc_queue: Vec::::new(), - cgroup_queue: Vec::::new(), + deseialize_job:0, pids: HashSet::::new(), sigchldgen: 0, - gc_marker: 0, - deseialize_job: 0, load_error: 0, stop_when_unneeded: false, - refuse_manual_start: false, - allow_isolate: false, - ignore_on_isolate: false, - ignore_on_snapshot: false, - condition_result: false, - assert_result: false, transient: false, in_load_queue: false, - in_dubs_queue: false, - in_cleanup_queue: false, - in_gc_queue: false, default_dependencies: true, - perpetual: false, - unit_file_state: UnitFileState::UnitFileStateInvalid, manager: None, conf: None, } @@ -221,24 +172,6 @@ impl Unit { if !self.unit_load_dropin() { return false; } - - if !self.source_path.is_empty() { - match fs::metadata(&self.source_path) { - Ok(metadata) => match metadata.modified() { - Ok(time) => { - self.source_mtime = time_util::timespec_load(time); - }, - _ => { - self.source_mtime = 0; - }, - } - - _ => { - self.source_mtime = 0; - } - } - } - return true; } @@ -271,13 +204,13 @@ impl Unit { } } } - - if self.fragment_path != unit_path { - self.fragment_path = unit_path; + + if self.config_file_path!= unit_path { + self.config_file_path = unit_path; } - if !self.fragment_path.is_empty() { - let file = File::open(&self.fragment_path); + if !self.config_file_path.is_empty() { + let file = File::open(&self.config_file_path); let time: SystemTime; match file { @@ -286,26 +219,23 @@ impl Unit { match f.metadata(){ Err(e) => return false, Ok(m) => - if (m.is_file() && m.len() <=0) || m.file_type().is_char_device() { - self.load_state = UnitLoadState::UNIT_MASKED; - if self.perpetual { - self.load_state = UnitLoadState::UNIT_LOADED; - } - self.fragment_mtine = 0; + if (m.is_file() && m.len() <=0) || m.file_type().is_char_device() { + self.load_state = UnitLoadState::UNIT_LOADED; + self.config_file_mtime = 0; } else { self.load_state = UnitLoadState::UNIT_LOADED; - // self.fragment_mtine = time_util::timespec_load(time); - match unit_load::unit_file_load(self.fragment_path.to_string()) { - Ok(conf) => {self.conf = Some(conf);}, + match unit_config_parser::unit_file_load(self.config_file_path.to_string()) { + Ok(conf) => self.conf = Some(conf), Err(e) => { - return false; - }, + return false; + }, } } }, } - println!("fragmeng_mtime is: {}", self.fragment_mtine); + println!("config file _mtime is: {}", self.config_file_mtime); + } return true; @@ -324,9 +254,9 @@ impl <'l> Default for Unit<'l> { depencies: Vec::::new(), desc: String::from(""), documnetation: null_str!(""), - fragment_path: null_str!(""), + config_file_path: null_str!(""), source_path: null_str!(""), - fragment_mtine: 0, + config_file_mtime: 0, source_mtime: 0, dropin_mtime: 0, units_by_type: Vec::::new(), @@ -393,16 +323,12 @@ fn unit_new(manager: RefCell, unit_type: UnitType) -> Box { return Box::new(service::ServiceUnit::new(unit)) }, - UnitType::UnitSocket => { + UnitType::UnitTarget => { return Box::new(service::ServiceUnit::new(unit)) - } - UnitType::UnitTarget => Box::new(service::ServiceUnit::new(unit)), - UnitType::UnitDevice => Box::new(service::ServiceUnit::new(unit)), - UnitType::UnitDevice => Box::new(service::ServiceUnit::new(unit)), - UnitType::UnitTimer => Box::new(service::ServiceUnit::new(unit)), - (_) => Box::new(service::ServiceUnit::new(unit)), - //TODO - + }, + _ => { + return Box::new(service::ServiceUnit::new(unit)) + }, /* UnitPath, UnitSlice, diff --git a/src/utils/src/lib.rs b/src/utils/src/lib.rs index 1e003181e71f81c57decf8614e17a6bb463e5a28..fa634cd840404740bd456d8f8bf755168180fd1c 100644 --- a/src/utils/src/lib.rs +++ b/src/utils/src/lib.rs @@ -4,4 +4,4 @@ extern crate serde_derive; pub mod macros; pub mod time_util; pub mod path_lookup; -pub mod unit_load; +pub mod unit_config_parser; diff --git a/src/utils/src/path_lookup.rs b/src/utils/src/path_lookup.rs index fc30c3dcb490d847a95c0fa0b02cb32da1ed6f85..8eb2087e6e612cf91cbc6589d94b60af6aa5b722 100644 --- a/src/utils/src/path_lookup.rs +++ b/src/utils/src/path_lookup.rs @@ -1,4 +1,3 @@ -use std::cell::RefCell; const ETC_SYSTEM_PATH: &'static str = "/etc/process1/system"; const LIB_SYSTEM_PATH: &'static str = "/usr/lib/process1/system"; diff --git a/src/utils/src/unit_load.rs b/src/utils/src/unit_config_parser.rs similarity index 97% rename from src/utils/src/unit_load.rs rename to src/utils/src/unit_config_parser.rs index 59069f156015387e23e227a17418d7eb32957131..f982646033a99fdae8d597f9d245b3178a9bea72 100644 --- a/src/utils/src/unit_load.rs +++ b/src/utils/src/unit_config_parser.rs @@ -68,9 +68,9 @@ struct ConfInstall { #[derive(Deserialize)] #[derive(Debug)] pub struct Conf { - Unit: Option, - Service: Option, - Install: Option, + unit: Option, + service: Option, + install: Option, } pub fn unit_file_load(file_path: String) -> Result {