11package crt
22
33import (
4+ "net"
5+ "time"
6+
7+ log "github.com/sirupsen/logrus"
8+
49 "os"
510 "strings"
611
@@ -81,7 +86,9 @@ func AvailableRuntimes() []string {
8186
8287 if strings .HasPrefix (info .Socket , "/" ) {
8388 if HasSocket (info .Socket ) {
84- usable [info .Name ] = struct {}{}
89+ if CanConnect (info .Socket ) {
90+ usable [info .Name ] = struct {}{}
91+ }
8592 }
8693 } else {
8794 //adding remote paths (for podman and others; without checking, for now)
@@ -106,11 +113,12 @@ func AvailableRuntimes() []string {
106113
107114func AutoSelectRuntime () string {
108115 available := AvailableRuntimes ()
116+ log .Debugf ("Available runtimes: %v" , available )
109117 if len (available ) > 0 {
110118 return available [0 ]
111119 }
112120
113- return DockerRuntime
121+ return DockerRuntime // Question -> This runtime may not necessarily be available?
114122}
115123
116124func HasSocket (name string ) bool {
@@ -121,3 +129,18 @@ func HasSocket(name string) bool {
121129
122130 return false
123131}
132+
133+ func CanConnect (socket string ) bool {
134+ timeout := 5 * time .Second
135+ conn , err := net .DialTimeout ("unix" , socket , timeout )
136+
137+ if err != nil {
138+ // If there are permission issues, this line will be tripped
139+ // when trying to connect to the socket.
140+ log .Debugf ("Error connecting to socket: %s: %v" , socket , err )
141+ return false
142+ }
143+ defer conn .Close ()
144+
145+ return true
146+ }
0 commit comments