diff --git a/core/coms/service/src/mng.rs b/core/coms/service/src/mng.rs index 47c2cf00b0c12ada036b06f732c12dcb22c6854f..cf545f4b61851b4b65c7779870d39411208900d0 100644 --- a/core/coms/service/src/mng.rs +++ b/core/coms/service/src/mng.rs @@ -1115,7 +1115,7 @@ impl ServiceMng { } fn demand_pid_file(&self) -> Result<()> { - let pid_file_inotify = PathIntofy::new(self.config.pid_file().unwrap()); + let pid_file_inotify = PathInotify::new(self.config.pid_file().unwrap()); self.rd.attach_inotify(Rc::new(pid_file_inotify)); @@ -1913,12 +1913,12 @@ impl RunningData { *self.mng.borrow_mut() = Rc::downgrade(&mng); } - pub(self) fn attach_inotify(&self, path_inotify: Rc) { + pub(self) fn attach_inotify(&self, path_inotify: Rc) { path_inotify.attach(self.mng.borrow_mut().clone()); self.data.borrow_mut().attach_inotify(path_inotify); } - pub(self) fn path_inotify(&self) -> Rc { + pub(self) fn path_inotify(&self) -> Rc { self.data.borrow().path_inotify() } @@ -2071,7 +2071,7 @@ impl RunningData { struct Rtdata { errno: i32, notify_state: NotifyState, - path_inotify: Option>, + path_inotify: Option>, forbid_restart: bool, reset_restarts: bool, @@ -2118,11 +2118,11 @@ impl Rtdata { self.errno } - pub(self) fn attach_inotify(&mut self, path_inotify: Rc) { + pub(self) fn attach_inotify(&mut self, path_inotify: Rc) { self.path_inotify = Some(path_inotify) } - pub(self) fn path_inotify(&self) -> Rc { + pub(self) fn path_inotify(&self) -> Rc { self.path_inotify.as_ref().unwrap().clone() } @@ -2205,7 +2205,7 @@ enum PathType { Modified, } -struct PathIntofy { +struct PathInotify { path: PathBuf, p_type: PathType, inotify: RefCell, @@ -2213,7 +2213,7 @@ struct PathIntofy { mng: RefCell>, } -impl fmt::Display for PathIntofy { +impl fmt::Display for PathInotify { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -2225,9 +2225,9 @@ impl fmt::Display for PathIntofy { } } -impl PathIntofy { +impl PathInotify { fn new(path: PathBuf) -> Self { - PathIntofy { + PathInotify { path, p_type: PathType::Modified, inotify: RefCell::new(-1), @@ -2368,7 +2368,7 @@ impl PathIntofy { } } -impl Source for PathIntofy { +impl Source for PathInotify { fn fd(&self) -> RawFd { *self.inotify.borrow() } diff --git a/exts/devmaster/src/lib/rules/node.rs b/exts/devmaster/src/lib/rules/node.rs index de600f729daec7c334205f9d5c64351f8122eaf2..502767875ebb8f2f7221773b9ff9f35e3f8573e0 100644 --- a/exts/devmaster/src/lib/rules/node.rs +++ b/exts/devmaster/src/lib/rules/node.rs @@ -874,7 +874,11 @@ mod test { Ok(()) }) { - assert!(e.is_errno(nix::Error::EACCES) || e.is_errno(nix::Error::EBUSY)); + assert!( + e.is_errno(nix::Error::EACCES) + || e.is_errno(nix::Error::EBUSY) + || e.is_errno(nix::Error::EAGAIN) + ); } } diff --git a/libs/device/src/device.rs b/libs/device/src/device.rs index 945bf91b62484355eb515a28af32011444859aee..0104307c3701c8f061ce400a3b8dc7c362dfae65 100644 --- a/libs/device/src/device.rs +++ b/libs/device/src/device.rs @@ -3528,8 +3528,11 @@ mod tests { } if let Err(e) = LoopDev::inner_process("/tmp/test_update_tag", 1024 * 10, inner_test) { - println!("e:{:?}", e); - assert!(e.is_errno(nix::Error::EACCES) || e.is_errno(nix::Error::EBUSY)); + assert!( + e.is_errno(nix::Error::EACCES) + || e.is_errno(nix::Error::EBUSY) + || e.is_errno(nix::Error::EAGAIN) + ); } } diff --git a/libs/event/src/lib.rs b/libs/event/src/lib.rs index c0dd1e4623d0cbc1c8bda3794ba31ed48b805aeb..25e74f861f37f1ac47f6b84ccc23568278bb219a 100644 --- a/libs/event/src/lib.rs +++ b/libs/event/src/lib.rs @@ -572,7 +572,7 @@ mod tests { * Thus the assertion condition should be slightly relaxed. */ let count = *post_s.as_ref().count.borrow(); - assert!(count < 10); + assert!(count >= 1); e.del_source(s).unwrap(); e.del_source(timer_s).unwrap(); diff --git a/libs/hwdb/src/hwdb_util.rs b/libs/hwdb/src/hwdb_util.rs index a5c2eac0e23cd46cb38aa101bde12caae3f26c10..bf0d749ccf589818eeaf54be6db2f9538f27858f 100644 --- a/libs/hwdb/src/hwdb_util.rs +++ b/libs/hwdb/src/hwdb_util.rs @@ -732,10 +732,16 @@ impl HwdbUtil { } match hwdb_bin_dir { - Some(dir) => bin_dir += &dir, - None => bin_dir += "/etc/devmaster/", + Some(dir) => { + if bin_dir.is_empty() { + bin_dir = dir; + } else { + bin_dir = bin_dir + "/" + &dir; + } + } + None => bin_dir += "/etc/devmaster", } - let hwdb_bin = bin_dir.clone() + "hwdb.bin"; + let hwdb_bin = bin_dir.clone() + "/" + "hwdb.bin"; let mut conf_file_dirs: Vec = Vec::new(); if let Some(p) = path { @@ -878,25 +884,97 @@ fn node_lookup(node: Rc>, c: u8) -> Option bool { let mut found: bool = false; - let duration = Duration::from_secs(self.st.st_mtime as u64); + let duration = Duration::new(self.st.st_mtime as u64, self.st.st_mtime_nsec as u32); let st_time = UNIX_EPOCH + duration; let mut time = st_time; @@ -273,7 +273,7 @@ impl SdHwdb { } /// get value by modalias and key - pub fn sd_hwdb_get(&mut self, modalias: String, key: String) -> Result { + pub fn get(&mut self, modalias: String, key: String) -> Result { if let Err(err) = self.properties_prepare(modalias) { return Err(err); } @@ -350,7 +350,7 @@ impl SdHwdb { ); } - if c != search.as_bytes()[i + p] { + if i + p >= search.len() || c != search.as_bytes()[i + p] { return Ok(()); } p += 1; @@ -776,3 +776,33 @@ impl LineBuf { self.rem(1); } } + +#[cfg(test)] +mod tests { + use super::*; + use std::path::Path; + + #[test] + fn test_get() { + for hwdb_bin in HWDB_BIN_PATHS { + if Path::new(hwdb_bin).exists() { + let mut hwdb = SdHwdb::new().unwrap(); + let s = hwdb + .get( + "dmi:bvnLENOVO".to_string(), + "ID_SYSFS_ATTRIBUTE_MODEL".to_string(), + ) + .unwrap(); + assert_eq!(s, "product_version"); + assert_eq!( + hwdb.get( + "invalid_modalias".to_string(), + "ID_SYSFS_ATTRIBUTE_MODEL".to_string() + ), + Err(Errno::ENOENT) + ); + return; + } + } + } +}