Skip to content

Commit

Permalink
refactor: 💡 cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: NachiketNamjoshi <nachiketnamjoshi@gmail.com>
  • Loading branch information
NachiketNamjoshi committed May 13, 2023
1 parent f0097d0 commit 8a64995
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
10 changes: 2 additions & 8 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ fn find_target_inodes(port: u16) -> Vec<u64> {
///
/// * `target_inode` - A u64 value representing the target inode.
/// * `signal` - A enum value representing the signal type.
fn kill_processes_by_inode(
target_inode: u64,
signal: Signal,
) -> Result<bool, Error> {
fn kill_processes_by_inode(target_inode: u64, signal: Signal) -> Result<bool, Error> {
let processes = procfs::process::all_processes().unwrap();
let mut killed_any = false;

Expand Down Expand Up @@ -160,10 +157,7 @@ fn kill_processes_by_inode(
///
/// * `pid` - An i32 value representing the process ID.
/// * `signal` - A enum value representing the signal type.
fn kill_process_and_children(
pid: i32,
signal: Signal,
) -> Result<(), std::io::Error> {
fn kill_process_and_children(pid: i32, signal: Signal) -> Result<(), std::io::Error> {
let mut children_pids = Vec::new();
collect_child_pids(pid, &mut children_pids)?;

Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ fn parse_signal(arg: &str) -> Result<Signal, std::io::Error> {
Ok(str_arg) => {
let signal_str = str_arg.to_uppercase();
let signal = Signal::from_str(signal_str.as_str())?;
return Ok(signal)
},
Err(e) => Err(std::io::Error::new(std::io::ErrorKind::Other, e))
return Ok(signal);
}
Err(e) => Err(std::io::Error::new(std::io::ErrorKind::Other, e)),
}
}

Expand Down
45 changes: 32 additions & 13 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use assert_cmd::Command;
use std::{fs::File, path};
use std::io::Write;
use std::{fs::File, path};
use tempfile::tempdir;

#[test]
Expand Down Expand Up @@ -45,10 +45,15 @@ fn test_killport() {
// Software termination signal from kill
test_killport_signal_arg(tempdir_path, "sigterm");
// Stack fault (obsolete)
#[cfg(all(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux"),
not(any(target_arch = "mips", target_arch = "mips64",
target_arch = "sparc64"))))]
#[cfg(all(
any(
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "linux"
),
not(any(target_arch = "mips", target_arch = "mips64", target_arch = "sparc64"))
))]
test_killport_signal_arg(tempdir_path, "sigstkflt");
// To parent on child stop or exit
test_killport_signal_arg(tempdir_path, "sigchld");
Expand Down Expand Up @@ -78,22 +83,36 @@ fn test_killport() {
#[cfg(not(target_os = "haiku"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
test_killport_signal_arg(tempdir_path, "sigio");
#[cfg(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux"))]
#[cfg(any(
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "linux"
))]
#[cfg_attr(docsrs, doc(cfg(all())))]
// Power failure imminent.
test_killport_signal_arg(tempdir_path, "sigpwr");
// Bad system call
test_killport_signal_arg(tempdir_path, "sigsys");
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox", target_os = "haiku")))]
#[cfg(not(any(
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "linux",
target_os = "redox",
target_os = "haiku"
)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
// Emulator trap
test_killport_signal_arg(tempdir_path, "sigemt");
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox", target_os = "haiku")))]
#[cfg(not(any(
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "linux",
target_os = "redox",
target_os = "haiku"
)))]
#[cfg_attr(docsrs, doc(cfg(all())))]
// Information request
test_killport_signal_arg(tempdir_path, "siginfo");
Expand Down

0 comments on commit 8a64995

Please sign in to comment.