aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/app.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-12-18 13:45:55 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-12-18 13:45:55 +0900
commitb752ec44689aa5a3a0f3b9672b218691f161c7c1 (patch)
treeb514cb0c247f8deaa9feba84d9f8944623911f5d /internal/app/app.go
parent5d00805a7c775382516e05b5b01e58df651408ab (diff)
fipc: export config struct
Also store full config as part of state. Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/app/app.go')
-rw-r--r--internal/app/app.go28
1 files changed, 27 insertions, 1 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
index 3260deab..5cb1ddf8 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -2,8 +2,10 @@ package app
import (
"sync"
+ "sync/atomic"
"git.ophivana.moe/security/fortify/cmd/fshim/ipc/shim"
+ "git.ophivana.moe/security/fortify/fipc"
"git.ophivana.moe/security/fortify/internal/linux"
)
@@ -17,11 +19,14 @@ type App interface {
// WaitErr returns error returned by the underlying wait syscall.
WaitErr() error
- Seal(config *Config) error
+ Seal(config *fipc.Config) error
String() string
}
type app struct {
+ // single-use config reference
+ ct *appCt
+
// application unique identifier
id *ID
// operating system interface
@@ -69,3 +74,24 @@ func New(os linux.System) (App, error) {
a.os = os
return a, newAppID(a.id)
}
+
+// appCt ensures its wrapped val is only accessed once
+type appCt struct {
+ val *fipc.Config
+ done *atomic.Bool
+}
+
+func (a *appCt) Unwrap() *fipc.Config {
+ if !a.done.Load() {
+ defer a.done.Store(true)
+ return a.val
+ }
+ panic("attempted to access config reference twice")
+}
+
+func newAppCt(config *fipc.Config) (ct *appCt) {
+ ct = new(appCt)
+ ct.done = new(atomic.Bool)
+ ct.val = config
+ return ct
+}