From 6f9e7c21c8c7b7e358b52ba525b62b18bca0e2e2 Mon Sep 17 00:00:00 2001 From: nm17 Date: Sat, 15 Mar 2025 22:51:08 +0400 Subject: [PATCH] fix: dumb mistake --- Cargo.lock | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 12 ++++- src/main.rs | 31 +++++++++++-- 3 files changed, 167 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 131f951..f8a2df1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.18" @@ -142,6 +151,29 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3716d7a920fb4fac5d84e9d4bce8ceb321e9414b4409da61b07b75c1e3d0697" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + [[package]] name = "errno" version = "0.3.10" @@ -186,6 +218,30 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "jiff" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d699bc6dfc879fb1bf9bdff0d4c56f0884fc6f0d0eb0fba397a6d00cd9a6b85e" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde", +] + +[[package]] +name = "jiff-static" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d16e75759ee0aa64c57a56acbf43916987b20c77373cb7e808979e02b93c9f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "libc" version = "0.2.171" @@ -213,6 +269,12 @@ dependencies = [ "libc", ] +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + [[package]] name = "nusb" version = "0.1.13" @@ -238,6 +300,21 @@ version = "1.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cde51589ab56b20a6f686b2c68f7a0bd6add753d697abf720d63f8db3ab7b1ad" +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + +[[package]] +name = "portable-atomic-util" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +dependencies = [ + "portable-atomic", +] + [[package]] name = "proc-macro2" version = "1.0.94" @@ -256,12 +333,42 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "rust-dms" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "clap-verbosity-flag", + "env_logger", "hex", "libc", "log", @@ -283,6 +390,26 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "signal-hook" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 970eb4b..7bf4978 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rust-dms" -version = "0.1.0" +version = "0.1.1" edition = "2024" description = """ A tiny utility to execute certain actions on upon a disconnection of any given USB device. @@ -10,13 +10,23 @@ license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://git.dc09.ru/nm17/rust-dms" homepage = "https://git.dc09.ru/nm17/rust-dms" +keywords = ["dead-man-switch", "security", "usb", "privacy", "cli"] +categories = ["command-line-utilities", "command-line-interface"] [dependencies] clap = { version = "4.5.32", features = ["derive"] } clap-verbosity-flag = "3.0.2" +env_logger = "0.11.7" hex = { version = "0.4.3" } libc = { version = "0.2.171", default-features = false } log = "0.4.26" nusb = "0.1.13" signal-hook = "0.3.17" snafu = "0.8.5" + +[profile.release] +codegen-units = 1 +opt-level = "z" +strip = "symbols" +lto = true +panic = "abort" diff --git a/src/main.rs b/src/main.rs index 66e9a5f..bef11b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,9 @@ use std::{ use clap::Parser; use cli::Cli; +use env_logger::Builder; use error::*; -use log::{info, trace}; +use log::{debug, info, trace, error}; use snafu::ResultExt; pub fn check_if_plugged(pid: u16, vid: u16, first_run: bool) -> Result { @@ -33,9 +34,13 @@ pub fn check_if_plugged(pid: u16, vid: u16, first_run: bool) -> Result>) { @@ -60,6 +65,15 @@ pub fn execute_actions(cli: &Cli, actions: impl Iterator> fn main() -> Result<(), MyError> { let cli = Cli::parse(); + let mut builder = Builder::new(); + + builder + .default_format() + .filter(None, cli.verbosity.log_level_filter()) + .init(); + + + if cfg!(target_os = "linux") { use signal_handler::handle_signals; let _signals_handler = handle_signals(&cli)?; @@ -93,6 +107,8 @@ fn main() -> Result<(), MyError> { ), ); + trace!("First iteration of the loop..."); + let first_check = check_if_plugged(pid, vid, true); if let Err(ref _first_check_err) = first_check { if !cli.not_plugged_on_boot_actions.is_empty() { @@ -105,6 +121,15 @@ fn main() -> Result<(), MyError> { } } + // Everything was fine, but the device is not plugged in + if !first_check.unwrap() { + error!("Device is not found on first loop! Exiting..."); + + execute_actions(&cli, cli.not_plugged_on_boot_actions.iter()); + + exit(1); + } + info!("Successfully got through the first iteration of the loop"); loop {