aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/fshim/ipc/payload.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-11-02 03:03:44 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-11-02 03:13:57 +0900
commit584732f80ab91afb349720cfb8e9979ed2ba173e (patch)
tree8ef6ab9f8c9d3b8197682a53fb2c4a7b2ce8da55 /cmd/fshim/ipc/payload.go
parent4b7b899bb35fb4ea218dabe49a674f4d2f80e7f8 (diff)
cmd: shim and init into separate binaries
This change also fixes a deadlock when shim fails to connect and complete the setup. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'cmd/fshim/ipc/payload.go')
-rw-r--r--cmd/fshim/ipc/payload.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/cmd/fshim/ipc/payload.go b/cmd/fshim/ipc/payload.go
new file mode 100644
index 00000000..1aaddb1f
--- /dev/null
+++ b/cmd/fshim/ipc/payload.go
@@ -0,0 +1,42 @@
+package shim0
+
+import (
+ "encoding/gob"
+ "errors"
+ "net"
+
+ "git.ophivana.moe/security/fortify/helper/bwrap"
+ "git.ophivana.moe/security/fortify/internal/fmsg"
+)
+
+const Env = "FORTIFY_SHIM"
+
+type Payload struct {
+ // child full argv
+ Argv []string
+ // bwrap, target full exec path
+ Exec [2]string
+ // bwrap config
+ Bwrap *bwrap.Config
+ // whether to pass wayland fd
+ WL bool
+
+ // verbosity pass through
+ Verbose bool
+}
+
+func (p *Payload) Serve(conn *net.UnixConn, wl *Wayland) error {
+ if err := gob.NewEncoder(conn).Encode(*p); err != nil {
+ return fmsg.WrapErrorSuffix(err,
+ "cannot stream shim payload:")
+ }
+
+ if wl != nil {
+ if err := wl.WriteUnix(conn); err != nil {
+ return errors.Join(err, conn.Close())
+ }
+ }
+
+ return fmsg.WrapErrorSuffix(conn.Close(),
+ "cannot close setup connection:")
+}