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

Implement safe bindings around pthread_sigqueue. #1798

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

pirocks
Copy link

@pirocks pirocks commented Aug 17, 2022

I had a usecase for pthread_sigqueue so I added it to nix.
Implementation is pretty much the same as pthread_kill.
Requires a libc version bump.

@pirocks pirocks marked this pull request as draft August 17, 2022 05:25
@pirocks pirocks force-pushed the master branch 5 times, most recently from 525eca9 to 070abb9 Compare August 17, 2022 05:42
@pirocks pirocks marked this pull request as ready for review August 17, 2022 13:51
@pirocks
Copy link
Author

pirocks commented Aug 18, 2022

No idea how review requests here, but other people seem to request reviews from @rtzoeller. This should be good to go for review.

@@ -65,5 +65,5 @@ pub fn test_timerfd_unset() {

timer.unset().unwrap();

assert!(timer.get().unwrap() == None);
Copy link
Member

Choose a reason for hiding this comment

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

This part looks like a merge error. You should revert it.

Copy link
Author

Choose a reason for hiding this comment

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

Removing the commit that does this causes this CI failure: https://github.com/nix-rust/nix/pull/1798/checks?check_run_id=7898677574

Ptr(*mut libc::c_void),
}

// Because of macro/trait machinery in libc, libc doesn't provide this union.
Copy link
Member

Choose a reason for hiding this comment

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

Why not? It's possible to define unions in libc these days. Unless there is a very compelling reason not to, you should submit this as a PR for libc.

Copy link
Author

@pirocks pirocks Aug 18, 2022

Choose a reason for hiding this comment

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

The problem is there already is a sigval in libc and is defined as a struct(which is used in many places since signal handling has several syscalls associated with it). That struct has PartialEq/Hash/Debug etc implemented, and has done so for a long time. There's no practical way to implement PartialEq/Hash/Debug for a union b/c that would lead to hashing/equality checking/printing uninitialized memory. So changing the current struct to a union is a breaking change. (see: rust-lang/libc#2816)

I can add a second definition in libc, but it would have to have a different name. If that's desired I guess reply to this comment. I'll also update that comment with the info in this one.

Copy link
Member

Choose a reason for hiding this comment

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

Have you seen rust-lang/libc#2813 ? It deals with another union that was originally defined as a struct in libc. The solution we came up with there was to define a sigevent_0_2_126 struct identical to the old sigevent, and then define sigevent with union fields as it ought to be. Then implement Deref and DerefMut for sigevent to sigevent_0_2_126 . That way consumers of the old version can still access the fields that should've been in a union. Would something similar work for sigval?

/// `pthread_sigqueue` is a GNU extension and is not available on other libcs
///
/// [`pthread_sigqueue(3)`]: https://man7.org/linux/man-pages/man3/pthread_sigqueue.3.html
#[cfg(all(any(target_os = "linux", target_os = "android"), target_env = "gnu"))]
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify this to

Suggested change
#[cfg(all(any(target_os = "linux", target_os = "android"), target_env = "gnu"))]
#[cfg(target_env = "gnu")]

And likewise in the test

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@pirocks
Copy link
Author

pirocks commented Aug 18, 2022

I'll rebase those review comments once every thread is resolved.

@pirocks pirocks requested a review from asomers August 24, 2022 16:44
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