diff --git a/pkg/machine/applehv/stubber.go b/pkg/machine/applehv/stubber.go index 910a3dbbaa..72dd51424c 100644 --- a/pkg/machine/applehv/stubber.go +++ b/pkg/machine/applehv/stubber.go @@ -23,7 +23,6 @@ import ( "github.com/containers/podman/v5/utils" vfConfig "github.com/crc-org/vfkit/pkg/config" "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" ) // applehcMACAddress is a pre-defined mac address that vfkit recognizes @@ -160,7 +159,7 @@ func (a AppleHVStubber) StartVM(mc *vmconfigs.MachineConfig) (func() error, func } // Wait on gvproxy to be running and aware - if err := waitForGvProxy(gvproxySocket); err != nil { + if err := sockets.WaitForSocketWithBackoffs(gvProxyMaxBackoffAttempts, gvProxyWaitBackoff, gvproxySocket.GetPath(), "gvproxy"); err != nil { return nil, nil, err } @@ -321,20 +320,6 @@ func (a AppleHVStubber) VMType() define.VMType { return define.AppleHvVirt } -func waitForGvProxy(gvproxySocket *define.VMFile) error { - backoffWait := gvProxyWaitBackoff - logrus.Debug("checking that gvproxy is running") - for i := 0; i < gvProxyMaxBackoffAttempts; i++ { - err := unix.Access(gvproxySocket.GetPath(), unix.W_OK) - if err == nil { - return nil - } - time.Sleep(backoffWait) - backoffWait *= 2 - } - return fmt.Errorf("unable to connect to gvproxy %q", gvproxySocket.GetPath()) -} - func (a AppleHVStubber) PrepareIgnition(_ *vmconfigs.MachineConfig, _ *ignition.IgnitionBuilder) (*ignition.ReadyUnitOpts, error) { return nil, nil } diff --git a/pkg/machine/sockets/sockets.go b/pkg/machine/sockets/sockets.go index afd6d3a7ae..f77d8fc0f5 100644 --- a/pkg/machine/sockets/sockets.go +++ b/pkg/machine/sockets/sockets.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" "net" + "os" "path/filepath" "time" @@ -94,3 +95,18 @@ func DialSocketWithBackoffsAndProcCheck( } return nil, err } + +// WaitForSocketWithBackoffs attempts to discover listening socket in maxBackoffs attempts +func WaitForSocketWithBackoffs(maxBackoffs int, backoff time.Duration, socketPath string, name string) error { + backoffWait := backoff + logrus.Debugf("checking that %q socket is ready", name) + for i := 0; i < maxBackoffs; i++ { + _, err := os.Stat(socketPath) + if err == nil { + return nil + } + time.Sleep(backoffWait) + backoffWait *= 2 + } + return fmt.Errorf("unable to connect to %q socket at %q", name, socketPath) +}