Add functions to print information about SysV mqs
Not needed yet but maybe useful..
This commit is contained in:
parent
9666e0788d
commit
ecd5ee5a36
1 changed files with 53 additions and 9 deletions
|
@ -1,21 +1,15 @@
|
||||||
use libc::{
|
use libc::{
|
||||||
msgctl, msgget, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE, IPC_RMID,
|
msgctl, msgget, msginfo, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE,
|
||||||
IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT,
|
IPC_RMID, 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, ptr};
|
use std::{marker::PhantomData, mem::MaybeUninit, ptr};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum SysvMqError {
|
pub enum SysvMqError {
|
||||||
#[error("SysV message queue: {0}")]
|
#[error("SysV message queue: {0}")]
|
||||||
ErrnoError(&'static str),
|
ErrnoError(&'static str),
|
||||||
#[error("No message queue found with key {0}")]
|
|
||||||
KeyNotFound(i32),
|
|
||||||
#[error("IO Error: {0}")]
|
|
||||||
IoError(#[from] std::io::Error),
|
|
||||||
#[error("Parse Error: {0}")]
|
|
||||||
ParserError(#[from] ParseIntError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// IPC bit flags
|
/// IPC bit flags
|
||||||
|
@ -78,6 +72,56 @@ pub fn id_from_key(key: i32) -> Result<i32, SysvMqError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ipc_info(id: i32) -> Result<(), SysvMqError> {
|
||||||
|
let mut msginfo = MaybeUninit::<msginfo>::uninit();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
msgctl(
|
||||||
|
id,
|
||||||
|
ControlCommands::IpcInfo as i32,
|
||||||
|
msginfo.as_mut_ptr() as *mut msqid_ds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let msginfo = unsafe { msginfo.assume_init() };
|
||||||
|
|
||||||
|
println!("info: {:?}", msginfo);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stat_info(id: i32) -> Result<(), SysvMqError> {
|
||||||
|
let mut msginfo = MaybeUninit::<msqid_ds>::uninit();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
msgctl(id, ControlCommands::Stat as i32, msginfo.as_mut_ptr());
|
||||||
|
}
|
||||||
|
|
||||||
|
let msginfo = unsafe { msginfo.assume_init() };
|
||||||
|
|
||||||
|
println!("info: {:?}", msginfo);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn msg_info(id: i32) -> Result<(), SysvMqError> {
|
||||||
|
let mut msginfo = MaybeUninit::<msginfo>::uninit();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
msgctl(
|
||||||
|
id,
|
||||||
|
ControlCommands::MsgInfo as i32,
|
||||||
|
msginfo.as_mut_ptr() as *mut msqid_ds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let msginfo = unsafe { msginfo.assume_init() };
|
||||||
|
|
||||||
|
println!("info: {:?}", msginfo);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SysvMq<T> {
|
pub struct SysvMq<T> {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub key: i32,
|
pub key: i32,
|
||||||
|
|
Loading…
Reference in a new issue