Skip to content

fix InterruptHandler to be safer #249

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

Merged
merged 1 commit into from
Oct 22, 2021
Merged

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Oct 20, 2021

motivation: InterruptHandler can crash when signal is handled but globals are not initialized

changes:

  • mark InterruptHandler as deprecated since DispatchSource provides this functionality already
  • change InterruptHandler globals to static members
  • add code to ensure the static state is initialized to make it more signal safe

rdar://76272674

motivation: InterruptHandler can crash when signal is handled by globals are not initialized

changes:
* mark InterruptHandler as deprecated since DispatchSource provides this functionality already
* change InterruptHandler globals to static members
* add code to ensure the static state is initialized to make it more signal safe
@tomerd
Copy link
Contributor Author

tomerd commented Oct 20, 2021

thanks @CodaFi for diagnosing this

@tomerd
Copy link
Contributor Author

tomerd commented Oct 20, 2021

@swift-ci please test

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Thank you!

/// This class can be used by command line tools to install a handler which
/// should be called when a interrupt signal is delivered to the process.
@available(*, deprecated, message: "use DispatchSource instead")
Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

#if os(Windows)
private static var signalWatchingPipe: [HANDLE] = [INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE]
#else
private static var signalWatchingPipe: [Int32] = [0, 0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably better to use a tuple for this one and the windows one but meh that's really not important.

@compnerd
Copy link
Member

This breaks the windows build :-(

compnerd added a commit to compnerd/swift-tools-support-core that referenced this pull request Oct 22, 2021
tomerd pushed a commit that referenced this pull request Oct 23, 2021
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.

4 participants