Refactor sysvmq::unlink_* and check for error

Use `sysvmq::id_from_key(key)` to receive the id of a queue identified
with `key`. Here an error check is added as well. Adapt
`Sysv::Unlink::run()` to comply with that change.
This commit is contained in:
finga 2021-07-08 14:20:53 +02:00
parent 8d127d840e
commit f4796e7da6
2 changed files with 9 additions and 4 deletions

View file

@ -25,9 +25,11 @@ impl Unlink {
info!("Removed message queue with id: {}", id);
} else if let Some(key) = self.key {
sysvmq::unlink_key(key)?;
let id = sysvmq::id_from_key(key)?;
info!("Removed message queue key: {}", key);
sysvmq::unlink_id(id)?;
info!("Removed message queue key: {} (id: {})", key, id);
}
Ok(())

View file

@ -69,10 +69,13 @@ pub fn unlink_id(id: i32) -> Result<(), SysvMqError> {
}
}
pub fn unlink_key(key: i32) -> Result<(), SysvMqError> {
pub fn id_from_key(key: i32) -> Result<i32, SysvMqError> {
let id = unsafe { msgget(key, 0) };
unlink_id(id)
match id {
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
id => Ok(id),
}
}
pub struct SysvMq<T> {