Skip to content

When checking the status from waitpid on a kill -STOP <child_pid> WIFSIGNALED returns true #472

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

Merged
merged 1 commit into from
Dec 13, 2016

Conversation

BrandonSchaefer
Copy link
Contributor

Currently in WIFSIGNALED rust is doing:
(status & 0x7f) + 1
where status is i32

As defined in /usr/include/x86_64-linux-gnu/bits/waitstatus.h
#define __WIFSIGNALED(status)
(((signed char) (((status) & 0x7f) + 1) >> 1) > 0)

Here is an example of the issue:
http://paste2.org/fXc8BxJ0

Run it, and it'll print the child pid then:
kill -STOP <child_pid>

Expect:
Stopped by signal print statement
Results:
Killed by signal print statement

Using the i32, it wont overflow leaving you with 128 returning true, using the waitstatus define you'll end up with -64 (since it shifts 1 right) which would return false. Though the C version shifts right once not really sure why but theres most likely a reason somewhere.

For the fix, just cast to i8 (signed char pretty much) as the C version is doing.

RUNNING ALL TESTS
PASSED 7356 tests

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Dec 13, 2016

📌 Commit 9f6f374 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Dec 13, 2016

⌛ Testing commit 9f6f374 with merge fb8587d...

bors added a commit that referenced this pull request Dec 13, 2016
When checking the status from waitpid on a kill -STOP <child_pid> WIFSIGNALED returns true

Currently in WIFSIGNALED rust is doing:
(status & 0x7f) + 1
where status is i32

As defined in /usr/include/x86_64-linux-gnu/bits/waitstatus.h
#define __WIFSIGNALED(status) \
  (((signed char) (((status) & 0x7f) + 1) >> 1) > 0)

Here is an example of the issue:
http://paste2.org/fXc8BxJ0

Run it, and it'll print the child pid then:
kill -STOP <child_pid>

Expect:
  Stopped by signal print statement
Results:
  Killed by signal print statement

Using the i32, it wont overflow leaving you with 128 returning true, using the waitstatus define you'll end up with -64 (since it shifts 1 right) which would return false. Though the C version shifts right once not really sure *why* but theres most likely a reason somewhere.

For the fix, just cast to i8 (signed char pretty much) as the C version is doing.

RUNNING ALL TESTS
PASSED 7356 tests
@bors
Copy link
Contributor

bors commented Dec 13, 2016

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing fb8587d to master...

@bors bors merged commit 9f6f374 into rust-lang:master Dec 13, 2016
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.

4 participants