Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/Cacheout/Headless/DaemonMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,17 @@ public actor DaemonMode: StatusSocket.DataSource {
withIntermediateDirectories: true,
attributes: [.posixPermissions: 0o700]
)
try FileManager.default.setAttributes(
[.posixPermissions: 0o700],
ofItemAtPath: config.stateDir.path
)
let fd = config.stateDir.withUnsafeFileSystemRepresentation { pathPtr -> Int32 in
guard let pathPtr = pathPtr else { return -1 }
return open(pathPtr, O_RDONLY | O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC)
}
guard fd >= 0 else {
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), userInfo: nil)
}
defer { close(fd) }
guard fchmod(fd, 0o700) == 0 else {
throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), userInfo: nil)
}
} catch {
logger.error("Failed to create/secure state directory: \(error.localizedDescription, privacy: .public)")
Foundation.exit(1)
Expand Down
Loading