Compare commits
2 commits
d5ef64171a
...
8f93d2d6c8
Author | SHA1 | Date | |
---|---|---|---|
8f93d2d6c8 | |||
1aab989000 |
13 changed files with 70 additions and 64 deletions
52
Cargo.lock
generated
52
Cargo.lock
generated
|
@ -13,9 +13,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.44"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
|
||||
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
|
@ -42,9 +42,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.71"
|
||||
version = "1.0.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
@ -67,9 +67,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.0.0-beta.4"
|
||||
version = "3.0.0-beta.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406"
|
||||
checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
|
@ -80,14 +80,14 @@ dependencies = [
|
|||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"vec_map",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.0.0-beta.4"
|
||||
version = "3.0.0-beta.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac"
|
||||
checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
|
@ -157,9 +157,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.103"
|
||||
version = "0.2.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
|
@ -233,9 +233,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "3.1.0"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d"
|
||||
checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "posixmq"
|
||||
|
@ -272,9 +275,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.29"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
|
||||
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
@ -313,9 +316,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.80"
|
||||
version = "1.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
|
||||
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -380,6 +383,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
|
@ -398,12 +410,6 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
name = "mqrs"
|
||||
version = "0.1.1"
|
||||
authors = ["finga <mqrs@onders.org>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
repository = "https://git.onders.org/finga/mqrs"
|
||||
license = "GPL-3.0-or-later"
|
||||
readme = "README.md"
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,10 +1,10 @@
|
|||
use anyhow::Result;
|
||||
use clap::{crate_authors, crate_version, AppSettings, Clap};
|
||||
use clap::{crate_authors, crate_version, AppSettings, Parser};
|
||||
|
||||
mod posix;
|
||||
mod sysv;
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
enum Backend {
|
||||
/// Handle POSIX message queues
|
||||
#[clap(subcommand)]
|
||||
|
@ -14,7 +14,7 @@ enum Backend {
|
|||
Sysv(SysvCommand),
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
enum PosixCommand {
|
||||
Create(posix::Create),
|
||||
Info(posix::Info),
|
||||
|
@ -24,7 +24,7 @@ enum PosixCommand {
|
|||
Recv(posix::Recv),
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
enum SysvCommand {
|
||||
Create(sysv::Create),
|
||||
Info(sysv::Info),
|
||||
|
@ -32,7 +32,7 @@ enum SysvCommand {
|
|||
Unlink(sysv::Unlink),
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(
|
||||
version = crate_version!(),
|
||||
author = crate_authors!(", "),
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use log::{info, log_enabled, Level::Info};
|
||||
use posixmq::PosixMq;
|
||||
use std::fs;
|
||||
|
||||
/// Create a POSIX message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Create {
|
||||
/// Permissions (octal) to create the queue with
|
||||
#[clap(short, long)]
|
||||
|
@ -40,7 +40,7 @@ impl Create {
|
|||
let mq = &mut posixmq::OpenOptions::readonly();
|
||||
|
||||
if let Some(m) = &self.mode {
|
||||
mq.mode(u32::from_str_radix(&m, 8)?);
|
||||
mq.mode(u32::from_str_radix(m, 8)?);
|
||||
}
|
||||
|
||||
mq.max_msg_len(self.msgsize.unwrap_or_else(msgsize_default))
|
||||
|
@ -53,10 +53,10 @@ impl Create {
|
|||
let attributes = mq.attributes()?;
|
||||
|
||||
info!("Created message queue: {} with attributes msgsize: {}, capacity: {}, current_messages: {}",
|
||||
&self.queue,
|
||||
&attributes.max_msg_len,
|
||||
&attributes.capacity,
|
||||
&attributes.current_messages);
|
||||
self.queue,
|
||||
attributes.max_msg_len,
|
||||
attributes.capacity,
|
||||
attributes.current_messages);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use posixmq::PosixMq;
|
||||
|
||||
/// Print information about an existing message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Info {
|
||||
/// Name of the queue
|
||||
#[clap(value_name = "QUEUE")]
|
||||
|
@ -16,7 +16,7 @@ impl Info {
|
|||
|
||||
println!(
|
||||
"Message queue: {}, msg_max: {}, msgsize_max: {}, current_messages: {}",
|
||||
&self.queue, &attrs.capacity, &attrs.max_msg_len, &attrs.current_messages
|
||||
self.queue, attrs.capacity, attrs.max_msg_len, attrs.current_messages
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use chrono::{DateTime, Local};
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use log::warn;
|
||||
use std::{fs, os::unix::fs::PermissionsExt};
|
||||
|
||||
/// Print a list of existing message queues
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct List {
|
||||
/// Show all parameters
|
||||
#[clap(short, long)]
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use chrono::{DateTime, Local};
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use humantime::Duration;
|
||||
use log::info;
|
||||
use posixmq::PosixMq;
|
||||
use std::str;
|
||||
|
||||
/// Receive and print a message from a message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Recv {
|
||||
/// Do not block
|
||||
#[clap(short, long)]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::Result;
|
||||
use chrono::DateTime;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use humantime::Duration;
|
||||
use log::info;
|
||||
|
||||
/// Send a message to a message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Send {
|
||||
/// Set a different priority, priority >= 0
|
||||
#[clap(short, long, default_value = "0")]
|
||||
|
@ -38,24 +38,24 @@ impl Send {
|
|||
if let Some(timeout) = &self.timeout {
|
||||
mq.open(&self.queue)?.send_timeout(
|
||||
self.priority,
|
||||
&self.msg.as_bytes(),
|
||||
self.msg.as_bytes(),
|
||||
*timeout.parse::<Duration>()?,
|
||||
)?;
|
||||
|
||||
info!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue);
|
||||
info!("Sent message: \"{}\" to queue: {}", self.msg, self.queue);
|
||||
} else if let Some(deadline) = &self.deadline {
|
||||
mq.open(&self.queue)?.send_deadline(
|
||||
self.priority,
|
||||
&self.msg.as_bytes(),
|
||||
self.msg.as_bytes(),
|
||||
DateTime::parse_from_str(deadline, "%Y-%m-%d %H:%M:%S")?.into(),
|
||||
)?;
|
||||
|
||||
info!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue);
|
||||
info!("Sent message: \"{}\" to queue: {}", self.msg, self.queue);
|
||||
} else {
|
||||
mq.open(&self.queue)?
|
||||
.send(self.priority, &self.msg.as_bytes())?;
|
||||
.send(self.priority, self.msg.as_bytes())?;
|
||||
|
||||
info!("Sent message: \"{}\" to queue: {}", &self.msg, &self.queue);
|
||||
info!("Sent message: \"{}\" to queue: {}", self.msg, self.queue);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
|
||||
/// Delete a message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Unlink {
|
||||
/// Name of the queue
|
||||
#[clap(value_name = "QUEUE")]
|
||||
|
@ -14,7 +14,7 @@ impl Unlink {
|
|||
pub fn run(&self) -> Result<()> {
|
||||
posixmq::remove_queue(&self.queue)?;
|
||||
|
||||
info!("Removed message queue: {}", &self.queue);
|
||||
info!("Removed message queue: {}", self.queue);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Create a SysV message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Create {
|
||||
/// Permissions (octal) to create the queue with (default: 0644)
|
||||
#[clap(short, long)]
|
||||
|
@ -19,7 +19,7 @@ impl Create {
|
|||
let mut mq = SysvMq::<String>::new();
|
||||
|
||||
if let Some(m) = &self.mode {
|
||||
mq.mode(i32::from_str_radix(&m, 8)?);
|
||||
mq.mode(i32::from_str_radix(m, 8)?);
|
||||
}
|
||||
|
||||
mq.create(self.key)?;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
};
|
||||
|
||||
/// Print information about an existing message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Info {
|
||||
/// Id of the queue
|
||||
#[clap(short, long, required_unless_present_any = &["key"], conflicts_with = "key")]
|
||||
|
@ -28,7 +28,7 @@ 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()))?);
|
||||
print_line(&lines.next().unwrap_or_else(|| Ok(String::new()))?);
|
||||
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
};
|
||||
|
||||
/// Print a list of existing message queues
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct List {}
|
||||
|
||||
impl List {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::Result;
|
||||
use clap::Clap;
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
|
||||
/// Delete a message queue
|
||||
#[derive(Clap, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Unlink {
|
||||
/// Id of the queue
|
||||
#[clap(
|
||||
|
|
Loading…
Reference in a new issue