Compare commits

..

No commits in common. "8f93d2d6c8d10d07e91738a62e182bc8dfb5aa75" and "d5ef64171a530bb7e0de96235978da56003eccc9" have entirely different histories.

13 changed files with 64 additions and 70 deletions

52
Cargo.lock generated
View file

@ -13,9 +13,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.51" version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203" checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
[[package]] [[package]]
name = "atty" name = "atty"
@ -42,9 +42,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.72" version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -67,9 +67,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.0.0-beta.5" version = "3.0.0-beta.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63" checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
@ -80,14 +80,14 @@ dependencies = [
"strsim", "strsim",
"termcolor", "termcolor",
"textwrap", "textwrap",
"unicase", "vec_map",
] ]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.0.0-beta.5" version = "3.0.0-beta.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3" checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro-error", "proc-macro-error",
@ -157,9 +157,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.108" version = "0.2.103"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
[[package]] [[package]]
name = "log" name = "log"
@ -233,12 +233,9 @@ dependencies = [
[[package]] [[package]]
name = "os_str_bytes" name = "os_str_bytes"
version = "4.2.0" version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799" checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "posixmq" name = "posixmq"
@ -275,9 +272,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.32" version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -316,9 +313,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.82" version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -383,15 +380,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "unicode-segmentation" name = "unicode-segmentation"
version = "1.8.0" version = "1.8.0"
@ -410,6 +398,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.3"

View file

@ -2,7 +2,7 @@
name = "mqrs" name = "mqrs"
version = "0.1.1" version = "0.1.1"
authors = ["finga <mqrs@onders.org>"] authors = ["finga <mqrs@onders.org>"]
edition = "2021" edition = "2018"
repository = "https://git.onders.org/finga/mqrs" repository = "https://git.onders.org/finga/mqrs"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
readme = "README.md" readme = "README.md"

View file

@ -1,10 +1,10 @@
use anyhow::Result; use anyhow::Result;
use clap::{crate_authors, crate_version, AppSettings, Parser}; use clap::{crate_authors, crate_version, AppSettings, Clap};
mod posix; mod posix;
mod sysv; mod sysv;
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
enum Backend { enum Backend {
/// Handle POSIX message queues /// Handle POSIX message queues
#[clap(subcommand)] #[clap(subcommand)]
@ -14,7 +14,7 @@ enum Backend {
Sysv(SysvCommand), Sysv(SysvCommand),
} }
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
enum PosixCommand { enum PosixCommand {
Create(posix::Create), Create(posix::Create),
Info(posix::Info), Info(posix::Info),
@ -24,7 +24,7 @@ enum PosixCommand {
Recv(posix::Recv), Recv(posix::Recv),
} }
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
enum SysvCommand { enum SysvCommand {
Create(sysv::Create), Create(sysv::Create),
Info(sysv::Info), Info(sysv::Info),
@ -32,7 +32,7 @@ enum SysvCommand {
Unlink(sysv::Unlink), Unlink(sysv::Unlink),
} }
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
#[clap( #[clap(
version = crate_version!(), version = crate_version!(),
author = crate_authors!(", "), author = crate_authors!(", "),

View file

@ -1,11 +1,11 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use log::{info, log_enabled, Level::Info}; use log::{info, log_enabled, Level::Info};
use posixmq::PosixMq; use posixmq::PosixMq;
use std::fs; use std::fs;
/// Create a POSIX message queue /// Create a POSIX message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Create { pub struct Create {
/// Permissions (octal) to create the queue with /// Permissions (octal) to create the queue with
#[clap(short, long)] #[clap(short, long)]
@ -40,7 +40,7 @@ impl Create {
let mq = &mut posixmq::OpenOptions::readonly(); let mq = &mut posixmq::OpenOptions::readonly();
if let Some(m) = &self.mode { 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)) mq.max_msg_len(self.msgsize.unwrap_or_else(msgsize_default))
@ -53,10 +53,10 @@ impl Create {
let attributes = mq.attributes()?; let attributes = mq.attributes()?;
info!("Created message queue: {} with attributes msgsize: {}, capacity: {}, current_messages: {}", info!("Created message queue: {} with attributes msgsize: {}, capacity: {}, current_messages: {}",
self.queue, &self.queue,
attributes.max_msg_len, &attributes.max_msg_len,
attributes.capacity, &attributes.capacity,
attributes.current_messages); &attributes.current_messages);
} }
Ok(()) Ok(())

View file

@ -1,9 +1,9 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use posixmq::PosixMq; use posixmq::PosixMq;
/// Print information about an existing message queue /// Print information about an existing message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Info { pub struct Info {
/// Name of the queue /// Name of the queue
#[clap(value_name = "QUEUE")] #[clap(value_name = "QUEUE")]
@ -16,7 +16,7 @@ impl Info {
println!( println!(
"Message queue: {}, msg_max: {}, msgsize_max: {}, current_messages: {}", "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(()) Ok(())

View file

@ -1,11 +1,11 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use clap::Parser; use clap::Clap;
use log::warn; use log::warn;
use std::{fs, os::unix::fs::PermissionsExt}; use std::{fs, os::unix::fs::PermissionsExt};
/// Print a list of existing message queues /// Print a list of existing message queues
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct List { pub struct List {
/// Show all parameters /// Show all parameters
#[clap(short, long)] #[clap(short, long)]

View file

@ -1,13 +1,13 @@
use anyhow::Result; use anyhow::Result;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use clap::Parser; use clap::Clap;
use humantime::Duration; use humantime::Duration;
use log::info; use log::info;
use posixmq::PosixMq; use posixmq::PosixMq;
use std::str; use std::str;
/// Receive and print a message from a message queue /// Receive and print a message from a message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Recv { pub struct Recv {
/// Do not block /// Do not block
#[clap(short, long)] #[clap(short, long)]

View file

@ -1,11 +1,11 @@
use anyhow::Result; use anyhow::Result;
use chrono::DateTime; use chrono::DateTime;
use clap::Parser; use clap::Clap;
use humantime::Duration; use humantime::Duration;
use log::info; use log::info;
/// Send a message to a message queue /// Send a message to a message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Send { pub struct Send {
/// Set a different priority, priority >= 0 /// Set a different priority, priority >= 0
#[clap(short, long, default_value = "0")] #[clap(short, long, default_value = "0")]
@ -38,24 +38,24 @@ impl Send {
if let Some(timeout) = &self.timeout { if let Some(timeout) = &self.timeout {
mq.open(&self.queue)?.send_timeout( mq.open(&self.queue)?.send_timeout(
self.priority, self.priority,
self.msg.as_bytes(), &self.msg.as_bytes(),
*timeout.parse::<Duration>()?, *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 { } else if let Some(deadline) = &self.deadline {
mq.open(&self.queue)?.send_deadline( mq.open(&self.queue)?.send_deadline(
self.priority, self.priority,
self.msg.as_bytes(), &self.msg.as_bytes(),
DateTime::parse_from_str(deadline, "%Y-%m-%d %H:%M:%S")?.into(), 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 { } else {
mq.open(&self.queue)? 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(()) Ok(())

View file

@ -1,9 +1,9 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use log::info; use log::info;
/// Delete a message queue /// Delete a message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Unlink { pub struct Unlink {
/// Name of the queue /// Name of the queue
#[clap(value_name = "QUEUE")] #[clap(value_name = "QUEUE")]
@ -14,7 +14,7 @@ impl Unlink {
pub fn run(&self) -> Result<()> { pub fn run(&self) -> Result<()> {
posixmq::remove_queue(&self.queue)?; posixmq::remove_queue(&self.queue)?;
info!("Removed message queue: {}", self.queue); info!("Removed message queue: {}", &self.queue);
Ok(()) Ok(())
} }

View file

@ -1,10 +1,10 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use log::info; use log::info;
use sysvmq::SysvMq; use sysvmq::SysvMq;
/// Create a SysV message queue /// Create a SysV message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Create { pub struct Create {
/// Permissions (octal) to create the queue with (default: 0644) /// Permissions (octal) to create the queue with (default: 0644)
#[clap(short, long)] #[clap(short, long)]
@ -19,7 +19,7 @@ impl Create {
let mut mq = SysvMq::<String>::new(); let mut mq = SysvMq::<String>::new();
if let Some(m) = &self.mode { 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)?; mq.create(self.key)?;

View file

@ -1,12 +1,12 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use std::{ use std::{
fs::File, fs::File,
io::{BufRead, BufReader}, io::{BufRead, BufReader},
}; };
/// Print information about an existing message queue /// Print information about an existing message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Info { pub struct Info {
/// Id of the queue /// Id of the queue
#[clap(short, long, required_unless_present_any = &["key"], conflicts_with = "key")] #[clap(short, long, required_unless_present_any = &["key"], conflicts_with = "key")]
@ -28,7 +28,7 @@ impl Info {
pub fn run(&self) -> Result<()> { pub fn run(&self) -> Result<()> {
let mut lines = BufReader::new(File::open("/proc/sysvipc/msg")?).lines(); let mut lines = BufReader::new(File::open("/proc/sysvipc/msg")?).lines();
print_line(&lines.next().unwrap_or_else(|| Ok(String::new()))?); print_line(&lines.nth(0).unwrap_or(Ok(String::new()))?);
for line in lines { for line in lines {
let line = line?; let line = line?;

View file

@ -1,12 +1,12 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use std::{ use std::{
fs::File, fs::File,
io::{BufRead, BufReader}, io::{BufRead, BufReader},
}; };
/// Print a list of existing message queues /// Print a list of existing message queues
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct List {} pub struct List {}
impl List { impl List {

View file

@ -1,9 +1,9 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Clap;
use log::info; use log::info;
/// Delete a message queue /// Delete a message queue
#[derive(Debug, Parser)] #[derive(Clap, Debug)]
pub struct Unlink { pub struct Unlink {
/// Id of the queue /// Id of the queue
#[clap( #[clap(