aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/app/errors.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-04-05 23:51:39 +0900
committerOphestra <cat@gensokyo.uk>2025-04-07 03:55:17 +0900
commite9a7cd526f4e5f0a8f7b18ad3682d2e3afbcb8ba (patch)
tree5b5ac59efa97d2d57d38c094dada9aff22bee72c /internal/app/errors.go
parent12be7bc78e093ef609c9b2a491239cc59721fec6 (diff)
app: improve shim process management
This ensures a signal gets delivered to the process instead of relying on parent death behaviour. SIGCONT was chosen as it is the only signal an unprivileged process is allowed to send to processes with different credentials. A custom signal handler is installed because the Go runtime does not expose signal information other than which signal was received, and shim must check pid to ensure reasonable behaviour. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/app/errors.go')
-rw-r--r--internal/app/errors.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/internal/app/errors.go b/internal/app/errors.go
index 6b5cffe4..5a490f90 100644
--- a/internal/app/errors.go
+++ b/internal/app/errors.go
@@ -8,7 +8,9 @@ import (
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
-func PrintRunStateErr(rs *fst.RunState, runErr error) {
+func PrintRunStateErr(rs *fst.RunState, runErr error) (code int) {
+ code = rs.ExitStatus()
+
if runErr != nil {
if rs.Time == nil {
fmsg.PrintBaseError(runErr, "cannot start app:")
@@ -49,8 +51,8 @@ func PrintRunStateErr(rs *fst.RunState, runErr error) {
}
}
- if rs.ExitCode == 0 {
- rs.ExitCode = 126
+ if code == 0 {
+ code = 126
}
}
@@ -97,13 +99,14 @@ func PrintRunStateErr(rs *fst.RunState, runErr error) {
}
out:
- if rs.ExitCode == 0 {
- rs.ExitCode = 128
+ if code == 0 {
+ code = 128
}
}
if rs.WaitErr != nil {
- log.Println("inner wait failed:", rs.WaitErr)
+ fmsg.Verbosef("wait: %v", rs.WaitErr)
}
+ return
}
// StateStoreError is returned for a failed state save
@@ -121,7 +124,7 @@ type StateStoreError struct {
}
// save saves arbitrary errors in [StateStoreError] once.
-func (e *StateStoreError) save(errs []error) {
+func (e *StateStoreError) save(errs ...error) {
if len(errs) == 0 || e.Err != nil {
panic("invalid call to save")
}