/
util_unix.go
74 lines (61 loc) · 1.59 KB
/
util_unix.go
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
64
65
66
67
68
69
70
71
72
73
74
//go:build !windows
// +build !windows
package workers
import (
"bufio"
"os"
"path/filepath"
"strings"
"syscall"
"github.com/khulnasoft/devkit/util/testutil/integration"
"github.com/pkg/errors"
)
func applyBuildkitdPlatformFlags(args []string) []string {
return append(args, "--oci-worker=false")
}
func requireRoot() error {
if os.Getuid() != 0 {
return errors.Wrap(integration.ErrRequirements, "requires root")
}
return nil
}
func getSysProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{
Setsid: true, // stretch sudo needs this for sigterm
}
}
func getBuildkitdAddr(tmpdir string) string {
return "unix://" + filepath.Join(tmpdir, "devkitd.sock")
}
func getTraceSocketPath(tmpdir string) string {
return filepath.Join(tmpdir, "otel-grpc.sock")
}
func getContainerdSock(tmpdir string) string {
return filepath.Join(tmpdir, "containerd.sock")
}
func getContainerdDebugSock(tmpdir string) string {
return filepath.Join(tmpdir, "debug.sock")
}
func mountInfo(tmpdir string) error {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return errors.Wrap(err, "failed to open mountinfo")
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
if strings.Contains(s.Text(), tmpdir) {
return errors.Errorf("leaked mountpoint for %s", tmpdir)
}
}
return s.Err()
}
// moved here since os.Chown is not supported on Windows.
// see no-op counterpart in util_windows.go
func chown(name string, uid, gid int) error {
return os.Chown(name, uid, gid)
}
func normalizeAddress(address string) string {
// for parity with windows, no effect for unix
return address
}