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

kill: fix the fail to use only least significant bits to identify signal with -l #7225

Merged
merged 6 commits into from
Jan 28, 2025

Conversation

Felle33
Copy link
Contributor

@Felle33 Felle33 commented Jan 26, 2025

This pull request solves the issue number #7218.
Fixes #7218

@Felle33
Copy link
Contributor Author

Felle33 commented Jan 26, 2025

With this pull request the tests/misc/kill.sh passes. Should I modify some file or is it just fine as it is?

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/kill is no longer failing!

@@ -164,13 +164,19 @@ fn table() {
}

fn print_signal(signal_name_or_value: &str) -> UResult<()> {
let lower_5_bits = |x: usize| x & 0b11111;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document this magic number :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is not entirely correct, because it recognizes, for example, 111 (= b1101111) as a TERM signal whereas GNU kill doesn't recognize it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you are right. I have done some tests and the range of number accepted goes from 0 to 64 and from 128 to 192 (both endings included). It is like they are managing the same signals but mapped 2 times.
I noticed also that we don't manage the name of the signals from 32 to 64 (and therefore also from 160 to 192).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could add this feature in this pull request or should I open a new one?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would create a new PR. There is also a ticket for it: #6218

@sylvestre
Copy link
Contributor

With this pull request the tests/misc/kill.sh passes. Should I modify some file or is it just fine as it is?

You can update utils/why-error.md but no worries if you don't

.arg("-l")
.arg("143")
.succeeds()
.stdout_matches(&Regex::new("TERM").unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

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

While this works, I think using a regex is a bit overkill and you can simplify it by using either stdout_is or stdout_contains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, I have just seen the function stdout_only, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's also fine.

@Felle33
Copy link
Contributor Author

Felle33 commented Jan 27, 2025

I tried to come up with a solution, take for example the signal EXIT (0):
with some tests, I noticed that it appears when the argument is 0 128 256 512 768 1024 and so on; it is repeated with a mod 128.
For this reason, we should only check only the low 7 bits

@cakebaker
Copy link
Contributor

I think you are close :) It looks like it's mod 256 for numbers >= 256 and not mod 128:

$ ../gnu/src/kill -l $(seq 0 128 2560)
EXIT
EXIT
EXIT
kill: ‘384’: invalid signal
EXIT
kill: ‘640’: invalid signal
EXIT
kill: ‘896’: invalid signal
EXIT
kill: ‘1152’: invalid signal
EXIT
kill: ‘1408’: invalid signal
EXIT
kill: ‘1664’: invalid signal
EXIT
kill: ‘1920’: invalid signal
EXIT
kill: ‘2176’: invalid signal
EXIT
kill: ‘2432’: invalid signal
EXIT

@sylvestre
Copy link
Contributor

is it a bug or a feature ?

@cakebaker
Copy link
Contributor

@sylvestre I think it's a feature. This is the relevant part of the corresponding GNU kill test:

# Verify we only consider the lower "signal" bits,
# to support ksh which just adds 256 to the signal value
STD_TERM_STATUS=$(expr "$SIGTERM" + 128)
KSH_TERM_STATUS=$(expr "$SIGTERM" + 256)
test $(env kill -l $STD_TERM_STATUS $KSH_TERM_STATUS | uniq) = TERM || fail=1

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/kill is no longer failing!

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/misc/usage_vs_getopt (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/misc/kill is no longer failing!
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit 1595b6a into uutils:main Jan 28, 2025
65 checks passed
@cakebaker
Copy link
Contributor

Congrats! The gnu test tests/misc/kill is no longer failing!

Well done and thanks :)

@Felle33 Felle33 deleted the kill_issue branch January 28, 2025 11:22
@Felle33
Copy link
Contributor Author

Felle33 commented Jan 28, 2025

Thanks for your patience...it was a journey :)

@sylvestre
Copy link
Contributor

only two days, kudos :)

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.

kill: fails to use only least significant bits to identify signal with -l
3 participants