From d2de9754cf3de6780e447f63fc0985e42bd790d1 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 27 Feb 2025 09:40:59 -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. --- Sources/Foundation/Process.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index 8e864ccb70..5ebcbd5123 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)))