Implement info
command for SysV IPC mqs
The `list` command was refactored a little bit as well and the man page and readme were updated.
This commit is contained in:
parent
4c82d41f8e
commit
9666e0788d
7 changed files with 113 additions and 16 deletions
|
@ -67,6 +67,12 @@ queue. Following optional arguments are supported:
|
|||
- `-m`, `--mode`: Permissions (octal) to create the queue
|
||||
with. Default: 0644.
|
||||
|
||||
#### Print information about a message queue
|
||||
Use the `info` command to print further information about a message
|
||||
queue. Exactly of the following arguments is mandatory:
|
||||
- `-i`, `--id id`: Id of the queue
|
||||
- `-k`, `--key key`: Key of the queue
|
||||
|
||||
#### List all message queues
|
||||
Use the `list` command to print a list of all message queues. No
|
||||
further arguments are supported.
|
||||
|
|
58
mqrs.1
58
mqrs.1
|
@ -41,7 +41,7 @@ The POSIX backend supports six commands:
|
|||
and
|
||||
.B recv
|
||||
.
|
||||
.SS create [FLAGS] [OPTIONS] \fI<QUEUE>\fP
|
||||
.SS posix create [FLAGS] [OPTIONS] \fI<QUEUE>\fP
|
||||
Create a new POSIX message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -72,7 +72,7 @@ Message size in bytes
|
|||
.B \-m, \-\-mode \fI<mode>\fP
|
||||
Permissions (octal) to create the queue with
|
||||
.RE
|
||||
.SS help [SUBCOMMAND]
|
||||
.SS posix help [SUBCOMMAND]
|
||||
Prints this message or the help of the given subcommand.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -81,7 +81,7 @@ Prints this message or the help of the given subcommand.
|
|||
.B \fI<SUBCOMMAND>\fP
|
||||
Show help for \fISUBCOMMAND\fP
|
||||
.RE
|
||||
.SS info [FLAGS] \fI<QUEUE>\fP
|
||||
.SS posix info [FLAGS] \fI<QUEUE>\fP
|
||||
Print further information about an existing message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -100,7 +100,7 @@ Prints help information
|
|||
.B \-v, \-\-verbose
|
||||
Produce verbose output
|
||||
.RE
|
||||
.SS list [FLAGS]
|
||||
.SS posix list [FLAGS]
|
||||
Print a list of all existing POSIX message queues.
|
||||
.TP 8
|
||||
.SS FLAGS
|
||||
|
@ -115,7 +115,7 @@ Produce verbose output
|
|||
.B \-a, \-\-all
|
||||
Print all available information
|
||||
.RE
|
||||
.SS recv [FLAGS] [OPTIONS] \fI<QUEUE>\fP
|
||||
.SS posix recv [FLAGS] [OPTIONS] \fI<QUEUE>\fP
|
||||
Receive and print one or more messages message from a message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -153,7 +153,7 @@ Deadline until messages are received (format: "%Y-%m-%d %H:%M:%S")
|
|||
.B \-o, \-\-timeout \fI<timeout>\fP
|
||||
Timeout as for example in "5h 23min 42ms"
|
||||
.RE
|
||||
.SS send [FLAGS] [OPTIONS] \fI<QUEUE>\fP \fI<MESSAGE>\fP
|
||||
.SS posix send [FLAGS] [OPTIONS] \fI<QUEUE>\fP \fI<MESSAGE>\fP
|
||||
Send a message to a message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -191,7 +191,7 @@ Set a different priority than default, priority >= 0 [default: 0]
|
|||
.B \-o, \-\-timeout \fI<timeout>\fP
|
||||
Timeout as for example in "5h 23min 42ms"
|
||||
.RE
|
||||
.SS unlink [FLAGS] \fI<QUEUE>\fP
|
||||
.SS posix unlink [FLAGS] \fI<QUEUE>\fP
|
||||
Delete an existing POSIX message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -211,12 +211,16 @@ Prints help information
|
|||
Produce verbose output
|
||||
.RE
|
||||
.SH SYSV IPC MESSAGE QUEUE SUBCOMMANDS
|
||||
The SysV IPC backend supports two commands:
|
||||
The SysV IPC backend supports four commands:
|
||||
.B create\
|
||||
,
|
||||
.B info\
|
||||
,
|
||||
.B list
|
||||
and
|
||||
.B unlink\
|
||||
.
|
||||
.SS create [FLAGS] [OPTIONS] \fI<KEY>\fP
|
||||
.SS sysv create [FLAGS] [OPTIONS] \fI<KEY>\fP
|
||||
Create a new SysV IPC message queue.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
|
@ -241,7 +245,39 @@ Produce verbose output
|
|||
.B \-m, \-\-mode \fI<mode>\fP
|
||||
Permissions (octal) to create the queue with (default: 0644)
|
||||
.RE
|
||||
.SS list [FLAGS]
|
||||
.SS sysv help [SUBCOMMAND]
|
||||
Prints this message or the help of the given subcommand.
|
||||
.TP 8
|
||||
.SS ARGS
|
||||
.RS
|
||||
.TP 8
|
||||
.B \fI<SUBCOMMAND>\fP
|
||||
Show help for \fISUBCOMMAND\fP
|
||||
.RE
|
||||
.SS sysv info [FLAGS] [OPTIONS]
|
||||
Print further information about an existing message queue. Exactly of
|
||||
the OPTION arguments is mandatory.
|
||||
.TP 8
|
||||
.SS FLAGS
|
||||
.RS
|
||||
.TP 8
|
||||
.B \-h, \-\-help
|
||||
Prints help information
|
||||
.TP 8
|
||||
.B \-v, \-\-verbose
|
||||
Produce verbose output
|
||||
.RE
|
||||
.TP 8
|
||||
.SS OPTIONS
|
||||
.RS
|
||||
.TP 8
|
||||
.B \-i, \-\-id \fI<id>\fP
|
||||
Id of the queue
|
||||
.TP 8
|
||||
.B \-k, \-\-key \fI<key>\fP
|
||||
Key of the queue
|
||||
.RE
|
||||
.SS sysv list [FLAGS]
|
||||
Print a list of all existing SysV IPC message queues.
|
||||
.TP 8
|
||||
.SS FLAGS
|
||||
|
@ -253,7 +289,7 @@ Prints help information
|
|||
.B \-v, \-\-verbose
|
||||
Produce verbose output
|
||||
.RE
|
||||
.SS unlink [FLAGS] [OPTIONS]
|
||||
.SS sysv unlink [FLAGS] [OPTIONS]
|
||||
Delete an existing SysV IPC message queue. It is mandatory to pass
|
||||
exactly one OPTION.
|
||||
.TP 8
|
||||
|
|
|
@ -25,6 +25,7 @@ enum PosixCommand {
|
|||
#[derive(Clap, Debug)]
|
||||
enum SysvCommand {
|
||||
Create(sysv::Create),
|
||||
Info(sysv::Info),
|
||||
List(sysv::List),
|
||||
Unlink(sysv::Unlink),
|
||||
}
|
||||
|
@ -70,6 +71,7 @@ fn main() -> Result<()> {
|
|||
},
|
||||
Backend::Sysv(s) => match s {
|
||||
SysvCommand::Create(c) => c.run()?,
|
||||
SysvCommand::Info(i) => i.run()?,
|
||||
SysvCommand::List(l) => l.run()?,
|
||||
SysvCommand::Unlink(u) => u.run()?,
|
||||
},
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
mod create;
|
||||
mod info;
|
||||
mod list;
|
||||
mod unlink;
|
||||
|
||||
pub use create::Create;
|
||||
pub use info::Info;
|
||||
pub use list::List;
|
||||
pub use unlink::Unlink;
|
||||
|
|
53
src/sysv/info.rs
Normal file
53
src/sysv/info.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
};
|
||||
|
||||
/// Print information about an existing message queue
|
||||
#[derive(Clap, Debug)]
|
||||
pub struct Info {
|
||||
/// Id of the queue
|
||||
#[clap(short, long, required_unless_present_any = &["key"], conflicts_with = "key")]
|
||||
id: Option<i32>,
|
||||
/// Key of the queue
|
||||
#[clap(short, long, required_unless_present_any = &["id"], conflicts_with = "id")]
|
||||
key: Option<i32>,
|
||||
}
|
||||
|
||||
fn print_line(line: &str) {
|
||||
for field in line.split_whitespace().collect::<Vec<&str>>() {
|
||||
print!("{0: <10}", field);
|
||||
}
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
impl Info {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mut lines = BufReader::new(File::open("/proc/sysvipc/msg")?).lines();
|
||||
|
||||
print_line(&lines.nth(0).unwrap_or(Ok(String::new()))?);
|
||||
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
|
||||
if let Some(id) = self.id {
|
||||
if id == line.split_whitespace().collect::<Vec<&str>>()[1].parse::<i32>()? {
|
||||
print_line(&line);
|
||||
|
||||
break;
|
||||
}
|
||||
} else if let Some(key) = self.key {
|
||||
if key == line.split_whitespace().collect::<Vec<&str>>()[0].parse::<i32>()? {
|
||||
print_line(&line);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -11,9 +11,7 @@ pub struct List {}
|
|||
|
||||
impl List {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let file = BufReader::new(File::open("/proc/sysvipc/msg")?);
|
||||
|
||||
for line in file.lines() {
|
||||
for line in BufReader::new(File::open("/proc/sysvipc/msg")?).lines() {
|
||||
for field in line?.split_whitespace().collect::<Vec<&str>>() {
|
||||
print!("{0: <10}", field);
|
||||
}
|
||||
|
|
|
@ -7,14 +7,14 @@ use log::info;
|
|||
pub struct Unlink {
|
||||
/// Id of the queue
|
||||
#[clap(
|
||||
long,
|
||||
short,
|
||||
long,
|
||||
required_unless_present_any = &["key"],
|
||||
conflicts_with = "key"
|
||||
)]
|
||||
id: Option<i32>,
|
||||
/// Key of the queue
|
||||
#[clap(long, short, required_unless_present_any = &["id"], conflicts_with = "id")]
|
||||
#[clap(short, long, required_unless_present_any = &["id"], conflicts_with = "id")]
|
||||
key: Option<i32>,
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue