Skip to content
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

[6.0.x] Add a thread-safe implementation of Process.currentDirectoryURL #5096

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

jakepetroules
Copy link
Contributor

posix_spawn_file_actions_addchdir_np is the official way to set the working directory of a spawned process and is supported on both macOS and glibc (Linux, etc.). This makes Process.currentDirectoryURL thread-safe, as the current approach will result in the working directory being nondeterministically assigned when spawning processes across multiple threads, using different working directories.

This already landed in main via #4981 (and amendment in #5090) and it's pretty disruptive for us so I'd like to get it into 6.0.x if possible.

posix_spawn_file_actions_addchdir_np is the official way to set the working directory of a spawned process and is supported on both macOS and glibc (Linux, etc.). This makes Process.currentDirectoryURL thread-safe, as the current approach will result in the working directory being nondeterministically assigned when spawning processes across multiple threads, using different working directories.
Swift still needs to support Amazon Linux 2 until it EoLs in mid-2025. So restore the thread-unsafe fallback for systems with glibc older than version 2.29, which was removed in #4981.
@jakepetroules jakepetroules changed the base branch from main to release/6.0 October 2, 2024 23:54
@jakepetroules
Copy link
Contributor Author

@swift-ci please test linux

@jakepetroules
Copy link
Contributor Author

@swift-ci please test windows

@jakepetroules
Copy link
Contributor Author

Also opened #5095 for release/6.0.2 to ensure this makes it into 6.0.2

@jakepetroules jakepetroules requested a review from parkera October 3, 2024 00:00
@jakepetroules jakepetroules merged commit cc817e4 into release/6.0 Oct 25, 2024
2 checks passed
@jakepetroules jakepetroules deleted the process-working-directory-thread-safe2 branch October 25, 2024 22:12
@aschwaighofer
Copy link
Contributor

@jakepetroules This appears to have broken this bot: https://ci.swift.org/job/oss-swift-6.0-package-static-sdk/78/

@parkera
Copy link
Contributor

parkera commented Oct 28, 2024

/home/build-user/source/swift-project/swift-corelibs-foundation/Sources/CoreFoundation/CFPlatform.c:2302:10: error: call to undeclared function 'posix_spawn_file_actions_addchdir'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
 2302 |   return posix_spawn_file_actions_addchdir((posix_spawn_file_actions_t *)file_actions, path);
      |          ^
/home/build-user/source/swift-project/swift-corelibs-foundation/Sources/CoreFoundation/CFPlatform.c:2302:10: note: did you mean 'posix_spawn_file_actions_addchdir_np'?
/home/build-user/build/sdk_root/x86_64/usr/include/spawn.h:74:5: note: 'posix_spawn_file_actions_addchdir_np' declared here
   74 | int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *__restrict, const char *__restrict);
      |     ^
1 error generated.

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.

3 participants