Compare commits
10 commits
main
...
wip/update
Author | SHA1 | Date | |
---|---|---|---|
5e777c577a | |||
6d25619673 | |||
79a2ad1d88 | |||
2c4d04b374 | |||
523c48b6f5 | |||
45cf653977 | |||
e1cac4e164 | |||
74090abdb6 | |||
f65039f615 | |||
2ba9aa34e9 |
19 changed files with 1026 additions and 378 deletions
7
.cargo/config
Normal file
7
.cargo/config
Normal file
|
@ -0,0 +1,7 @@
|
|||
[target.'cfg(feature = "cargo-clippy")']
|
||||
rustflags = [
|
||||
"-Dwarnings",
|
||||
"-Dclippy::pedantic",
|
||||
"-Dclippy::nursery",
|
||||
"-Dclippy::cargo",
|
||||
]
|
18
CHANGELOG.md
Normal file
18
CHANGELOG.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a
|
||||
Changelog](https://keepachangelog.com/en/1.0.0/), and this project
|
||||
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Update to the latext version of **env_logger**.
|
||||
- Update to the latext version of **nix**.
|
||||
- Fix several clippy findings in preperation to enable several lint
|
||||
groups.
|
||||
- Update to the latest version of **clap**.
|
||||
- Update all dependencies that should not break SemVer.
|
604
Cargo.lock
generated
604
Cargo.lock
generated
|
@ -4,47 +4,108 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.51"
|
||||
name = "android-tzdata"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
|
||||
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
name = "anstream"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
checksum = "a3a318f1f38d2418400f8209655bfd825785afd25aa30bb7ba6cc792e4596748"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
version = "2.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.72"
|
||||
version = "1.0.83"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
||||
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
@ -54,84 +115,104 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
version = "0.4.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
||||
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"android-tzdata",
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"time",
|
||||
"winapi",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.0.0-beta.5"
|
||||
version = "4.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "feff3878564edb93745d58cf63e17b63f24142506e7a20c87a5521ed7bfb1d63"
|
||||
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
"indexmap",
|
||||
"lazy_static",
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.4.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
"unicase",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "3.0.0-beta.5"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b15c6b4f786ffb6192ffe65a36855bc1fc2444bcd0945ae16748dcd6ed7d0d3"
|
||||
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.8.4"
|
||||
name = "clap_lex"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3"
|
||||
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"is-terminal",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.11.2"
|
||||
name = "errno"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.3"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
|
@ -140,50 +221,71 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.7.0"
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.58"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
||||
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
"android_system_properties",
|
||||
"core-foundation-sys",
|
||||
"iana-time-zone-haiku",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"windows-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
name = "iana-time-zone-haiku"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"rustix",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.108"
|
||||
version = "0.2.150"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
|
||||
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.14"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
version = "2.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||
|
||||
[[package]]
|
||||
name = "mqrs"
|
||||
|
@ -201,44 +303,29 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.21.2"
|
||||
version = "0.27.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77d9f3521ea8e0641a153b3cddaf008dcbf26acd4ed739a2517295e0760d12c7"
|
||||
checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"memoffset",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.14"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
version = "4.2.0"
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "addaa943333a514159c80c97ff4a93306530d965d27e139188283cd13e06a799"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "posixmq"
|
||||
|
@ -249,53 +336,41 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.32"
|
||||
version = "1.0.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
|
||||
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.10"
|
||||
version = "1.0.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.5.4"
|
||||
version = "1.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -304,9 +379,22 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.25"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
|
@ -316,13 +404,13 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.82"
|
||||
version = "2.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
|
||||
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -336,36 +424,27 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.30"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
|
||||
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.30"
|
||||
version = "1.0.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
|
||||
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -373,54 +452,70 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.1.44"
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"winapi",
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
|
||||
checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
|
||||
dependencies = [
|
||||
"version_check",
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.8.0"
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||
checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.9"
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||
checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.2"
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
|
||||
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
|
@ -440,9 +535,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
@ -452,3 +547,144 @@ name = "winapi-x86_64-pc-windows-gnu"
|
|||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.48.5",
|
||||
"windows_aarch64_msvc 0.48.5",
|
||||
"windows_i686_gnu 0.48.5",
|
||||
"windows_i686_msvc 0.48.5",
|
||||
"windows_x86_64_gnu 0.48.5",
|
||||
"windows_x86_64_gnullvm 0.48.5",
|
||||
"windows_x86_64_msvc 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.0",
|
||||
"windows_aarch64_msvc 0.52.0",
|
||||
"windows_i686_gnu 0.52.0",
|
||||
"windows_i686_msvc 0.52.0",
|
||||
"windows_x86_64_gnu 0.52.0",
|
||||
"windows_x86_64_gnullvm 0.52.0",
|
||||
"windows_x86_64_msvc 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
|
||||
|
|
12
Cargo.toml
12
Cargo.toml
|
@ -11,13 +11,13 @@ keywords = ["message_queue", "mq", "mqueue", "queue"]
|
|||
categories = ["command-line-utilities"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
clap = "3.0.0-beta.2"
|
||||
posixmq = "1.0"
|
||||
chrono = "0.4"
|
||||
anyhow = "1.0.51"
|
||||
chrono = "0.4.31"
|
||||
clap = { version = "4.4.6", features = ["derive"] }
|
||||
env_logger = "0.10.0"
|
||||
humantime = "2.1"
|
||||
log = "0.4"
|
||||
env_logger = "0.8"
|
||||
log = "0.4.14"
|
||||
posixmq = "1.0.0"
|
||||
sysvmq = { path = "sysvmq" }
|
||||
|
||||
[workspace]
|
||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -1,5 +1,7 @@
|
|||
use anyhow::Result;
|
||||
use clap::{crate_authors, crate_version, AppSettings, Parser};
|
||||
use clap::Parser;
|
||||
use log::Level;
|
||||
use std::env;
|
||||
|
||||
mod posix;
|
||||
mod sysv;
|
||||
|
@ -30,20 +32,20 @@ enum SysvCommand {
|
|||
Info(sysv::Info),
|
||||
List(sysv::List),
|
||||
Unlink(sysv::Unlink),
|
||||
Send(sysv::Send),
|
||||
Recv(sysv::Recv),
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(
|
||||
version = crate_version!(),
|
||||
author = crate_authors!(", "),
|
||||
setting = AppSettings::SubcommandRequiredElseHelp,
|
||||
global_setting = AppSettings::PropagateVersion,
|
||||
global_setting = AppSettings::InferSubcommands,
|
||||
arg_required_else_help = true,
|
||||
infer_subcommands = true,
|
||||
subcommand_required = true
|
||||
)]
|
||||
struct Opts {
|
||||
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
|
||||
#[clap(short, long, global = true, parse(from_occurrences))]
|
||||
verbose: u32,
|
||||
/// Set a log level
|
||||
#[arg(short, long, value_name = "LEVEL", default_value_t = Level::Info)]
|
||||
pub log_level: Level,
|
||||
/// Backend to be used
|
||||
#[clap(subcommand)]
|
||||
backend: Backend,
|
||||
|
@ -52,15 +54,11 @@ struct Opts {
|
|||
fn main() -> Result<()> {
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
|
||||
match opts.verbose {
|
||||
0 => "warn",
|
||||
1 => "info",
|
||||
2 => "debug",
|
||||
_ => "trace",
|
||||
},
|
||||
))
|
||||
.init();
|
||||
if env::var("RUST_LOG").is_err() {
|
||||
env::set_var("RUST_LOG", format!("{}", opts.log_level));
|
||||
}
|
||||
|
||||
env_logger::init();
|
||||
|
||||
match opts.backend {
|
||||
Backend::Posix(p) => match p {
|
||||
|
@ -76,6 +74,8 @@ fn main() -> Result<()> {
|
|||
SysvCommand::Info(i) => i.run()?,
|
||||
SysvCommand::List(l) => l.run()?,
|
||||
SysvCommand::Unlink(u) => u.run()?,
|
||||
SysvCommand::Send(s) => s.run()?,
|
||||
SysvCommand::Recv(r) => r.run()?,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -22,17 +22,13 @@ pub struct Create {
|
|||
}
|
||||
|
||||
fn msgsize_default() -> usize {
|
||||
match fs::read_to_string("/proc/sys/fs/mqueue/msgsize_default") {
|
||||
Ok(m) => m.trim().parse::<usize>().expect("can never fail"),
|
||||
_ => 8192,
|
||||
}
|
||||
fs::read_to_string("/proc/sys/fs/mqueue/msgsize_default")
|
||||
.map_or(8192, |m| m.trim().parse::<usize>().expect("can never fail"))
|
||||
}
|
||||
|
||||
fn msg_default() -> usize {
|
||||
match fs::read_to_string("/proc/sys/fs/mqueue/msg_default") {
|
||||
Ok(m) => m.trim().parse::<usize>().expect("can never fail"),
|
||||
_ => 10,
|
||||
}
|
||||
fs::read_to_string("/proc/sys/fs/mqueue/msg_default")
|
||||
.map_or(10, |m| m.trim().parse::<usize>().expect("can never fail"))
|
||||
}
|
||||
|
||||
impl Create {
|
||||
|
|
|
@ -14,12 +14,13 @@ pub struct List {
|
|||
|
||||
impl List {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
match self.all {
|
||||
false => println!("Name"),
|
||||
true => println!(
|
||||
if self.all {
|
||||
println!(
|
||||
"{0: <10} {1: <10} {2: <12} {3: <26} {4: <26}",
|
||||
"Name", "Size", "Permissions", "Modified", "Accessed",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
println!("Name");
|
||||
}
|
||||
|
||||
for mq in fs::read_dir("/dev/mqueue")? {
|
||||
|
|
|
@ -36,7 +36,7 @@ fn print_message(priority: u32, length: usize, timestamp: bool, msg: &str) {
|
|||
println!("{}", Local::now());
|
||||
}
|
||||
|
||||
println!("{}", msg);
|
||||
println!("{msg}");
|
||||
}
|
||||
|
||||
impl Recv {
|
||||
|
|
|
@ -3,7 +3,8 @@ use clap::Parser;
|
|||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Create a SysV message queue
|
||||
#[allow(clippy::doc_markdown)]
|
||||
/// Create a SysV IPC message queue
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Create {
|
||||
/// Permissions (octal) to create the queue with (default: 0644)
|
||||
|
|
|
@ -17,8 +17,8 @@ pub struct Info {
|
|||
}
|
||||
|
||||
fn print_line(line: &str) {
|
||||
for field in line.split_whitespace().collect::<Vec<&str>>() {
|
||||
print!("{0: <10}", field);
|
||||
for field in line.split_whitespace() {
|
||||
print!("{field: <10}");
|
||||
}
|
||||
|
||||
println!();
|
||||
|
|
|
@ -10,10 +10,11 @@ use std::{
|
|||
pub struct List {}
|
||||
|
||||
impl List {
|
||||
#[allow(clippy::unused_self)]
|
||||
pub fn run(&self) -> Result<()> {
|
||||
for line in BufReader::new(File::open("/proc/sysvipc/msg")?).lines() {
|
||||
for field in line?.split_whitespace().collect::<Vec<&str>>() {
|
||||
print!("{0: <10}", field);
|
||||
for field in line?.split_whitespace() {
|
||||
print!("{field: <10}");
|
||||
}
|
||||
|
||||
println!();
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
mod create;
|
||||
mod info;
|
||||
mod list;
|
||||
mod recv;
|
||||
mod send;
|
||||
mod unlink;
|
||||
|
||||
pub use create::Create;
|
||||
pub use info::Info;
|
||||
pub use list::List;
|
||||
pub use recv::Recv;
|
||||
pub use send::Send;
|
||||
pub use unlink::Unlink;
|
||||
|
|
42
src/sysv/recv.rs
Normal file
42
src/sysv/recv.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use anyhow::Result;
|
||||
// use chrono::DateTime;
|
||||
use clap::Parser;
|
||||
// use humantime::Duration;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Send a message to a message queue
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Recv {
|
||||
// /// Set a different priority, priority >= 0
|
||||
// #[clap(short, long, default_value = "0")]
|
||||
// priority: u32,
|
||||
// /// Do not block
|
||||
// #[clap(short, long)]
|
||||
// non_blocking: bool,
|
||||
// /// Timeout, example "5h 23min 42ms"
|
||||
// #[clap(short = 'o', long, conflicts_with = "deadline")]
|
||||
// timeout: Option<String>,
|
||||
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
|
||||
// #[clap(short, long, conflicts_with = "timeout")]
|
||||
// deadline: Option<String>,
|
||||
// /// Name of the queue
|
||||
// #[clap(value_name = "QUEUE")]
|
||||
// queue: String,
|
||||
/// Key of of the queue to write to
|
||||
#[clap(value_name = "Key")]
|
||||
key: i32,
|
||||
// /// Message to be sent to the queue
|
||||
// #[clap(value_name = "MESSAGE")]
|
||||
// msg: String,
|
||||
}
|
||||
|
||||
impl Recv {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mq = SysvMq::<String>::new();
|
||||
|
||||
mq.open(self.key)?.recv();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
42
src/sysv/send.rs
Normal file
42
src/sysv/send.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use anyhow::Result;
|
||||
// use chrono::DateTime;
|
||||
use clap::Parser;
|
||||
// use humantime::Duration;
|
||||
use log::info;
|
||||
use sysvmq::SysvMq;
|
||||
|
||||
/// Send a message to a message queue
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct Send {
|
||||
// /// Set a different priority, priority >= 0
|
||||
// #[clap(short, long, default_value = "0")]
|
||||
// priority: u32,
|
||||
// /// Do not block
|
||||
// #[clap(short, long)]
|
||||
// non_blocking: bool,
|
||||
// /// Timeout, example "5h 23min 42ms"
|
||||
// #[clap(short = 'o', long, conflicts_with = "deadline")]
|
||||
// timeout: Option<String>,
|
||||
// /// Deadline until messages are sent (format: "%Y-%m-%d %H:%M:%S")
|
||||
// #[clap(short, long, conflicts_with = "timeout")]
|
||||
// deadline: Option<String>,
|
||||
// /// Name of the queue
|
||||
// #[clap(value_name = "QUEUE")]
|
||||
// queue: String,
|
||||
/// Key of of the queue to write to
|
||||
#[clap(value_name = "Key")]
|
||||
key: i32,
|
||||
/// Message to be sent to the queue
|
||||
#[clap(value_name = "MESSAGE")]
|
||||
msg: String,
|
||||
}
|
||||
|
||||
impl Send {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
let mq = SysvMq::<String>::new();
|
||||
|
||||
mq.open(self.key)?.send(self.msg.as_bytes());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
44
sysvmq/CHANGELOG.md
Normal file
44
sysvmq/CHANGELOG.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a
|
||||
Changelog](https://keepachangelog.com/en/1.0.0/), and this project
|
||||
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Basic tests to create, send, receive and delete a message queue as
|
||||
well as changing the mode of a queue.
|
||||
- The functions `SysvMq::stat()`, `SysvMq::info()`,
|
||||
`SysvMq::msg_stat()` and `SysvMq::msg_info()` are added to receive
|
||||
parameters of a queue.
|
||||
- The function `new()` passes now a key which is used for the new
|
||||
message queue.
|
||||
- A basic test to test the happy path of a queue.
|
||||
- The function `get()` to gather facts from a message queue.
|
||||
- The function `set()` to set facts of a message queue.
|
||||
- The function `create()` to create a message queue.
|
||||
- The functions `send()` and `SysvMq::send()` to send messages to a
|
||||
queue.
|
||||
- The functions `recv()` and `SysvMq::recv()` to receive messages from
|
||||
a queue.
|
||||
- The function `SysvMq::delete()` to delete a queue.
|
||||
|
||||
### Changed
|
||||
|
||||
- The function `SysvMq::mode()` now also updates the message queue
|
||||
accordingly.
|
||||
- Remove `PhantomData` from the `SysvMq` struct.
|
||||
- The function `SysvMq::create()` is replaced by `SysvMq::new()`.
|
||||
- Remove generic type for `SysvMq`.
|
||||
- Rename `unlink_id()` to `delete()`.
|
||||
- Update to the latest verscion of `nix`.
|
||||
- Fix several clippy findings in preperation to enable several lint
|
||||
groups.
|
||||
|
||||
### Removed
|
||||
|
||||
- The function `id_from_key()` was removed.
|
|
@ -1,12 +1,15 @@
|
|||
[package]
|
||||
name = "sysvmq"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
authors = ["finga <mqrs@onders.org>"]
|
||||
repository = "https://git.onders.org/finga/mqrs"
|
||||
license = "GPL-3.0-or-later"
|
||||
description = "A simple API for SysV IPC message queues."
|
||||
keywords = ["message_queue", "mq", "mqueue", "queue", "sysv", "ipc"]
|
||||
categories = ["os"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.98"
|
||||
thiserror = "1.0.26"
|
||||
nix = "0.21.0"
|
||||
nix = "0.27.1"
|
||||
|
|
9
sysvmq/README.md
Normal file
9
sysvmq/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Sysvmq
|
||||
|
||||
This aims to be a easy usable API for SysV IPC message queues.
|
||||
|
||||
Note: This library is work in progress.
|
||||
|
||||
Currently supported operations are only `create` and `unlink`. The
|
||||
`create` operation creates a SysV IPC message queue and the `unlink`
|
||||
operation deletes such a SysV IPC message queue.
|
|
@ -1,179 +1,355 @@
|
|||
#![allow(clippy::doc_markdown)]
|
||||
//! This library provides a convenient API to SysV IPC message queues.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! ```rust
|
||||
//! use sysvmq::{SysvMq, SysvMqError};
|
||||
//!
|
||||
//! fn example() -> Result<(), SysvMqError> {
|
||||
//! let mut mq = SysvMq::new(0)?;
|
||||
//! let mut buf = [0u8; 11];
|
||||
//!
|
||||
//! mq.send(b"hello queue")?;
|
||||
//! mq.recv(&mut buf)?;
|
||||
//! mq.delete()?;
|
||||
//!
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use libc::{
|
||||
msgctl, msgget, msginfo, msqid_ds, IPC_CREAT, IPC_EXCL, IPC_INFO, IPC_NOWAIT, IPC_PRIVATE,
|
||||
IPC_RMID, IPC_SET, IPC_STAT, MSG_COPY, MSG_EXCEPT, MSG_INFO, MSG_NOERROR, MSG_STAT,
|
||||
c_void, msgctl, msgget, msgrcv, msgsnd, msqid_ds, IPC_CREAT, IPC_NOWAIT, IPC_RMID, IPC_SET,
|
||||
};
|
||||
pub use libc::{IPC_INFO, IPC_STAT, MSG_INFO, MSG_STAT};
|
||||
use nix::errno::{errno, Errno};
|
||||
use std::{marker::PhantomData, mem::MaybeUninit, ptr};
|
||||
use std::{convert::TryFrom, mem::MaybeUninit, ptr};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
/// An enum containing all errors
|
||||
pub enum SysvMqError {
|
||||
#[error("SysV message queue: {0}")]
|
||||
ErrnoError(&'static str),
|
||||
#[error("Cannot convert integer")]
|
||||
From(#[from] std::num::TryFromIntError),
|
||||
}
|
||||
|
||||
/// IPC bit flags
|
||||
#[repr(i32)]
|
||||
pub enum Flags {
|
||||
/// Create key if key does not exist.
|
||||
CreateKey = IPC_CREAT,
|
||||
/// Fail if key exists.
|
||||
Exclusive = IPC_EXCL,
|
||||
/// Return error on wait.
|
||||
NoWait = IPC_NOWAIT,
|
||||
/// No error if message is too big.
|
||||
NoError = MSG_NOERROR,
|
||||
/// Receive any message except of specified type.
|
||||
Except = MSG_EXCEPT,
|
||||
/// Copy (not remove) all queue messages.
|
||||
Copy = MSG_COPY,
|
||||
/// Private key (Special key value).
|
||||
Private = IPC_PRIVATE,
|
||||
/// Low level function to create a new SysV IPC message queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sysvmq::delete;
|
||||
/// use sysvmq::{create, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_id = create(0, 0o644)?;
|
||||
/// println!("new queue: {mq_id}");
|
||||
/// # delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the queue cannot be created.
|
||||
pub fn create(key: i32, mode: i32) -> Result<i32, SysvMqError> {
|
||||
let mq = unsafe { msgget(key, IPC_CREAT | mode) };
|
||||
|
||||
match mq {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
id => Ok(id),
|
||||
}
|
||||
}
|
||||
|
||||
/// Commands for `msgctl()`
|
||||
#[repr(i32)]
|
||||
pub enum ControlCommands {
|
||||
/// Remove identifier (Control command for `msgctl`, `semctl`, and `shmctl`).
|
||||
Remove = IPC_RMID,
|
||||
/// Set `ipc_perm` options (Control command for `msgctl`, `semctl`, and `shmctl`).
|
||||
SetPerm = IPC_SET,
|
||||
/// Get `ipc_perm` options (Control command for `msgctl`, `semctl`, and `shmctl`).
|
||||
GetPerm = IPC_STAT,
|
||||
/// See ipcs (Control command for `msgctl`, `semctl`, and `shmctl`).
|
||||
IpcInfo = IPC_INFO,
|
||||
/// IPCS control command.
|
||||
Stat = MSG_STAT,
|
||||
/// IPCS control command.
|
||||
MsgInfo = MSG_INFO,
|
||||
/// Low level function to send a message to a SysV IPC message queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sysvmq::{delete};
|
||||
/// use sysvmq::{create, send, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_id = create(0, 0o644)?;
|
||||
/// let msg = b"hello queue";
|
||||
/// send(mq_id, msg, 0)?;
|
||||
/// # delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message cannot be sent to the queue.
|
||||
pub fn send(id: i32, msg: &[u8], mask: i32) -> Result<(), SysvMqError> {
|
||||
match unsafe { msgsnd(id, msg.as_ptr().cast::<c_void>(), msg.len(), mask) } {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlink_id(id: i32) -> Result<(), SysvMqError> {
|
||||
let res = unsafe {
|
||||
msgctl(
|
||||
id,
|
||||
ControlCommands::Remove as i32,
|
||||
ptr::null::<msqid_ds>() as *mut msqid_ds,
|
||||
)
|
||||
/// Low level function to receive a message from a SysV IPC message
|
||||
/// queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sysvmq::{delete, send};
|
||||
/// use sysvmq::{create, recv, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_mask = 0o644;
|
||||
/// let mq_id = create(0, mq_mask)?;
|
||||
/// let mut buf = [0u8; 32];
|
||||
/// # let msg = b"hello queue";
|
||||
/// # send(mq_id, msg, 0)?;
|
||||
/// recv(mq_id, &mut buf, mq_mask)?;
|
||||
/// println!("received message: {:?}", buf);
|
||||
/// # delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message cannot be received from the
|
||||
/// queue.
|
||||
pub fn recv(id: i32, msg: &mut [u8], mask: i32) -> Result<(), SysvMqError> {
|
||||
match unsafe { msgrcv(id, msg.as_mut_ptr().cast::<c_void>(), msg.len(), 0, mask) } {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Low level function to get parameters of a SysV IPC message queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sysvmq::{delete};
|
||||
/// use sysvmq::{create, get, IPC_STAT, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_id = create(0, 0o644)?;
|
||||
/// let mq_stat = get(mq_id, IPC_STAT)?;
|
||||
/// println!("received message: {:?}", mq_stat);
|
||||
/// # delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the parameters cannot be gathered.
|
||||
pub fn get(id: i32, cmd: i32) -> Result<msqid_ds, SysvMqError> {
|
||||
let mut ipc_info = MaybeUninit::<msqid_ds>::uninit();
|
||||
let ret;
|
||||
|
||||
let ipc_info = unsafe {
|
||||
ret = msgctl(id, cmd, ipc_info.as_mut_ptr());
|
||||
ipc_info.assume_init()
|
||||
};
|
||||
|
||||
match ret {
|
||||
0 => Ok(ipc_info),
|
||||
_ => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Low level function to set parameters of a SysV IPC message queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use sysvmq::{delete};
|
||||
/// use sysvmq::{create, get, IPC_STAT, set, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_id = create(0, 0o644)?;
|
||||
/// let mut mq_stat = get(mq_id, IPC_STAT)?;
|
||||
/// mq_stat.msg_perm.mode = 0o666;
|
||||
/// set(mq_id, &mut mq_stat)?;
|
||||
/// # delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the parameters cannot be set.
|
||||
pub fn set(id: i32, data: &mut msqid_ds) -> Result<(), SysvMqError> {
|
||||
match unsafe { msgctl(id, IPC_SET, data) } {
|
||||
0 => Ok(()),
|
||||
_ => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
}
|
||||
}
|
||||
|
||||
/// Low level function to delete a SysV IPC message queue.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use sysvmq::{create, delete, SysvMqError};
|
||||
///
|
||||
/// fn main() -> Result<(), SysvMqError> {
|
||||
/// let mq_id = create(0, 0o644)?;
|
||||
/// delete(mq_id)?;
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when no queue with the given key can be
|
||||
/// found.
|
||||
pub fn delete(id: i32) -> Result<(), SysvMqError> {
|
||||
let res = unsafe { msgctl(id, IPC_RMID, ptr::null::<msqid_ds>().cast_mut()) };
|
||||
|
||||
match res {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id_from_key(key: i32) -> Result<i32, SysvMqError> {
|
||||
let id = unsafe { msgget(key, 0) };
|
||||
|
||||
match id {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
id => Ok(id),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ipc_info(id: i32) -> Result<(), SysvMqError> {
|
||||
let mut msginfo = MaybeUninit::<msginfo>::uninit();
|
||||
|
||||
unsafe {
|
||||
msgctl(
|
||||
id,
|
||||
ControlCommands::IpcInfo as i32,
|
||||
msginfo.as_mut_ptr() as *mut msqid_ds,
|
||||
);
|
||||
}
|
||||
|
||||
let msginfo = unsafe { msginfo.assume_init() };
|
||||
|
||||
println!("info: {:?}", msginfo);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn stat_info(id: i32) -> Result<(), SysvMqError> {
|
||||
let mut msginfo = MaybeUninit::<msqid_ds>::uninit();
|
||||
|
||||
unsafe {
|
||||
msgctl(id, ControlCommands::Stat as i32, msginfo.as_mut_ptr());
|
||||
}
|
||||
|
||||
let msginfo = unsafe { msginfo.assume_init() };
|
||||
|
||||
println!("info: {:?}", msginfo);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn msg_info(id: i32) -> Result<(), SysvMqError> {
|
||||
let mut msginfo = MaybeUninit::<msginfo>::uninit();
|
||||
|
||||
unsafe {
|
||||
msgctl(
|
||||
id,
|
||||
ControlCommands::MsgInfo as i32,
|
||||
msginfo.as_mut_ptr() as *mut msqid_ds,
|
||||
);
|
||||
}
|
||||
|
||||
let msginfo = unsafe { msginfo.assume_init() };
|
||||
|
||||
println!("info: {:?}", msginfo);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct SysvMq<T> {
|
||||
pub id: i32,
|
||||
#[derive(Clone, Debug)]
|
||||
/// Struct representation of a Message Queue
|
||||
pub struct SysvMq {
|
||||
pub key: i32,
|
||||
message_mask: i32,
|
||||
mode: i32,
|
||||
types: PhantomData<T>,
|
||||
pub id: i32,
|
||||
pub mask: i32,
|
||||
pub mode: i32,
|
||||
}
|
||||
|
||||
impl<T> SysvMq<T> {
|
||||
pub fn create(&mut self, key: i32) -> Result<&Self, SysvMqError> {
|
||||
self.key = key;
|
||||
self.id = unsafe { msgget(self.key, Flags::CreateKey as i32 | self.mode) };
|
||||
|
||||
match self.id {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(self),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open(mut self, key: i32) -> Result<Self, SysvMqError> {
|
||||
self.key = key;
|
||||
self.id = unsafe { msgget(self.key, self.mode) };
|
||||
|
||||
match self.id {
|
||||
-1 => Err(SysvMqError::ErrnoError(Errno::from_i32(errno()).desc())),
|
||||
_ => Ok(self),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mode(&mut self, mode: i32) -> &Self {
|
||||
self.mode = mode;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn nonblocking(&mut self) -> &Self {
|
||||
self.message_mask |= Flags::NoWait as i32;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
SysvMq {
|
||||
id: -1,
|
||||
key: 0,
|
||||
message_mask: 0,
|
||||
mode: 0o644,
|
||||
types: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Default for SysvMq<T> {
|
||||
impl Default for SysvMq {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self {
|
||||
key: 0,
|
||||
id: -1,
|
||||
mask: 0,
|
||||
mode: 0o644,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SysvMq {
|
||||
/// Create a new message SysV IPC message queue with the given
|
||||
/// key.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the queue cannot be created.
|
||||
pub fn new(key: i32) -> Result<Self, SysvMqError> {
|
||||
let mut mq = Self::default();
|
||||
mq.key = key;
|
||||
mq.id = create(mq.key, mq.mode)?;
|
||||
Ok(mq)
|
||||
}
|
||||
|
||||
/// Open an existing SysV IPC message queye with the given key.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the queue cannot be opened.
|
||||
pub fn open(key: i32, id: i32) -> Result<Self, SysvMqError> {
|
||||
let mut mq = Self::default();
|
||||
mq.key = key;
|
||||
mq.id = id;
|
||||
mq.mode = i32::from(get(mq.id, IPC_STAT)?.msg_perm.mode);
|
||||
Ok(mq)
|
||||
}
|
||||
|
||||
/// Set the mode of a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the mode of the queue cannot be set.
|
||||
pub fn mode(&mut self, mode: i32) -> Result<(), SysvMqError> {
|
||||
self.mode = mode;
|
||||
let mut stats = get(self.id, IPC_STAT)?;
|
||||
stats.msg_perm.mode = u16::try_from(self.mode)?;
|
||||
set(self.id, &mut stats)
|
||||
}
|
||||
|
||||
/// Set the mask of a SysV IPC message queue to nonblocking
|
||||
/// (`IPC_NOWAIT`).
|
||||
pub fn nonblocking(&mut self) {
|
||||
self.mask |= IPC_NOWAIT;
|
||||
}
|
||||
|
||||
/// Send a message to a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message cannot be sent to the queue.
|
||||
pub fn send(&mut self, msg: &[u8]) -> Result<(), SysvMqError> {
|
||||
send(self.id, msg, self.mask)
|
||||
}
|
||||
|
||||
/// Receive a message from a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message cannot be received from the
|
||||
/// queue.
|
||||
pub fn recv(&mut self, msg: &mut [u8]) -> Result<(), SysvMqError> {
|
||||
recv(self.id, msg, self.mask)
|
||||
}
|
||||
|
||||
/// Receive stats from a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the stats cannot be gathered from
|
||||
/// the queue.
|
||||
pub fn stat(&self) -> Result<msqid_ds, SysvMqError> {
|
||||
get(self.id, IPC_STAT)
|
||||
}
|
||||
|
||||
/// Receive info from a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the info cannot be gathered from the
|
||||
/// queue.
|
||||
pub fn info(&self) -> Result<msqid_ds, SysvMqError> {
|
||||
get(self.id, IPC_INFO)
|
||||
}
|
||||
|
||||
/// Receive message stats from a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message stats cannot be gathered
|
||||
/// from the queue.
|
||||
pub fn msg_stat(&self) -> Result<msqid_ds, SysvMqError> {
|
||||
get(self.id, MSG_STAT)
|
||||
}
|
||||
|
||||
/// Receive message info from a SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return `SysvMqError` when the message info cannot be gathered
|
||||
/// from the queue.
|
||||
pub fn msg_info(&self) -> Result<msqid_ds, SysvMqError> {
|
||||
get(self.id, MSG_INFO)
|
||||
}
|
||||
|
||||
/// Delete an existing SysV IPC message queue.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Return an `SysvMqError` when no queue with the given key can be
|
||||
/// found.
|
||||
pub fn delete(&mut self) -> Result<(), SysvMqError> {
|
||||
delete(self.id)
|
||||
}
|
||||
}
|
||||
|
|
68
sysvmq/tests/main.rs
Normal file
68
sysvmq/tests/main.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use sysvmq::SysvMq;
|
||||
|
||||
#[test]
|
||||
fn new_send_recv_delete() {
|
||||
let mut mq = SysvMq::new(0).expect("could not create SysV message queue with key 0");
|
||||
let msg = b"this is a test";
|
||||
let mut buf = [0u8; 14];
|
||||
mq.send(msg)
|
||||
.expect("could not send message to SysV message queue");
|
||||
mq.recv(&mut buf)
|
||||
.expect("could not receive message from SysV message queue");
|
||||
mq.delete().expect("could not destroy SysV message queue");
|
||||
assert_eq!(msg, &buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn separate_send_recv_clone() {
|
||||
let mut sender = SysvMq::new(0).expect("could not create SysV message queue with key 0");
|
||||
let mut receiver = sender.clone();
|
||||
let msg = b"this is another test";
|
||||
let mut buf = [0u8; 20];
|
||||
sender
|
||||
.send(msg)
|
||||
.expect("could not send message to SysV message queue");
|
||||
receiver
|
||||
.recv(&mut buf)
|
||||
.expect("could not receive message from SysV message queue");
|
||||
sender
|
||||
.delete()
|
||||
.expect("could not destroy SysV message queue");
|
||||
assert_eq!(msg, &buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn separate_send_recv_open() {
|
||||
let mut sender = SysvMq::new(0).expect("could not create SysV message queue with key 0");
|
||||
let mut receiver = SysvMq::open(sender.key, sender.id)
|
||||
.expect("could not create second handle to SysV message queue");
|
||||
let msg = b"this is another test";
|
||||
let mut buf = [0u8; 20];
|
||||
sender
|
||||
.send(msg)
|
||||
.expect("could not send message to SysV message queue");
|
||||
receiver
|
||||
.recv(&mut buf)
|
||||
.expect("could not receive message from SysV message queue");
|
||||
sender
|
||||
.delete()
|
||||
.expect("could not destroy SysV message queue");
|
||||
assert_eq!(msg, &buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn change_mode() {
|
||||
let mut mq = SysvMq::new(0).expect("could not create SysV message queue with key 0");
|
||||
let init_stats = mq
|
||||
.stat()
|
||||
.expect("could not get stats from SysV message queue");
|
||||
mq.mode(0o666)
|
||||
.expect("could not set mode of SysV message queue");
|
||||
let new_stats = mq
|
||||
.stat()
|
||||
.expect("could not get stats from SysV message queue");
|
||||
mq.delete().expect("could not destroy SysV message queue");
|
||||
|
||||
assert_eq!(0o644, init_stats.msg_perm.mode);
|
||||
assert_eq!(0o666, new_stats.msg_perm.mode);
|
||||
}
|
Loading…
Reference in a new issue