Skip to content

Commit d2de975

Browse files
committed
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.
1 parent 9dd8777 commit d2de975

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/Foundation/Process.swift

+6
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,12 @@ open class Process: NSObject, @unchecked Sendable {
944944
var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t()
945945
#endif
946946
try _throwIfPosixError(posix_spawnattr_init(&spawnAttrs))
947+
#if os(Android)
948+
guard var spawnAttrs else {
949+
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno),
950+
userInfo: [NSURLErrorKey:self.executableURL!])
951+
}
952+
#endif
947953
try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_SETPGROUP)))
948954
#if canImport(Darwin)
949955
try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_CLOEXEC_DEFAULT)))

0 commit comments

Comments
 (0)