Skip to content

Commit 13db301

Browse files
committed
Call chdir to change working directory in older versions of glibc
Motivation: `SPM_posix_spawn_file_actions_addchdir_np_supported` and `SPM_posix_spawn_file_actions_addchdir_np` simply return error for glibc versions < 2.29. This causes SwiftPM tools such as `swift package-registry publish` to be unusable on Amazon Linux 2, which has an older version of glibc installed. Modifications: For older versions of glibc, call `chdir` to change working directory as an alternative to `posix_spawn_file_actions_addchdir_np`. This way child process will inherit the working directory path.
1 parent 8732961 commit 13db301

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Sources/TSCclibc/process.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#endif
66

77
#include <errno.h>
8+
#include <unistd.h>
89

910
#include "process.h"
1011

@@ -13,7 +14,8 @@ int SPM_posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restric
1314
# if __GLIBC_PREREQ(2, 29)
1415
return posix_spawn_file_actions_addchdir_np(file_actions, path);
1516
# else
16-
return ENOSYS;
17+
// Change working directory which child process will inherit
18+
return chdir(path);
1719
# endif
1820
#else
1921
return ENOSYS;
@@ -22,11 +24,7 @@ int SPM_posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restric
2224

2325
bool SPM_posix_spawn_file_actions_addchdir_np_supported() {
2426
#if defined(__GLIBC__)
25-
# if __GLIBC_PREREQ(2, 29)
2627
return true;
27-
# else
28-
return false;
29-
# endif
3028
#else
3129
return false;
3230
#endif

0 commit comments

Comments
 (0)