swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.29k stars 1.14k forks source link

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

Closed jakepetroules closed 1 month ago

jakepetroules commented 1 month ago

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 https://github.com/swiftlang/swift-corelibs-foundation/pull/4981 (and amendment in https://github.com/swiftlang/swift-corelibs-foundation/pull/5090) and it's pretty disruptive for us so I'd like to get it into 6.0.x if possible.

jakepetroules commented 1 month ago

@swift-ci please test linux

jakepetroules commented 1 month ago

@swift-ci please test windows

jakepetroules commented 1 month ago

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

aschwaighofer commented 4 weeks ago

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

parkera commented 4 weeks ago
/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.