Skip to content

Commit

Permalink
client/connection: Add support for the socket existing in /run/incus
Browse files Browse the repository at this point in the history
Transient sockets are supposed to be in /run rather than /var, so make
it possible to detect that automatically when used.

Signed-off-by: Neal Gompa <[email protected]>
  • Loading branch information
Conan-Kudo authored and stgraber committed May 4, 2024
1 parent 974df22 commit 7017014
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions client/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func ConnectIncusHTTPWithContext(ctx context.Context, args *ConnectionArgs, clie
//
// If the path argument is empty, then $INCUS_SOCKET will be used, if
// unset $INCUS_DIR/unix.socket will be used and if that one isn't set
// either, then the path will default to /var/lib/incus/unix.socket.
// either, then the path will default to /var/lib/incus/unix.socket or /run/incus/unix.socket.
func ConnectIncusUnix(path string, args *ConnectionArgs) (InstanceServer, error) {
return ConnectIncusUnixWithContext(context.Background(), path, args)
}
Expand All @@ -157,7 +157,7 @@ func ConnectIncusUnix(path string, args *ConnectionArgs) (InstanceServer, error)
//
// If the path argument is empty, then $INCUS_SOCKET will be used, if
// unset $INCUS_DIR/unix.socket will be used and if that one isn't set
// either, then the path will default to /var/lib/incus/unix.socket.
// either, then the path will default to /var/lib/incus/unix.socket or /run/incus/unix.socket.
func ConnectIncusUnixWithContext(ctx context.Context, path string, args *ConnectionArgs) (InstanceServer, error) {
logger.Debug("Connecting to a local Incus over a Unix socket")

Expand All @@ -180,7 +180,11 @@ func ConnectIncusUnixWithContext(ctx context.Context, path string, args *Connect
if path == "" {
incusDir := os.Getenv("INCUS_DIR")
if incusDir == "" {
incusDir = "/var/lib/incus"
if util.PathExists("/run/incus/unix.socket") {
incusDir = "/run/incus"
} else {
incusDir = "/var/lib/incus"
}
}

path = filepath.Join(incusDir, "unix.socket")
Expand Down

0 comments on commit 7017014

Please sign in to comment.