aboutsummaryrefslogtreecommitdiffhomepage
path: root/helper/bwrap/arg.static.string.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-10-15 02:15:55 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-10-15 02:15:55 +0900
commit2faf510146733c28a5dbc3245175700abcf4f966 (patch)
tree707b5fec5d210c19123205969731837b780e318d /helper/bwrap/arg.static.string.go
parenta0db19b9ad7def33eacdfc23d462604dce3af3bb (diff)
helper/bwrap: ordered filesystem args
The argument builder was written based on the incorrect assumption that bwrap arguments are unordered. The argument builder is replaced in this commit to correct that mistake. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'helper/bwrap/arg.static.string.go')
-rw-r--r--helper/bwrap/arg.static.string.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/helper/bwrap/arg.static.string.go b/helper/bwrap/arg.static.string.go
new file mode 100644
index 00000000..e7f5c332
--- /dev/null
+++ b/helper/bwrap/arg.static.string.go
@@ -0,0 +1,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)
+ }
+ }
+}