Implement creation of SysV IPC message queues
This adds the `sysvmq` package which handles SysV IPC message queues. For consistency the parameter for `permissions` is renamed to `mode` also for POSIX message queues.
This commit is contained in:
parent
a468c5d7bb
commit
4d200bb5f3
11 changed files with 271 additions and 10 deletions
|
@ -2,6 +2,7 @@ use anyhow::Result;
|
|||
use clap::{crate_authors, crate_version, AppSettings, Clap};
|
||||
|
||||
mod posix;
|
||||
mod sysv;
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
enum Backend {
|
||||
|
@ -23,6 +24,7 @@ enum PosixCommand {
|
|||
|
||||
#[derive(Clap, Debug)]
|
||||
enum SysvCommand {
|
||||
Create(sysv::Create),
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
|
@ -65,6 +67,7 @@ fn main() -> Result<()> {
|
|||
PosixCommand::Recv(r) => r.run()?,
|
||||
},
|
||||
Backend::Sysv(s) => match s {
|
||||
SysvCommand::Create(c) => c.run()?,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::fs;
|
|||
pub struct Create {
|
||||
/// Permissions (octal) to create the queue with
|
||||
#[clap(short, long)]
|
||||
permissions: Option<String>,
|
||||
mode: Option<String>,
|
||||
/// Maximum number of messages in the queue
|
||||
#[clap(short, long)]
|
||||
capacity: Option<usize>,
|
||||
|
@ -39,7 +39,7 @@ impl Create {
|
|||
pub fn run(&self) -> Result<()> {
|
||||
let mq = &mut posixmq::OpenOptions::readonly();
|
||||
|
||||
if let Some(m) = &self.permissions {
|
||||
if let Some(m) = &self.mode {
|
||||
mq.mode(u32::from_str_radix(&m, 8)?);
|
||||
}
|
||||
|
||||
|
|
3
src/sysv.rs
Normal file
3
src/sysv.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod create;
|
||||
|
||||
pub use create::Create;
|
31
src/sysv/create.rs
Normal file
31
src/sysv/create.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Create a SysV message queue
|
||||
#[derive(Clap, Debug)]
|
||||
pub struct Create {
|
||||
/// Permissions (octal) to create the queue with (default: 0644)
|
||||
#[clap(short, long)]
|
||||
mode: Option<String>,
|
||||
/// Key of the new queue
|
||||
#[clap(value_name = "KEY")]
|
||||
key: i32,
|
||||
}
|
||||
|
||||
impl Create {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mut mq = SysvMq::<String>::new();
|
||||
|
||||
if let Some(m) = &self.mode {
|
||||
mq.mode(i32::from_str_radix(&m, 8)?);
|
||||
}
|
||||
|
||||
mq.create(self.key)?;
|
||||
|
||||
info!("SysV message queue created, key: {}, id: {}", mq.key, mq.id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue