Add more logging.

This commit is contained in:
Max Goedjen 2025-11-16 19:01:10 -08:00
parent 9216a2b931
commit acc1023cb2
No known key found for this signature in database
3 changed files with 16 additions and 4 deletions

View File

@ -120,7 +120,7 @@ extension Agent {
/// Gives any store with no loaded secrets a chance to reload. /// Gives any store with no loaded secrets a chance to reload.
func reloadSecretsIfNeccessary() async { func reloadSecretsIfNeccessary() async {
for store in await storeList.stores { for store in await storeList.stores {
if await store.secrets.isEmpty { if await store.isAvailable, await store.secrets.isEmpty {
let name = await store.name let name = await store.name
logger.debug("Store \(name, privacy: .public) has no loaded secrets. Reloading.") logger.debug("Store \(name, privacy: .public) has no loaded secrets. Reloading.")
await store.reloadSecrets() await store.reloadSecrets()

View File

@ -36,7 +36,7 @@ extension SigningRequestTracer {
/// - Parameter pid: The process ID to look up. /// - Parameter pid: The process ID to look up.
/// - Returns: A ``SecretKit.SigningRequestProvenance.Process`` describing the process. /// - Returns: A ``SecretKit.SigningRequestProvenance.Process`` describing the process.
func process(from pid: Int32) -> SigningRequestProvenance.Process { func process(from pid: Int32) -> SigningRequestProvenance.Process {
var pidAndNameInfo = self.pidAndNameInfo(from: pid) var pidAndNameInfo = unsafe self.pidAndNameInfo(from: pid)
let ppid = unsafe pidAndNameInfo.kp_eproc.e_ppid != 0 ? pidAndNameInfo.kp_eproc.e_ppid : nil let ppid = unsafe pidAndNameInfo.kp_eproc.e_ppid != 0 ? pidAndNameInfo.kp_eproc.e_ppid : nil
let procName = unsafe withUnsafeMutablePointer(to: &pidAndNameInfo.kp_proc.p_comm.0) { pointer in let procName = unsafe withUnsafeMutablePointer(to: &pidAndNameInfo.kp_proc.p_comm.0) { pointer in
unsafe String(cString: pointer) unsafe String(cString: pointer)

View File

@ -37,12 +37,19 @@ public struct SocketController {
port = SocketPort(path: path) port = SocketPort(path: path)
fileHandle = FileHandle(fileDescriptor: port.socket, closeOnDealloc: true) fileHandle = FileHandle(fileDescriptor: port.socket, closeOnDealloc: true)
Task { [fileHandle, sessionsContinuation, logger] in Task { [fileHandle, sessionsContinuation, logger] in
logger.debug("Starting socket controller task")
for await notification in NotificationCenter.default.notifications(named: .NSFileHandleConnectionAccepted) { for await notification in NotificationCenter.default.notifications(named: .NSFileHandleConnectionAccepted) {
logger.debug("Socket controller accepted connection") logger.debug("Socket controller accepted connection")
guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else { continue } guard let new = notification.userInfo?[NSFileHandleNotificationFileHandleItem] as? FileHandle else {
logger.error("FileHandle not present in user info.")
continue
}
let session = Session(fileHandle: new) let session = Session(fileHandle: new)
logger.debug("Yielding session")
sessionsContinuation.yield(session) sessionsContinuation.yield(session)
logger.debug("Yielded session")
await fileHandle.acceptConnectionInBackgroundAndNotifyOnMainActor() await fileHandle.acceptConnectionInBackgroundAndNotifyOnMainActor()
logger.debug("Session waiting for connection.")
} }
} }
fileHandle.acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.Mode.common]) fileHandle.acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.Mode.common])
@ -74,11 +81,15 @@ extension SocketController {
/// Initializes a new Session. /// Initializes a new Session.
/// - Parameter fileHandle: The FileHandle used to communicate with the socket. /// - Parameter fileHandle: The FileHandle used to communicate with the socket.
init(fileHandle: FileHandle) { init(fileHandle: FileHandle) {
logger.debug("Initializing session.")
self.fileHandle = fileHandle self.fileHandle = fileHandle
provenance = SigningRequestTracer().provenance(from: fileHandle) provenance = SigningRequestTracer().provenance(from: fileHandle)
logger.debug("Traced provenance.")
(messages, messagesContinuation) = AsyncStream.makeStream() (messages, messagesContinuation) = AsyncStream.makeStream()
Task { [messagesContinuation, logger] in Task { [messagesContinuation, logger] in
logger.debug("Starting Session task.")
for await _ in NotificationCenter.default.notifications(named: .NSFileHandleDataAvailable, object: fileHandle) { for await _ in NotificationCenter.default.notifications(named: .NSFileHandleDataAvailable, object: fileHandle) {
logger.debug("Session received data avilable message.")
let data = fileHandle.availableData let data = fileHandle.availableData
guard !data.isEmpty else { guard !data.isEmpty else {
logger.debug("Socket controller received empty data, ending continuation.") logger.debug("Socket controller received empty data, ending continuation.")
@ -90,7 +101,8 @@ extension SocketController {
logger.debug("Socket controller yielded data.") logger.debug("Socket controller yielded data.")
} }
} }
Task { Task { [logger] in
logger.debug("Session waiting for data.")
await fileHandle.waitForDataInBackgroundAndNotifyOnMainActor() await fileHandle.waitForDataInBackgroundAndNotifyOnMainActor()
} }
} }