Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkill: implement #290

Merged
merged 29 commits into from
Jan 15, 2025
Merged

pkill: implement #290

merged 29 commits into from
Jan 15, 2025

Conversation

MCredbear
Copy link
Contributor

#27

@cakebaker cakebaker changed the title pkill: impletment pkill: implement Dec 26, 2024
.idea/.gitignore Outdated Show resolved Hide resolved
.idea/modules.xml Outdated Show resolved Hide resolved
@sylvestre
Copy link
Contributor

Great start. Could you please add tests?

@MCredbear
Copy link
Contributor Author

Great start. Could you please add tests?

Yes, any advice?

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Dec 30, 2024

And also, more unit tests would be better. If it cannot run on Windows, you can disable it for Windows simply.

eg.

#[cfg(target_os = "linux")]
#[test]
fn test_something() {
...
}

At least you can write unit tests about parsing arguments?

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Jan 6, 2025

Could you please fix the CI failures?

    Compiling uu_pkill v0.0.1 (D:\a\procps\procps\src\uu\pkill)
   Compiling uu_watch v0.0.1 (D:\a\procps\procps\src\uu\watch)
error[E0433]: failed to resolve: could not find `sys` in `nix`
 --> src\uu\pkill\src\pkill.rs:8:10
  |
8 | use nix::sys::signal::{self, Signal};
  |          ^^^ could not find `sys` in `nix`

error[E0432]: unresolved import `nix::sys`
 --> src\uu\pkill\src\pkill.rs:8:10
  |
8 | use nix::sys::signal::{self, Signal};
  |          ^^^ could not find `sys` in `nix`

error[E0432]: unresolved import `nix::unistd`
 --> src\uu\pkill\src\pkill.rs:9:10
  |
9 | use nix::unistd::Pid;
  |          ^^^^^^ could not find `unistd` in `nix`

error[E0432]: unresolved import `uucore::signals`
  --> src\uu\pkill\src\pkill.rs:20:5
   |
20 |     signals::{signal_by_name_or_value, signal_name_by_value},
   |     ^^^^^^^ could not find `signals` in `uucore`
   |
note: found an item that was configured out
  --> C:\Users\runneradmin/.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\uucore-0.0.28\src\lib\lib.rs:82:26
   |
82 | pub use crate::features::signals;
   |                          ^^^^^^^
note: the item is gated here
  --> C:\Users\runneradmin/.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\uucore-0.0.28\src\lib\lib.rs:81:1
   |
81 | #[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   Compiling uu_pmap v0.0.1 (D:\a\procps\procps\src\uu\pmap)
   Compiling uu_slabtop v0.0.1 (D:\a\procps\procps\src\uu\slabtop)

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Jan 6, 2025

I think this file will help you to be compatible with macOS and other *NIX implementations.

https://github.com/uutils/coreutils/blob/main/src/uucore/src/lib/features/signals.rs

The Windows implementation much different with *NIX implementation, so you can simply disable it.

#[cfg(target_family = "unix")]
#[cfg(target_family = "unix")]
fn do_something(){}

#[cfg(not(target_family = "unix"))]
fn do_something(){}

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Jan 9, 2025

Behavior seems doesn't match

➜  procps git:(pkill) sleep 60&
[2] 529099
➜  procps git:(pkill) cargo run pkill 529099
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/procps pkill 529099`
[2]  + 529099 terminated  sleep 60
➜  procps git:(pkill) sleep 60&
[1] 530352
➜  procps git:(pkill) pkill 530352
➜  procps git:(pkill)

Comment on lines +96 to +117
#[cfg(unix)]
let sig_num = if let Some(signal) = obs_signal {
signal
} else if let Some(signal) = matches.get_one::<String>("signal") {
parse_signal_value(signal)?
} else {
15_usize //SIGTERM
};

#[cfg(unix)]
let sig_name = signal_name_by_value(sig_num);
// Signal does not support converting from EXIT
// Instead, nix::signal::kill expects Option::None to properly handle EXIT
#[cfg(unix)]
let sig: Option<Signal> = if sig_name.is_some_and(|name| name == "EXIT") {
None
} else {
let sig = (sig_num as i32)
.try_into()
.map_err(|e| std::io::Error::from_raw_os_error(e as i32))?;
Some(sig)
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap as block

Comment on lines +140 to +143
#[cfg(unix)]
let echo = matches.get_flag("echo");
#[cfg(unix)]
kill(&pids, sig, echo);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, or a function

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Jan 9, 2025

fells confusing, the implementation should be correct but the behavior not. could you give some help? @sylvestre @cakebaker

@sylvestre
Copy link
Contributor

the behavior not.

do you have details ?

@Krysztal112233
Copy link
Collaborator

Behavior seems doesn't match

➜  procps git:(pkill) sleep 60&
[2] 529099
➜  procps git:(pkill) cargo run pkill 529099
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/procps pkill 529099`
[2]  + 529099 terminated  sleep 60
➜  procps git:(pkill) sleep 60&
[1] 530352
➜  procps git:(pkill) pkill 530352
➜  procps git:(pkill)

Here's the details

@Krysztal112233 Krysztal112233 merged commit ab6e081 into uutils:main Jan 15, 2025
14 checks passed
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (b2d2737) to head (a48a50e).
Report is 56 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff     @@
##   main   #290   +/-   ##
===========================
===========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants