Implement deletion of SysV IPC message queues

As usual also the readme and the man page are updated.
This commit is contained in:
finga 2021-07-07 20:48:07 +02:00
parent 060b6ac88d
commit 0bff16f5b2

View file

@ -1,9 +1,9 @@
use libc::{ use libc::{
msgget, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID, IPC_SET, IPC_STAT, msgctl, msgget, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID,
MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT, IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT,
}; };
use nix::errno::{errno, Errno}; use nix::errno::{errno, Errno};
use std::{marker::PhantomData, num::ParseIntError}; use std::{marker::PhantomData, num::ParseIntError, ptr};
use thiserror::Error; use thiserror::Error;
#[derive(Debug, Error)] #[derive(Debug, Error)]
@ -54,6 +54,27 @@ pub enum ControlCommands {
MsgInfo = MSG_INFO, 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 struct SysvMq<T> {
pub id: i32, pub id: i32,
pub key: i32, pub key: i32,