Skip to content

Commit c6dc97f

Browse files
authored
Merge pull request #26 from jakepetroules/fix-musl
Fix build error with static Linux SDK (Musl libc)
2 parents 8c9110b + 3a20e41 commit c6dc97f

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

Sources/Subprocess/Platforms/Subprocess+Linux.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ private let _childProcessContinuations:
257257

258258
private let signalSource: SendableSourceSignal = SendableSourceSignal()
259259

260+
private extension siginfo_t {
261+
var si_status: Int32 {
262+
#if canImport(Glibc)
263+
return _sifields._sigchld.si_status
264+
#elseif canImport(Musl)
265+
return __si_fields.__si_common.__second.__sigchld.si_status
266+
#endif
267+
}
268+
269+
var si_pid: pid_t {
270+
#if canImport(Glibc)
271+
return _sifields._sigchld.si_pid
272+
#elseif canImport(Musl)
273+
return __si_fields.__si_common.__first.__piduid.si_pid
274+
#endif
275+
}
276+
}
277+
260278
private let setup: () = {
261279
signalSource.setEventHandler {
262280
_childProcessContinuations.withLock { continuations in
@@ -268,9 +286,9 @@ private let setup: () = {
268286
var status: TerminationStatus? = nil
269287
switch siginfo.si_code {
270288
case .init(CLD_EXITED):
271-
status = .exited(siginfo._sifields._sigchld.si_status)
289+
status = .exited(siginfo.si_status)
272290
case .init(CLD_KILLED), .init(CLD_DUMPED):
273-
status = .unhandledException(siginfo._sifields._sigchld.si_status)
291+
status = .unhandledException(siginfo.si_status)
274292
case .init(CLD_TRAPPED), .init(CLD_STOPPED), .init(CLD_CONTINUED):
275293
// Ignore these signals because they are not related to
276294
// process exiting
@@ -279,7 +297,7 @@ private let setup: () = {
279297
fatalError("Unexpected exit status: \(siginfo.si_code)")
280298
}
281299
if let status = status {
282-
let pid = siginfo._sifields._sigchld.si_pid
300+
let pid = siginfo.si_pid
283301
if let existing = continuations.removeValue(forKey: pid),
284302
case .continuation(let c) = existing
285303
{

Sources/_SubprocessCShims/process_shims.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ int _subprocess_spawn(
251251

252252
// MARK: - Linux (fork/exec + posix_spawn fallback)
253253
#if TARGET_OS_LINUX
254+
#ifndef __GLIBC_PREREQ
255+
#define __GLIBC_PREREQ(maj, min) 0
256+
#endif
254257

255258
#if _POSIX_SPAWN
256259
static int _subprocess_is_addchdir_np_available() {

0 commit comments

Comments
 (0)