From 44d253b6c0346319e88287cb14e7e0b2769ccdf9 Mon Sep 17 00:00:00 2001 From: "Jason T. Greene" Date: Wed, 11 May 2022 16:42:18 -0500 Subject: Add support for machine events on Windows Signed-off-by: Jason T. Greene --- cmd/podman/machine/machine.go | 2 +- cmd/podman/machine/machine_unix.go | 12 ++++++++++++ cmd/podman/machine/machine_windows.go | 11 +++++++++++ pkg/util/utils_windows.go | 10 +++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 cmd/podman/machine/machine_unix.go create mode 100644 cmd/podman/machine/machine_windows.go diff --git a/cmd/podman/machine/machine.go b/cmd/podman/machine/machine.go index 553f1ef7a..5a8a06b9d 100644 --- a/cmd/podman/machine/machine.go +++ b/cmd/podman/machine/machine.go @@ -115,7 +115,7 @@ func resolveEventSock() ([]string, error) { return err case info.IsDir(): return nil - case info.Type() != os.ModeSocket: + case !isUnixSocket(info): return nil case !re.MatchString(info.Name()): return nil diff --git a/cmd/podman/machine/machine_unix.go b/cmd/podman/machine/machine_unix.go new file mode 100644 index 000000000..213c24f8c --- /dev/null +++ b/cmd/podman/machine/machine_unix.go @@ -0,0 +1,12 @@ +//go:build linux || ignore || aix || ignore || android || ignore || darwin || ignore || freebsd || ignore || hurd || ignore || illumos || ignore || ios || ignore || netbsd || ignore || openbsd || ignore || solaris +// +build linux ignore aix ignore android ignore darwin ignore freebsd ignore hurd ignore illumos ignore ios ignore netbsd ignore openbsd ignore solaris + +package machine + +import ( + "os" +) + +func isUnixSocket(file os.DirEntry) bool { + return file.Type()&os.ModeSocket != 0 +} diff --git a/cmd/podman/machine/machine_windows.go b/cmd/podman/machine/machine_windows.go new file mode 100644 index 000000000..ffd5d8827 --- /dev/null +++ b/cmd/podman/machine/machine_windows.go @@ -0,0 +1,11 @@ +package machine + +import ( + "os" + "strings" +) + +func isUnixSocket(file os.DirEntry) bool { + // Assume a socket on Windows, since sock mode is not supported yet https://github.com/golang/go/issues/33357 + return !file.Type().IsDir() && strings.HasSuffix(file.Name(), ".sock") +} diff --git a/pkg/util/utils_windows.go b/pkg/util/utils_windows.go index 2732124f2..b91680f7a 100644 --- a/pkg/util/utils_windows.go +++ b/pkg/util/utils_windows.go @@ -4,6 +4,9 @@ package util import ( + "path/filepath" + + "github.com/containers/storage/pkg/homedir" "github.com/pkg/errors" ) @@ -34,7 +37,12 @@ func GetRootlessPauseProcessPidPathGivenDir(unused string) (string, error) { // GetRuntimeDir returns the runtime directory func GetRuntimeDir() (string, error) { - return "", errors.New("this function is not implemented for windows") + data, err := homedir.GetDataHome() + if err != nil { + return "", err + } + runtimeDir := filepath.Join(data, "containers", "podman") + return runtimeDir, nil } // GetRootlessConfigHomeDir returns the config home directory when running as non root -- cgit v1.2.3-54-g00ecf