Implement printing a list of SysV IPC mqs
What could be improved is when printing the information to use a better human readable format. As usual the readme and the man page are both updated.
This commit is contained in:
parent
f4796e7da6
commit
4c82d41f8e
5 changed files with 46 additions and 0 deletions
|
@ -67,6 +67,10 @@ queue. Following optional arguments are supported:
|
||||||
- `-m`, `--mode`: Permissions (octal) to create the queue
|
- `-m`, `--mode`: Permissions (octal) to create the queue
|
||||||
with. Default: 0644.
|
with. Default: 0644.
|
||||||
|
|
||||||
|
#### List all message queues
|
||||||
|
Use the `list` command to print a list of all message queues. No
|
||||||
|
further arguments are supported.
|
||||||
|
|
||||||
#### Delete a message queue
|
#### Delete a message queue
|
||||||
Use the `unlink` command to delete a message queue. This can either be
|
Use the `unlink` command to delete a message queue. This can either be
|
||||||
done by providing a `key` or an `id` of the queue:
|
done by providing a `key` or an `id` of the queue:
|
||||||
|
|
12
mqrs.1
12
mqrs.1
|
@ -241,6 +241,18 @@ Produce verbose output
|
||||||
.B \-m, \-\-mode \fI<mode>\fP
|
.B \-m, \-\-mode \fI<mode>\fP
|
||||||
Permissions (octal) to create the queue with (default: 0644)
|
Permissions (octal) to create the queue with (default: 0644)
|
||||||
.RE
|
.RE
|
||||||
|
.SS list [FLAGS]
|
||||||
|
Print a list of all existing SysV IPC message queues.
|
||||||
|
.TP 8
|
||||||
|
.SS FLAGS
|
||||||
|
.RS
|
||||||
|
.TP 8
|
||||||
|
.B \-h, \-\-help
|
||||||
|
Prints help information
|
||||||
|
.TP 8
|
||||||
|
.B \-v, \-\-verbose
|
||||||
|
Produce verbose output
|
||||||
|
.RE
|
||||||
.SS unlink [FLAGS] [OPTIONS]
|
.SS unlink [FLAGS] [OPTIONS]
|
||||||
Delete an existing SysV IPC message queue. It is mandatory to pass
|
Delete an existing SysV IPC message queue. It is mandatory to pass
|
||||||
exactly one OPTION.
|
exactly one OPTION.
|
||||||
|
|
|
@ -25,6 +25,7 @@ enum PosixCommand {
|
||||||
#[derive(Clap, Debug)]
|
#[derive(Clap, Debug)]
|
||||||
enum SysvCommand {
|
enum SysvCommand {
|
||||||
Create(sysv::Create),
|
Create(sysv::Create),
|
||||||
|
List(sysv::List),
|
||||||
Unlink(sysv::Unlink),
|
Unlink(sysv::Unlink),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ fn main() -> Result<()> {
|
||||||
},
|
},
|
||||||
Backend::Sysv(s) => match s {
|
Backend::Sysv(s) => match s {
|
||||||
SysvCommand::Create(c) => c.run()?,
|
SysvCommand::Create(c) => c.run()?,
|
||||||
|
SysvCommand::List(l) => l.run()?,
|
||||||
SysvCommand::Unlink(u) => u.run()?,
|
SysvCommand::Unlink(u) => u.run()?,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
mod create;
|
mod create;
|
||||||
|
mod list;
|
||||||
mod unlink;
|
mod unlink;
|
||||||
|
|
||||||
pub use create::Create;
|
pub use create::Create;
|
||||||
|
pub use list::List;
|
||||||
pub use unlink::Unlink;
|
pub use unlink::Unlink;
|
||||||
|
|
26
src/sysv/list.rs
Normal file
26
src/sysv/list.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use clap::Clap;
|
||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::{BufRead, BufReader},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Print a list of existing message queues
|
||||||
|
#[derive(Clap, Debug)]
|
||||||
|
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 field in line?.split_whitespace().collect::<Vec<&str>>() {
|
||||||
|
print!("{0: <10}", field);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue