Skip to content

Commit

Permalink
Use different socket paths for different users
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Aug 11, 2024
1 parent 6f3f045 commit 5861e85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/AppBundle/server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Common
func startServer() {
let socket = Result { try Socket.create(family: .unix, type: .stream, proto: .unix) }
.getOrThrow("Can't create socket ")
let socketFile = "/tmp/\(Bundle.appId).sock"
let socketFile = "/tmp/\(Bundle.appId)-\(unixUserName).sock"
Result { try socket.listen(on: socketFile) }.getOrThrow("Can't listen to socket \(socketFile) ")
DispatchQueue.global().async {
while true {
Expand All @@ -21,7 +21,7 @@ func sendCommandToReleaseServer(args: [String]) {
defer {
socket.close()
}
let socketFile = "/tmp/bobko.aerospace.sock"
let socketFile = "/tmp/bobko.aerospace-\(unixUserName).sock"
if (try? socket.connect(to: socketFile)) == nil { // Can't connect, AeroSpace.app is not running
return
}
Expand Down
7 changes: 5 additions & 2 deletions Sources/Cli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ func run(_ args: [String], stdin: String) -> ServerAnswer {
Result { try socket.read(into: &answer) }.getOrThrow()
return Result { try JSONDecoder().decode(ServerAnswer.self, from: answer) }.getOrThrow()
}
let socketFile = "/tmp/\(appId).sock"
let socketFile = "/tmp/\(appId)-\(unixUserName).sock"
let socketFileCompat = "/tmp/\(appId).sock" // Compatibility. Drop after a few versions

if let e: Error = Result(catching: { try socket.connect(to: socketFile) }).errorOrNil {
if let e: Error = Result(catching: { try socket.connect(to: socketFile) })
.flatMapError({ _ in Result(catching: { try socket.connect(to: socketFileCompat) }) })
.errorOrNil {
if isVersion {
printVersionAndExit(serverVersion: nil)
} else {
Expand Down
1 change: 1 addition & 0 deletions Sources/Common/util/commonUtil.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import AppKit

public let unixUserName = NSUserName()
public let mainModeId = "main"
private var recursionDetectorDuringFailure: Bool = false

Expand Down

0 comments on commit 5861e85

Please sign in to comment.