Implement deletion of SysV IPC message queues
As usual also the readme and the man page are updated.
This commit is contained in:
parent
060b6ac88d
commit
0bff16f5b2
1 changed files with 24 additions and 3 deletions
27
src/lib.rs
27
src/lib.rs
|
@ -1,9 +1,9 @@
|
|||
use libc::{
|
||||
msgget, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID, IPC_SET, IPC_STAT,
|
||||
MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT,
|
||||
msgctl, msgget, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID,
|
||||
IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT,
|
||||
};
|
||||
use nix::errno::{errno, Errno};
|
||||
use std::{marker::PhantomData, num::ParseIntError};
|
||||
use std::{marker::PhantomData, num::ParseIntError, ptr};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
@ -54,6 +54,27 @@ pub enum ControlCommands {
|
|||
MsgInfo = MSG_INFO,
|
||||
}
|
||||
|
||||
pub fn unlink_id(id: i32) -> Result<(), SysvMqError> {
|
||||
let res = unsafe {
|
||||
msgctl(
|
||||
id,
|
||||
ControlCommands::Remove as i32,
|
||||
ptr::null::<msqid_ds>() as *mut msqid_ds,
|
||||
)
|
||||
};
|
||||
|
||||
match res {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlink_key(key: i32) -> Result<(), SysvMqError> {
|
||||
let id = unsafe { msgget(key, 0) };
|
||||
|
||||
unlink_id(id)
|
||||
}
|
||||
|
||||
pub struct SysvMq<T> {
|
||||
pub id: i32,
|
||||
pub key: i32,
|
||||
|
|
Loading…
Reference in a new issue