From 6d3320328d33d868f4ec6c0cb42c7a1e498855b6 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Wed, 5 Mar 2025 14:19:54 -0800 Subject: [PATCH] Process: unwrap the posix_spawnattr_t on Android This is required as while `posix_spawnattr_init` permits a nullable type, `posix_spawnattr_setflags` properly expects a non-null parameter. Unwrap the newly minted spawnattr or abort if the allocation failed. Cherry pick commit https://github.com/swiftlang/swift-corelibs-foundation/pull/5179 --- Sources/Foundation/Process.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index 07b9be12fd..6baa2e2c0e 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -944,6 +944,12 @@ open class Process: NSObject, @unchecked Sendable { var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t() #endif try _throwIfPosixError(posix_spawnattr_init(&spawnAttrs)) +#if os(Android) + guard var spawnAttrs else { + throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), + userInfo: [NSURLErrorKey:self.executableURL!]) + } +#endif try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_SETPGROUP))) #if canImport(Darwin) try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_CLOEXEC_DEFAULT)))