forked from security/hakurei
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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user