Skip to content

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Jun 10, 2025

On FreeBSD, OpenBSD, Android, and Glibc ≥ 2.29, posix_spawn_file_actions_adddup2() automatically clears FD_CLOEXEC if the file descriptors passed to it are equal. Relying on this behaviour eliminates a race condition when spawning child processes. This functionality is standardized in POSIX.1-2024 thanks to Austin Group Defect #411.

Some older Linuxes (Amazon Linux 2 in particular) don't have this functionality, so we do a runtime check of the Glibc version.

This PR is a follow-up to #1145.
Resolves #1140.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

On FreeBSD, OpenBSD, Android, and Glibc ≥ 2.29, `posix_spawn_file_actions_adddup2()` automatically clears `FD_CLOEXEC` if the file descriptors passed to it are equal. Relying on this behaviour eliminates a race condition when spawning child processes.

Some older Linuxes (Amazon Linux 2 in particular) don't have this functionality, so we do a runtime check of the Glibc version.
@grynspan grynspan added this to the Swift 6.x milestone Jun 10, 2025
@grynspan grynspan self-assigned this Jun 10, 2025
@grynspan grynspan added enhancement New feature or request linux 🐧 Linux support (all distros) exit-tests ☠️ Work related to exit tests android 🤖 Android support freebsd 😈 FreeBSD support openbsd 🐡 OpenBSD support labels Jun 10, 2025
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan requested a review from jmschonfeld June 10, 2025 14:26
@grynspan grynspan marked this pull request as ready for review June 10, 2025 14:26
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test Windows

@grynspan
Copy link
Contributor Author

@swift-ci test

@jmschonfeld
Copy link

Confirmed that swift-foundation exit tests still work when running with this branch of swift-testing on Ubuntu 20.04

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test Linux

@grynspan
Copy link
Contributor Author

@swift-ci test

1 similar comment
@grynspan
Copy link
Contributor Author

@swift-ci test

@stmontgomery
Copy link
Contributor

@swift-ci please test

@grynspan grynspan merged commit 3278217 into main Jun 10, 2025
3 checks passed
@grynspan grynspan deleted the jgrynspan/dup2-cloexec branch June 10, 2025 20:18
owenv added a commit to owenv/swift-testing that referenced this pull request Jun 16, 2025
@stmontgomery stmontgomery modified the milestones: Swift 6.x, Swift 6.2 Jun 25, 2025
etcwilde added a commit that referenced this pull request Jul 2, 2025
The FreeBSD builds are currently using the GlibC modulemap to import the
C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in
build failures.

The use of this API was introduced in
#1147
etcwilde added a commit to etcwilde/swift-testing that referenced this pull request Jul 2, 2025
The FreeBSD builds are currently using the GlibC modulemap to import the
C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in
build failures.

The use of this API was introduced in
swiftlang#1147

(cherry picked from commit 79c22ad)

- **Explanation**:
  The FreeBSD builds are currently using the GlibC modulemap to import the
  C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in
  build failures.
- **Scope**: Build failure on platforms using Glibc modulemap that don't
  have GNU extensions. (FreeBSD, OpenBSD)
- **Issues**: swiftlang#1193
- **Original PRs**: swiftlang#1183
- **Risk**: Low risk. Removes use of unavailable API.
- **Testing**: Built swift-testing on FreeBSD and Linux.
- **Reviewers**: @grynspan @3405691582

Fixes: swiftlang#1193
etcwilde added a commit that referenced this pull request Jul 2, 2025
The FreeBSD builds are currently using the GlibC modulemap to import the
C runtimes. FreeBSD does not have `gnu_get_libc_version` resulting in
build failures.

The use of this API was introduced in
#1147

(cherry picked from commit 79c22ad)

- **Explanation**: The FreeBSD builds are currently using the GlibC
modulemap to import the C runtimes. FreeBSD does not have
`gnu_get_libc_version` resulting in build failures.
- **Scope**: Build failure on platforms using Glibc modulemap that don't
have GNU extensions. (FreeBSD, OpenBSD)
- **Issues**: #1193
- **Original PRs**: #1183
- **Risk**: Low risk. Removes use of unavailable API.
- **Testing**: Built swift-testing on FreeBSD and Linux.
- **Reviewers**: @grynspan @3405691582

Fixes: #1193
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android 🤖 Android support enhancement New feature or request exit-tests ☠️ Work related to exit tests freebsd 😈 FreeBSD support linux 🐧 Linux support (all distros) openbsd 🐡 OpenBSD support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exit tests hang indefinitely on Ubuntu 20.04
3 participants