summaryrefslogtreecommitdiff
path: root/internal/namespace/ops.go
blob: 76f696c033ba1f3056ce8734bbe881680d8b21b8 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package namespace

import (
	"os"

	"git.theodohertyfamily.com/wg-wrap/internal/paths"
)

// Ops defines the set of operations required by the Manager to handle
// namespace isolation, lifecycle, and synchronization.
type Ops interface {
	CheckSystemRequirements() error
	IsIsolated() bool
	Bootstrap() error
	BootstrapJoin(pid int) error
	RegisterProcess(pm *paths.PathManager, profile string) error
	UnregisterProcess(pm *paths.PathManager, profile string) error
	PruneStalePids(pm *paths.PathManager, profile string) error
	IsLastProcess(pm *paths.PathManager, profile string) (bool, error)
	PinNamespace(pm *paths.PathManager, profile string) error
	UnpinNamespace(pm *paths.PathManager, profile string) error
	FindActiveProfilePid(pm *paths.PathManager, profile string) (int, error)
	AcquireProfileLock(pm *paths.PathManager, profile string) (*os.File, error)
	ReleaseProfileLock(file *os.File)
}

// linuxOps is the concrete implementation of Ops for Linux systems.
type linuxOps struct{}

// NewLinuxOps returns a new instance of the Linux-specific namespace operations.
func NewLinuxOps() Ops {
	return &linuxOps{}
}

func (l *linuxOps) CheckSystemRequirements() error {
	return CheckSystemRequirements()
}

func (l *linuxOps) IsIsolated() bool {
	return IsIsolated()
}

func (l *linuxOps) Bootstrap() error {
	return Bootstrap()
}

func (l *linuxOps) BootstrapJoin(pid int) error {
	return BootstrapJoin(pid)
}

func (l *linuxOps) RegisterProcess(pm *paths.PathManager, profile string) error {
	return RegisterProcess(pm, profile)
}

func (l *linuxOps) UnregisterProcess(pm *paths.PathManager, profile string) error {
	return UnregisterProcess(pm, profile)
}

func (l *linuxOps) PruneStalePids(pm *paths.PathManager, profile string) error {
	return PruneStalePids(pm, profile)
}

func (l *linuxOps) IsLastProcess(pm *paths.PathManager, profile string) (bool, error) {
	return IsLastProcess(pm, profile)
}

func (l *linuxOps) PinNamespace(pm *paths.PathManager, profile string) error {
	return PinNamespace(pm, profile)
}

func (l *linuxOps) UnpinNamespace(pm *paths.PathManager, profile string) error {
	return UnpinNamespace(pm, profile)
}

func (l *linuxOps) FindActiveProfilePid(pm *paths.PathManager, profile string) (int, error) {
	return FindActiveProfilePid(pm, profile)
}

func (l *linuxOps) AcquireProfileLock(pm *paths.PathManager, profile string) (*os.File, error) {
	return AcquireProfileLock(pm, profile)
}

func (l *linuxOps) ReleaseProfileLock(file *os.File) {
	ReleaseProfileLock(file)
}