Skip to content

Conversation

jakepetroules
Copy link
Contributor

For now, we use Dispatch for AsyncIO and process termination monitoring, since BSDs (including macOS) all use kqueue as the Dispatch backend anyways.

This likely also fixes the build on OpenBSD, but I haven't been able to verify that.

Closes #115

@jakepetroules
Copy link
Contributor Author

@3405691582 does this build on OpenBSD?

@3405691582
Copy link
Member

Some of the changes discussed on #115 are still missing, so with just the patch atop HEAD it doesn't build. If I apply those changes, namely those below, it seems to build:

  • Sources/Subprocess/Platforms/Subprocess+Linux.swift needs to expose the extension and these changes
  • Sources/Subprocess/Platforms/Subprocess+Unix.swift: the snprintf shim change
  • Sources/_SubprocessCShims/include/process_shims.h: snprintf shim needs TARGET_OS_UNIX
  • Sources/_SubprocessCShims/process_shims.c: snprintf shim needs TARGET_OS_UNIX
  • Tests/SubprocessTests/ProcessMonitoringTests.swift: testInvalidProcessIdentifier needs an os(OpenBSD); in testDoesNotReapUnrelatedChildProcess the si_status extension doesn't seem to be active and I don't know why at the moment.

I tried to run the tests but ran into some other unrelated issues.

@jakepetroules jakepetroules force-pushed the freebsd branch 6 times, most recently from 920cb71 to fd03cf1 Compare August 22, 2025 10:09
For now, we use Dispatch for AsyncIO and process termination monitoring, since BSDs (including macOS) all use kqueue as the Dispatch backend anyways.

Closes swiftlang#115
@3405691582
Copy link
Member

FYI: Most recent revision builds successfully on OpenBSD!

}

// Save the continuation (before calling epoll_ctl, so we don't miss any data)
_registration.withLock { storage in
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate a bit more on why this change is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's two threads:

  • thread A: thread that calls registerFileDescriptor
  • thread B: monitor loop

With the original code, the following ordering could occur:

  • (thread A) add file descriptor N to epoll
  • (thread B) process event for N
  • (thread B) look up continuation <-- continuation is nil!
  • (thread A) save continuation <-- too late

This change forces the ordering to become:

  • (thread A) save continuation
  • (thread A) add file descriptor N to epoll
  • (thread B) process event for N
  • (thread B) look up continuation <-- continuation cannot be nil

@iCharlesHu
Copy link
Contributor

Thanks for the fix!

@jakepetroules jakepetroules merged commit 15e0df9 into swiftlang:main Aug 26, 2025
39 checks passed
@jakepetroules jakepetroules deleted the freebsd branch August 26, 2025 19:06
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.

OpenBSD / FreeBSD Support for Subprocess

3 participants