native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #239 from onevcat/fix/cli-socket-tmp-cleanup

fix(cli): move socket out of tmp to survive macOS cleanup

authored by

Wei Wang and committed by
GitHub
a4c04ee2 d837c3e2

+23 -1
+7
supacode/CLIService/CLISocketServer.swift
··· 24 24 25 25 /// Start listening for CLI connections. 26 26 func start() throws { 27 + // Ensure parent directory exists (e.g. ~/Library/Application Support/com.onevcat.prowl) 28 + let parentDir = (socketPath as NSString).deletingLastPathComponent 29 + try? FileManager.default.createDirectory( 30 + atPath: parentDir, 31 + withIntermediateDirectories: true 32 + ) 33 + 27 34 // Clean up stale socket file 28 35 unlink(socketPath) 29 36
+16 -1
supacode/CLIService/Shared/SocketConstants.swift
··· 16 16 public static let cliOpenPathArgument = "--prowl-cli-open-path" 17 17 18 18 /// Default Unix domain socket path. 19 - /// Located in user's temporary directory to avoid permission issues. 19 + /// 20 + /// Located under `~/Library/Application Support/com.onevcat.prowl/` because macOS periodically 21 + /// sweeps `/var/folders/.../T/` (NSTemporaryDirectory) and removes the socket file out from 22 + /// under a long-running app, leaving a bound FD with no path entry — connect() then fails with 23 + /// ENOENT and the CLI mistakenly reports `APP_NOT_RUNNING`. 20 24 /// 21 25 /// If `PROWL_CLI_SOCKET` is set and not empty, it takes precedence. 26 + /// Falls back to NSTemporaryDirectory if the preferred path would exceed the AF_UNIX limit. 22 27 public static var defaultPath: String { 23 28 if let override = ProcessInfo.processInfo.environment[environmentKey], !override.isEmpty { 24 29 return override 30 + } 31 + let preferred = FileManager.default.homeDirectoryForCurrentUser 32 + .appending(path: "Library", directoryHint: .isDirectory) 33 + .appending(path: "Application Support", directoryHint: .isDirectory) 34 + .appending(path: "com.onevcat.prowl", directoryHint: .isDirectory) 35 + .appending(path: "cli.sock", directoryHint: .notDirectory) 36 + .path(percentEncoded: false) 37 + // sockaddr_un.sun_path is 104 bytes on Darwin (including NUL terminator). 38 + if preferred.utf8.count < 104 { 39 + return preferred 25 40 } 26 41 let tmpDir = NSTemporaryDirectory() 27 42 return (tmpDir as NSString).appendingPathComponent("prowl-cli.sock")