Skip to content

The libc::sigaction struct doesn't contain any way to access the underlying sa_handler field. #3111

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

Open
dead-claudia opened this issue Feb 9, 2023 · 4 comments
Labels
breakage-candidate C-bug Category: bug E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Milestone

Comments

@dead-claudia
Copy link

Per https://pubs.opengroup.org/onlinepubs/007904875/functions/sigaction.html and https://man7.org/linux/man-pages/man2/sigaction.2.html, there's an sa_handler field for the sigaction struct. On Linux with some architectures, it may be aliased to sa_sigaction, but it's always there.

This is required in order to know what the previous signal handler was, and more importantly, whether it was previously ignored (.sa_handler == SIG_IGN) or set to the default disposition (.sa_handler == SIG_DFL).

Also, this allows omitting the SA_SIGINFO property of sa_flags, offering a simpler API for most common cases as it's just one (commonly-ignored) argument, not three.

@tgross35
Copy link
Contributor

What platforms is this missing on? From a quick breeze, all of our (too many) struct sigactions seem to have sa_sigaction.

A PR is welcome here as needed.

@tgross35 tgross35 added this to the 1.0 milestone Aug 29, 2024
@tgross35 tgross35 added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Aug 29, 2024
@dead-claudia
Copy link
Author

dead-claudia commented Aug 30, 2024

I've not done an exhaustive check, but I have run into it in x86-64.

Edit: to be clear, the problem isn't that sa_sigaction is missing, but that sa_handler is.

@highjeans
Copy link

Would you happen to know which platforms require the struct to have sa_sigaction and which ones require sa_handler?

@dead-claudia
Copy link
Author

@highjeans Both fields are required in all Unix-like systems per POSIX spec. The spec just allows systems to place the fields in overlapping memory if it so chooses (and turns out, everyone does exactly that in practice).

Specifically, sa_sigaction is to be used for void handler(int sig, siginfo_t *info, void *ucontext) callbacks, while sa_handler is to be used for void handler(int sig) callbacks. It's an either-or, and applications are not to attempt to set both handlers on a single struct. (This is why a union is possible.)

Here's a line-by-line of all supported platforms with a sigaction struct:


@tgross35 From a quick search, here's the platforms sa_handler is defined on:

Conversely, here's the platforms sa_sigaction is defined on:

Hopefully, this can help you figure out what needs what.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breakage-candidate C-bug Category: bug E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants