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

Creating proper type for sighandler_t using anonymous union on Unix #2107

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

landhb
Copy link

@landhb landhb commented Mar 11, 2021

Resolves #1359

This PR allows you to use the sigaction struct on Unix properly. For instance you'll be able to create a new sigaction struct passing all three types of handlers, below demonstrates both the creation of a handler of type void (*sa_handler)(int) and for SIG_IGN which is a const size_t:

extern "C" fn signal_handler(signal: i32) {todo!()}

let mut act = libc::sigaction {
    sa_sigaction: libc::sighandler_t {
        sa_handler: Some(signal_handler),
    },
    sa_mask: newmask,
    sa_flags: 0,
    sa_restorer: None,
};

// Demonstrating use of SIG_IGN constant 
let _ignore_action = libc::sigaction {
    sa_sigaction: libc::SIG_IGN,
    sa_mask: newmask,
    sa_flags: 0,
    sa_restorer: None,
};

unsafe {
    libc::sigaction(libc::SIGUSR1, &mut act, core::ptr::null_mut());
}

@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 @JohnTitor (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.

@landhb
Copy link
Author

landhb commented Mar 11, 2021

Working on fixing the test suite errors.

@landhb
Copy link
Author

landhb commented Mar 11, 2021

All checks are passing now.

Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
But this should be a breaking change and I'd hold off unless it's a serious issue.

src/unix/mod.rs Outdated
Comment on lines 1728 to 1749
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for __c_anonymous_sigaction_handler {
fn eq(&self, other: &__c_anonymous_sigaction_handler) -> bool {
unsafe { self.default == other.default }
}
}
impl Eq for __c_anonymous_sigaction_handler {}
impl ::fmt::Debug for __c_anonymous_sigaction_handler {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("sigaction_t")
.field("value", unsafe { &self.default } )
.finish()
}
}
impl ::hash::Hash for __c_anonymous_sigaction_handler {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
unsafe { self.default.hash(state) };
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this before the consts declaration?

Copy link
Author

Choose a reason for hiding this comment

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

Yep! Moved in 6913b31. Let me know if that's where you meant.

@@ -27,7 +27,7 @@ pub type uid_t = u32;
pub type gid_t = u32;
pub type in_addr_t = u32;
pub type in_port_t = u16;
pub type sighandler_t = ::size_t;
pub type sighandler_t = __c_anonymous_sigaction_handler;
Copy link
Member

Choose a reason for hiding this comment

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

Is the current type wrong on all the UNIX platforms?

Copy link
Author

Choose a reason for hiding this comment

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

@JohnTitor
Copy link
Member

Also cc @Amanieu as I'm unfamiliar with this.

@Amanieu
Copy link
Member

Amanieu commented Mar 13, 2021

The new version is more correct but I'm afraid it will be a significant breaking change so we should hold off on it until the next major release.

@bors
Copy link
Contributor

bors commented Dec 20, 2022

☔ The latest upstream changes (presumably #3038) made this pull request unmergeable. Please resolve the merge conflicts.

@safinaskar
Copy link

@landhb , breaking release of libc will be released soon. So, consider to continue this work

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

Successfully merging this pull request may close these issues.

sighandler_t has an incorrect type on most unix targets
6 participants