aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/bwrap/arg.static.string.go
blob: e7f5c3326a5f3365748414cd7fe2aa70007cc3f8 (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
package bwrap

const (
	Hostname = iota
	Chdir
	UnsetEnv
	LockFile

	RemountRO
	Procfs
	DevTmpfs
	Mqueue
)

var stringArgs = [...]string{
	Hostname: "--hostname",
	Chdir:    "--chdir",
	UnsetEnv: "--unsetenv",
	LockFile: "--lock-file",

	RemountRO: "--remount-ro",
	Procfs:    "--proc",
	DevTmpfs:  "--dev",
	Mqueue:    "--mqueue",
}

func (c *Config) stringArgs() Builder {
	n := stringArg{
		UnsetEnv: c.UnsetEnv,
		LockFile: c.LockFile,
	}

	if c.Hostname != "" {
		n[Hostname] = []string{c.Hostname}
	}
	if c.Chdir != "" {
		n[Chdir] = []string{c.Chdir}
	}

	// Arg types:
	// 	 RemountRO
	//   Procfs
	//   DevTmpfs
	//   Mqueue
	// are handled by the sequential builder

	return &n
}

type stringArg [len(stringArgs)][]string

func (s *stringArg) Len() (l int) {
	for _, arg := range s {
		l += len(arg) * 2
	}
	return
}

func (s *stringArg) Append(args *[]string) {
	for i, arg := range s {
		for _, v := range arg {
			*args = append(*args, stringArgs[i], v)
		}
	}
}