diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-24 13:26:30 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-24 13:37:38 +0900 |
| commit | b99c63337df4068b36d7d8de2ae79fd274172977 (patch) | |
| tree | 81d2453857b7d6328db6545f096181b771c24cc3 /internal/sys/hsu.go | |
| parent | f09133a224fabf2d16c7790654e39068cb59450f (diff) | |
internal/app: do not return from shim start
The whole RunState ugliness and the other horrendous error handling conditions for internal/app come from an old design proposal for maintaining all app containers under the same daemon process for a user. The proposal was ultimately rejected but the implementation remained. It is removed here to alleviate internal/app from much of its ugliness and unreadability.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/sys/hsu.go')
| -rw-r--r-- | internal/sys/hsu.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/sys/hsu.go b/internal/sys/hsu.go index 84bb0731..2be12d1e 100644 --- a/internal/sys/hsu.go +++ b/internal/sys/hsu.go @@ -3,6 +3,7 @@ package sys import ( "errors" "fmt" + "log" "os" "os/exec" "strconv" @@ -11,6 +12,7 @@ import ( "hakurei.app/container" "hakurei.app/hst" "hakurei.app/internal" + "hakurei.app/internal/hlog" ) // Hsu caches responses from cmd/hsu. @@ -79,3 +81,24 @@ func (h *Hsu) Uid(identity int) (int, error) { } return u.uid, u.err } + +// MustUid calls [State.Uid] and terminates on error. +func MustUid(s State, identity int) int { + uid, err := s.Uid(identity) + if err == nil { + return uid + } + + const fallback = "cannot obtain uid from setuid wrapper:" + if errors.Is(err, ErrHsuAccess) { + hlog.Verbose("*"+fallback, err) + os.Exit(1) + return -0xdeadbeef + } else if m, ok := container.GetErrorMessage(err); ok { + log.Fatal(m) + return -0xdeadbeef + } else { + log.Fatalln(fallback, err) + return -0xdeadbeef + } +} |
