Skip to content

Commit

Permalink
Merge pull request #830 from stgraber/main
Browse files Browse the repository at this point in the history
client/connection: Add support for the socket existing in /run/incus
  • Loading branch information
stgraber authored May 4, 2024
2 parents 974df22 + d8b78d5 commit e9ce2c1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 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,12 @@ func ConnectIncusUnixWithContext(ctx context.Context, path string, args *Connect
if path == "" {
incusDir := os.Getenv("INCUS_DIR")
if incusDir == "" {
incusDir = "/var/lib/incus"
_, err := os.Lstat("/run/incus/unix.socket")
if err == nil {
incusDir = "/run/incus"
} else {
incusDir = "/var/lib/incus"
}
}

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

0 comments on commit e9ce2c1

Please sign in to comment.