-
Notifications
You must be signed in to change notification settings - Fork 26
Introduce process file descriptor (pidfd) based process monitoring for Linux #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,26 +477,41 @@ extension Configuration { | |
} | ||
} | ||
|
||
// Special keys used in Error's user dictionary | ||
extension String { | ||
static let debugDescriptionErrorKey = "NSDebugDescription" | ||
// MARK: - ProcessIdentifier | ||
|
||
/// A platform independent identifier for a Subprocess. | ||
public struct ProcessIdentifier: Sendable, Hashable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you make this type move-only and incorporate the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Closing might involve closing FDs right? Which might be an asynchronous and throwing operation. |
||
/// The platform specific process identifier value | ||
public let value: pid_t | ||
|
||
public init(value: pid_t) { | ||
self.value = value | ||
} | ||
|
||
internal func close() { /* No-op on Darwin */ } | ||
} | ||
|
||
extension ProcessIdentifier: CustomStringConvertible, CustomDebugStringConvertible { | ||
public var description: String { "\(self.value)" } | ||
|
||
public var debugDescription: String { "\(self.value)" } | ||
} | ||
|
||
// MARK: - Process Monitoring | ||
@Sendable | ||
internal func monitorProcessTermination( | ||
forExecution execution: Execution | ||
for processIdentifier: ProcessIdentifier | ||
) async throws -> TerminationStatus { | ||
return try await withCheckedThrowingContinuation { continuation in | ||
let source = DispatchSource.makeProcessSource( | ||
identifier: execution.processIdentifier.value, | ||
identifier: processIdentifier.value, | ||
eventMask: [.exit], | ||
queue: .global() | ||
) | ||
source.setEventHandler { | ||
source.cancel() | ||
var siginfo = siginfo_t() | ||
let rc = waitid(P_PID, id_t(execution.processIdentifier.value), &siginfo, WEXITED) | ||
let rc = waitid(P_PID, id_t(processIdentifier.value), &siginfo, WEXITED) | ||
guard rc == 0 else { | ||
continuation.resume( | ||
throwing: SubprocessError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unrelated, but you could delete
consoleBehavior
as well as nothing actually uses it.