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

env: adds --ignore-signal #6377

Merged
merged 20 commits into from
May 23, 2024
Merged

Conversation

Walid-Kh
Copy link
Contributor

@Walid-Kh Walid-Kh commented May 7, 2024

This commit implement #6164.

Copy link

github-actions bot commented May 7, 2024

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 7, 2024

I have fixed styling issues and handled STOP signal and fixed styling issues
but I have no idea how the windows and arm mac test can be passed

@BenWiederhake
Copy link
Collaborator

The windows failures should be gone now, the mac failures are probably known issues #6275 and #6333, so don't worry about them for now.

@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 7, 2024

The windows failures should be gone now, the mac failures are probably known issues #6275 and #6333, so don't worry about them for now.

Thanks I was worried, how's the code I imagine some things should be changed!

Copy link
Collaborator

@BenWiederhake BenWiederhake left a comment

Choose a reason for hiding this comment

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

Hi, welcome to uutils! :D

  • We try to match GNU behavior closely, so please always check what GNU is doing. It's okay to deviate intentionally if GNU does something suboptimally, or when we offer an extension. However, these cases should be intentional.
  • coreutils/uutils is (or will be) used at the heart of the operating system. As such, we strive for high reliability. Part of that is carefully considering each use of unsafe, and having thorough testing. Therefore, please always write a few tests to check the main functionality. Additionally, I outlined a handful of bugs that the PR would introduce in its current state. Please use these examples as starting points for tests.
  • You may also want to take another look at the development and contributing guidelines.

I hope I didn't discourage you. Keep going! :)

src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 8, 2024

I hope I didn't discourage you. Keep going! :)

No not at all, I really appreciate your encouragement, regarding testing I will add tests today and check code coverage today or tomorrow at the latest.
Thanks again for the previous review definitely eye-opening.

@cakebaker cakebaker linked an issue May 8, 2024 that may be closed by this pull request
Copy link
Collaborator

@BenWiederhake BenWiederhake left a comment

Choose a reason for hiding this comment

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

Yup, getting better :)

  • There still are zero tests. I have lost count of all the things that need to be tested, please fix this.
  • Formatting issues and a stray #[cfg(unix)], see CI failures for details. They're there to help you :)
  • Plus some small things, see below

src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
src/uu/env/src/env.rs Outdated Show resolved Hide resolved
@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 14, 2024

Sorry for being late, been pretty busy at uni
I hope everything checks out, regarding testing I think there more to be added but these are the ones that came to my mind.
Also one more thing, GNU's implementation have --ignore-signal without specifying a signal ignore all signals, except those which cannot be ignored kill, stop, this is not implemented yet

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/rm/rm1 (passes in this run but fails in the 'main' branch)

@BenWiederhake
Copy link
Collaborator

Nearly there! :)

  • The tests cover all the interesting cases, great! However, the actual functionality of "ignoring a signal" is not actually tested at all, so if for example you simply remove the call to nix::signal, all tests would still be green even when it's utterly broken. Can you write a test that can detect that problem? I'm not entirely sure how to do that, you might want to look into the Target struct, maybe it helps here.
  • Please rebase. I think it's as simple as writing git rebase -i origin/main (or upstream/main or whatever you called the remote-repo on your checkout). The advantage is that all the "old issues" that currently make CI red will vanish (they are solved on main), so the CI can actually do its job and verify that your code is good. Also, I would like to demonstrate to you how easy and helpful rebasing can be :)

@Walid-Kh
Copy link
Contributor Author

I looked at Target struct and it was quite useful, but I still a bit confused about how the test should be implemented, I wrote this code which behaves as expected should this be refactored in it's own Target struct maybe one that takes in the signals which should be ignored.

fn test_env_arg_ignore_signal_valid_signals() {
    let mut child = new_ucmd!()
        .args(&["--ignore-signal=usr1,int,usr2", "sleep", "25"])
        .run_no_wait();
    let id = child.id();
    child.delay(500);


    Command::new("kill")
        .args(&["-usr1", &format!("{}", id)])
        .spawn()
        .expect("failed to send signal");
    child.delay(100);
    assert_eq!(child.is_alive(), true);

    Command::new("kill")
        .args(&["-usr2", &format!("{}", id)])
        .spawn()
        .expect("failed to send signal");
    child.delay(100);
    assert_eq!(child.is_alive(), true);

    Command::new("kill")
        .args(&["-int", &format!("{}", id)])
        .spawn()
        .expect("failed to send signal");
    child.delay(100);
    assert_eq!(child.is_alive(), true);

    Command::new("kill")
        .args(&["-kill", &format!("{}", id)])
        .spawn()
        .expect("failed to send signal");
    child.delay(100);
    assert_eq!(child.is_alive(), false);
    
}

@BenWiederhake
Copy link
Collaborator

Yes, your approach (call sleep, send a signal, check whether it's still running) seems like a good idea. (At least I can't think of a better way.)

And yes, please refactor it somehow, ideally with a new sleep process for each test/experiment. It's up to you to decide whether that code should live in impl Target { … }, or a function inside tests/by-util/test_env.rs, or somewhere else entirely.

Copy link
Collaborator

@BenWiederhake BenWiederhake left a comment

Choose a reason for hiding this comment

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

LGTM, let's see what the CI says …

@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 21, 2024

I looked at CI and these are the errors

  1. env.rs:117 .as_encoded_bytes()
    • method not found in &OsStr Ubuntu
    • error: current MSRV (Minimum Supported Rust Version) is 1.70.0 but this item is stable since 1.74.0
  2. env.rs:39 Windows: use uucore::signals::signal_by_name_or_value; could not find signals in uucore
    • env.rs:681 let sig: Signal = (sig_value as i32)
    • env.rs:690 fn ignore_signal(sig: Signal) -> UResult<()> Signal not found in this scope
    • env.rs:692 let result = unsafe { signal(sig, SigIgn) }; SigIgn not found in this scope
    • env.rs:119 .map(OsStr::from_bytes) from_bytes function or associated item not found in OsStr
    • env.rs:692 let result = unsafe { signal(sig, SigIgn) }; signal not found in this scope
  3. test_env:809 cspell unknown word SIGSTOP
  4. There is a failing test in test_stat.rs unrelated to env

Potential Fixes
1 and 2 can be solved by replacing as_encoded_bytes with from_bytes and using #[cfg(unix)]
3 By adding SIGSTOP to workspace.wordlist
4 Rebasing?

@Walid-Kh Walid-Kh force-pushed the env-ignore-signal branch 3 times, most recently from 349a5d2 to 11a14e8 Compare May 21, 2024 13:48
@BenWiederhake
Copy link
Collaborator

You're absolutely right, and thanks for fixing it ^^
The test_stat-error is #6419 btw (and the other macOs error is #6275)

In "Potential Fix 2", you removed Windows-support entirely from env. That's fair, Windows doesn't have the same concept, and I don't think there's anything comparable. CI is complaining about a missed opportunity to use #[cfg(unix)] though:

error: field `ignore_signal` is never read
  --> src\uu\env\src/env.rs:58:5
   |
49 | struct Options<'a> {
   |        ------- field in this struct
...
58 |     ignore_signal: Vec<usize>,
   |     ^^^^^^^^^^^^^

I think that will be the last thing. Thanks for sticking with it! :)

@Walid-Kh
Copy link
Contributor Author

Walid-Kh commented May 22, 2024

I think that will be the last thing. Thanks for sticking with it! :)

Thank you for your kind comments and guidance, I had a a lot of fun working on this!

@BenWiederhake
Copy link
Collaborator

LGTM, CI is green, and as far as I can see it tests for (nearly) every possible scenario, except #6353, which is unfixable for now. Excellent! :D

@BenWiederhake BenWiederhake merged commit ebcd86d into uutils:main May 23, 2024
63 of 65 checks passed
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.

env: implement --ignore-signal
3 participants