Skip to content

Unix: scope sighandler_t to GNU/Linux platforms - #5445

Open
chengr4 wants to merge 7 commits into
rust-lang:mainfrom
chengr4:remove-sighandler_t-unix
Open

Unix: scope sighandler_t to GNU/Linux platforms#5445
chengr4 wants to merge 7 commits into
rust-lang:mainfrom
chengr4:remove-sighandler_t-unix

Conversation

@chengr4

@chengr4 chengr4 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

This PR fixes part of #1273 1 and #1359.

Question:
With sighandler_t removed on non-GNU targets, should I also clean up the existing skip rules such asskip_alias("sighandler_t") and rename_type etc. in libc-test/build/main.rs in this PR? (I am worried that I might break the tests. 🫣)


[EDIT 2026-09-03]

sighandler_t is a GNU extension provided by glibc on Linux and Hurd.
Non-GNU Unix platforms 2 do not define sighandler_t in their native C headers (BSDs define sig_t instead).

Previously, sighandler_t was declared in src/unix/mod.rs for all Unix platforms,
causing type mismatches and requiring workarounds in test configurations.

Changes

  1. Scope pub type sighandler_t = size_t; only to GNU/Linux-like platforms (linux_like and hurd).
  2. Remove sighandler_t from non-GNU platforms where it does not exist natively in C headers.
  3. (Fix CI error) Update FreeBSD and Apple test configurations to skip SIG_DFL, SIG_IGN, and SIG_ERR in ctest.

Footnotes

  1. https://github.com/rust-lang/libc/issues/1273#issuecomment-5436574721

  2. BSDs, Solaris, AIX, and Cygwin

@chengr4

chengr4 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

Where does the PR message template go? 🤔

@chengr4
chengr4 force-pushed the remove-sighandler_t-unix branch from 743f5f6 to 2cfc13d Compare September 3, 2026 06:01
@chengr4
chengr4 marked this pull request as ready for review September 3, 2026 06:13
@rustbot

rustbot commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in a solarish module

cc @jclulow, @pfmooney

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are still some tests failing. Could you also update the commit message and PR description to mention this is only on platforms that don't exist? Sounds a bit like unconditional removal as-is.

With sighandler_t removed on non-GNU targets, should I also clean up the existing skip rules such asskip_alias("sighandler_t") and rename_type etc. in libc-test/build/main.rs in this PR? (I am worried that I might break the tests. 🫣)

Yes please! The point is to clean up those tests :)

Basically, ideally, all mentions of sighandler_t should be deleted and then libc is updated as-needed to make things work. We might need a few skips still not nearly as many as are currently there.

View changes since this review

Comment thread src/unix/mod.rs Outdated
Comment on lines +1366 to +1390
#[cfg(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd"
)))]
pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t;
))]
pub fn signal(signum: c_int, handler: sig_t) -> sig_t;

#[cfg(any(
#[cfg(not(any(
target_os = "linux",
target_os = "l4re",
target_os = "android",
target_os = "emscripten",
target_os = "hurd",
target_vendor = "apple",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "openbsd"
))]
pub fn signal(signum: c_int, handler: sig_t) -> sig_t;
)))]
pub fn signal(
signum: c_int,
handler: Option<unsafe extern "C" fn(c_int)>,
) -> Option<unsafe extern "C" fn(c_int)>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This cfg is complex. Delete signal from this file and add it back to each of the child modules, with the correct definition.

@rustbot

rustbot commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@chengr4 chengr4 changed the title unix: remove sighandler_t unix: scope sighandler_t to GNU/Linux platforms Sep 4, 2026
Background:

Refer to `libc-test/build/main.rs`,
sighandler_t` is a GNU extension provided by glibc on Linux and Hurd.
Non-GNU Unix platforms (such as BSDs, Solaris, AIX, and Cygwin) do not define
`sighandler_t` in their native C headers (BSDs define `sig_t` instead).

Fixes:

Scope `sighandler_t` to `linux_like` and `hurd`, removing it from non-GNU platforms.
Since `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` are changed to `size_t` for apple platform,
`ctest` fails on Apple because its C headers define them as function pointers.

Fixes:
- Skip `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` in `test_apple`.
(Follow what other BSDs have already done)
- Remove the obsolete `rename_type` for `sighandler_t`.
@chengr4
chengr4 marked this pull request as draft September 4, 2026 06:44
@chengr4
chengr4 force-pushed the remove-sighandler_t-unix branch from dfcb972 to 36ad7e0 Compare September 4, 2026 06:45
@chengr4 chengr4 changed the title unix: scope sighandler_t to GNU/Linux platforms Unix: scope sighandler_t to GNU/Linux platforms Sep 4, 2026
Since `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` were changed to `size_t` for FreeBSD,
`ctest` failed because C headers define them as function pointer macros.

Fixes:
- Skip `SIG_DFL`, `SIG_IGN`, and `SIG_ERR` in `test_freebsd`.
- Remove obsolete `rename_type` for `sighandler_t`.
@chengr4
chengr4 force-pushed the remove-sighandler_t-unix branch from 36ad7e0 to b7b8c32 Compare September 4, 2026 06:53
Move `signal()` from `src/unix/mod.rs` to child platforms repectively
to reduce the codebase complexity
Since `c_int` is already re-exported in `crate::prelude::*`,
explicitly qualifying it with `crate::` is redundant.
Since `sighandler_t` was scoped to GNU/Linux platforms,
several test configs and semver files became obsolete.

- Remove `skip_alias` and `rename_type` for `sighandler_t` across
  non-GNU Unix targets in `libc-test/build/main.rs`.
- Remove obsolete `signal` skips in Solarish, Neutrino, and AIX, where
  `signal` was using `sighandler_t`. => Now using function pointers.
- Update `SIG_DFL`/`SIG_ERR`/`SIG_IGN` comments to clarify they are C
  function pointers mapped to Rust `size_t`.
- Remove `sighandler_t` from `semver/aix.txt`, `semver/nto.txt`, and
  `semver/qnx.txt`.
@chengr4
chengr4 force-pushed the remove-sighandler_t-unix branch from 5c0e174 to 039ddbe Compare September 5, 2026 19:50
@chengr4
chengr4 marked this pull request as ready for review September 5, 2026 19:55
@rustbot

rustbot commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in a NetBSD-like module

cc @semarie

Some changes occurred in an OpenBSD module

cc @semarie

@chengr4

chengr4 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

Note: Honestly, I didn't go through <signal.h> on all Unix platforms to carefully check my fix; I only randomly and roughly picked a few platforms to read.

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Skimming this it looks plausable, but could you scope only to removing sighandler_t on unsupported platforms? Currently it does that but also changes the signatures to take Option<unsafe extern "C" fn(c_int)> while the actual 1:1 substitute is size_t. That is something we want and we can't remove all test skips until that happens, but it would be better in a separate PR.

@dybucc could you review this as well since you've been working in the area?

View changes since this review

Comment thread src/unix/mod.rs
Comment on lines +252 to +268
cfg_if! {
if #[cfg(any(
target_os = "linux",
target_os = "l4re",
target_os = "android",
target_os = "emscripten",
target_os = "hurd"
))] {
pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
pub const SIG_IGN: sighandler_t = 1 as sighandler_t;
pub const SIG_ERR: sighandler_t = !0 as sighandler_t;
} else {
pub const SIG_DFL: size_t = 0;
pub const SIG_IGN: size_t = 1;
pub const SIG_ERR: size_t = !0;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These should be split across platfoms too

pub type useconds_t = u32;
pub type key_t = c_int;
pub type id_t = c_uint;
pub type sighandler_t = size_t;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this actually available on all linux-like platforms? I.e. emscripten, linux, android, l4re

@rustbot

This comment has been minimized.

@tgross35

tgross35 commented Sep 6, 2026

Copy link
Copy Markdown
Member

Actually could you make this PR just split the definitions up and deprecate sighandler_t on unsupported platforms, then actually remove them in a separate PR? That way we can backport the deprecations.

Also, no AI when communicating with humans please. That includes commit messages and PR descriptions. (This needs a squash anyway)

Sorry for the conflict, I cleaned up the crate::c_* in a separate commit since it's unrelated to this and I noticed a few other cases 4e4a96a.

@rustbot

rustbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

rustbot commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/libc.git main
    $ git push --force-with-lease
    

@chengr4

chengr4 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Also, no AI when communicating with humans please. That includes commit messages and PR descriptions. (This needs a squash anyway)

I use AI as a drafting tool for my commit messages and PR templates because English is not my first language. However, every single word is reviewed, judged, and intentionally chosen by me. I never copy-paste AI output without double-checking. Every sentence in PRs or commit messages is I believe it can help with code review and git history tracing.

Could you point out specifically where you feel it is over-expressed? E.g., which paragraphs you think are unnecessary

I am open to any suggestions for improvement.

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.

3 participants