aboutsummaryrefslogtreecommitdiff
path: root/pkg/machine/qemu/claim_darwin.go
blob: 66aed9ad88b3f79b7f3003b30f8b69fdf0f22ea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package qemu

import (
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"os/user"
	"path/filepath"
	"time"
)

func dockerClaimSupported() bool {
	return true
}

func dockerClaimHelperInstalled() bool {
	u, err := user.Current()
	if err != nil {
		return false
	}

	labelName := fmt.Sprintf("com.github.containers.podman.helper-%s", u.Username)
	fileName := filepath.Join("/Library", "LaunchDaemons", labelName+".plist")
	info, err := os.Stat(fileName)
	return err == nil && info.Mode().IsRegular()
}

func claimDockerSock() bool {
	u, err := user.Current()
	if err != nil {
		return false
	}

	helperSock := fmt.Sprintf("/var/run/podman-helper-%s.socket", u.Username)
	con, err := net.DialTimeout("unix", helperSock, time.Second*5)
	if err != nil {
		return false
	}
	_ = con.SetWriteDeadline(time.Now().Add(time.Second * 5))
	_, err = fmt.Fprintln(con, "GO")
	if err != nil {
		return false
	}
	_ = con.SetReadDeadline(time.Now().Add(time.Second * 5))
	read, err := ioutil.ReadAll(con)

	return err == nil && string(read) == "OK"
}

func findClaimHelper() string {
	exe, err := os.Executable()
	if err != nil {
		return ""
	}

	exe, err = filepath.EvalSymlinks(exe)
	if err != nil {
		return ""
	}

	return filepath.Join(filepath.Dir(exe), "podman-mac-helper")
}