-
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. 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. That So I just about always just drop a (As for asynchronous, it's a blocking operation in userland but it can't fail to make forward progress in this case because there's no network I/O involved unless we're doing something really wonky.) 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. We've had this discussion in another place (here?). We ended up not calling But it does seem like a design people are going to reach for repeatedly. I wonder if we can put our thought process down somewhere. 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.
I agree that it is a weirdness; nevertheless, we need to handle it and most likely surface it to the user. We shouldn't just swallow those errors.
This is not entirely true. If you are using io_uring you can asynchronously listen for the subprocess termination with The only pattern that keeps us flexible is a |
||
/// 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.