Skip to content

Commit 5861e85

Browse files
committed
Use different socket paths for different users
#370
1 parent 6f3f045 commit 5861e85

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Sources/AppBundle/server.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Common
55
func startServer() {
66
let socket = Result { try Socket.create(family: .unix, type: .stream, proto: .unix) }
77
.getOrThrow("Can't create socket ")
8-
let socketFile = "/tmp/\(Bundle.appId).sock"
8+
let socketFile = "/tmp/\(Bundle.appId)-\(unixUserName).sock"
99
Result { try socket.listen(on: socketFile) }.getOrThrow("Can't listen to socket \(socketFile) ")
1010
DispatchQueue.global().async {
1111
while true {
@@ -21,7 +21,7 @@ func sendCommandToReleaseServer(args: [String]) {
2121
defer {
2222
socket.close()
2323
}
24-
let socketFile = "/tmp/bobko.aerospace.sock"
24+
let socketFile = "/tmp/bobko.aerospace-\(unixUserName).sock"
2525
if (try? socket.connect(to: socketFile)) == nil { // Can't connect, AeroSpace.app is not running
2626
return
2727
}

Sources/Cli/main.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ func run(_ args: [String], stdin: String) -> ServerAnswer {
5858
Result { try socket.read(into: &answer) }.getOrThrow()
5959
return Result { try JSONDecoder().decode(ServerAnswer.self, from: answer) }.getOrThrow()
6060
}
61-
let socketFile = "/tmp/\(appId).sock"
61+
let socketFile = "/tmp/\(appId)-\(unixUserName).sock"
62+
let socketFileCompat = "/tmp/\(appId).sock" // Compatibility. Drop after a few versions
6263

63-
if let e: Error = Result(catching: { try socket.connect(to: socketFile) }).errorOrNil {
64+
if let e: Error = Result(catching: { try socket.connect(to: socketFile) })
65+
.flatMapError({ _ in Result(catching: { try socket.connect(to: socketFileCompat) }) })
66+
.errorOrNil {
6467
if isVersion {
6568
printVersionAndExit(serverVersion: nil)
6669
} else {

Sources/Common/util/commonUtil.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import AppKit
33

4+
public let unixUserName = NSUserName()
45
public let mainModeId = "main"
56
private var recursionDetectorDuringFailure: Bool = false
67

0 commit comments

Comments
 (0)