internal/outcome/process: output via msg
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m5s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m4s
Test / Hakurei (race detector) (push) Successful in 4m54s
Test / Flake checks (push) Successful in 1m27s
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m18s
Test / Hakurei (push) Successful in 3m5s
Test / Hpkg (push) Successful in 4m2s
Test / Sandbox (race detector) (push) Successful in 4m4s
Test / Hakurei (race detector) (push) Successful in 4m54s
Test / Flake checks (push) Successful in 1m27s
This makes it possible to instrument output behaviour through stub. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
eeb9f98e5b
commit
eda9d45a5a
@ -3,7 +3,6 @@ package outcome
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
|
|
||||||
"hakurei.app/hst"
|
"hakurei.app/hst"
|
||||||
"hakurei.app/message"
|
"hakurei.app/message"
|
||||||
@ -18,8 +17,8 @@ func Main(ctx context.Context, msg message.Msg, config *hst.Config) {
|
|||||||
|
|
||||||
seal := outcome{syscallDispatcher: direct{msg}}
|
seal := outcome{syscallDispatcher: direct{msg}}
|
||||||
if err := seal.finalise(ctx, msg, &id, config); err != nil {
|
if err := seal.finalise(ctx, msg, &id, config); err != nil {
|
||||||
printMessageError("cannot seal app:", err)
|
printMessageError(msg.GetLogger().Fatalln, "cannot seal app:", err)
|
||||||
os.Exit(1)
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
seal.main(msg)
|
seal.main(msg)
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -68,7 +67,7 @@ func (ms mainState) beforeExit(isFault bool) {
|
|||||||
// updates hasErr but does not terminate
|
// updates hasErr but does not terminate
|
||||||
perror := func(err error, message string) {
|
perror := func(err error, message string) {
|
||||||
hasErr = true
|
hasErr = true
|
||||||
printMessageError("cannot "+message+":", err)
|
printMessageError(ms.GetLogger().Println, "cannot "+message+":", err)
|
||||||
}
|
}
|
||||||
exitCode := 1
|
exitCode := 1
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -121,7 +120,7 @@ func (ms mainState) beforeExit(isFault bool) {
|
|||||||
// this is only reachable when shim did not exit within shimWaitTimeout, after its WaitDelay has elapsed.
|
// this is only reachable when shim did not exit within shimWaitTimeout, after its WaitDelay has elapsed.
|
||||||
// This is different from the container failing to terminate within its timeout period, as that is enforced
|
// This is different from the container failing to terminate within its timeout period, as that is enforced
|
||||||
// by the shim. This path is instead reached when there is a lockup in shim preventing it from completing.
|
// by the shim. This path is instead reached when there is a lockup in shim preventing it from completing.
|
||||||
log.Printf("process %d did not terminate", ms.cmd.Process.Pid)
|
ms.GetLogger().Printf("process %d did not terminate", ms.cmd.Process.Pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
ms.Resume()
|
ms.Resume()
|
||||||
@ -167,7 +166,7 @@ func (ms mainState) beforeExit(isFault bool) {
|
|||||||
if s.Config != nil {
|
if s.Config != nil {
|
||||||
rt |= s.Config.Enablements.Unwrap()
|
rt |= s.Config.Enablements.Unwrap()
|
||||||
} else {
|
} else {
|
||||||
log.Printf("state entry %d does not contain config", i)
|
ms.GetLogger().Printf("state entry %d does not contain config", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +195,7 @@ func (ms mainState) beforeExit(isFault bool) {
|
|||||||
|
|
||||||
// fatal calls printMessageError, performs necessary cleanup, followed by a call to [os.Exit](1).
|
// fatal calls printMessageError, performs necessary cleanup, followed by a call to [os.Exit](1).
|
||||||
func (ms mainState) fatal(fallback string, ferr error) {
|
func (ms mainState) fatal(fallback string, ferr error) {
|
||||||
printMessageError(fallback, ferr)
|
printMessageError(ms.GetLogger().Println, fallback, ferr)
|
||||||
ms.beforeExit(true)
|
ms.beforeExit(true)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -310,12 +309,12 @@ func (k *outcome) main(msg message.Msg) {
|
|||||||
|
|
||||||
// printMessageError prints the error message according to [message.GetMessage],
|
// printMessageError prints the error message according to [message.GetMessage],
|
||||||
// or fallback prepended to err if an error message is not available.
|
// or fallback prepended to err if an error message is not available.
|
||||||
func printMessageError(fallback string, err error) {
|
func printMessageError(println func(v ...any), fallback string, err error) {
|
||||||
m, ok := message.GetMessage(err)
|
m, ok := message.GetMessage(err)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println(fallback, err)
|
println(fallback, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print(m)
|
println(m)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package outcome
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -213,11 +214,19 @@ func shimEntrypoint(k syscallDispatcher) {
|
|||||||
z.WaitDelay = state.Shim.WaitDelay
|
z.WaitDelay = state.Shim.WaitDelay
|
||||||
|
|
||||||
if err := k.containerStart(z); err != nil {
|
if err := k.containerStart(z); err != nil {
|
||||||
printMessageError("cannot start container:", err)
|
var f func(v ...any)
|
||||||
|
if logger := msg.GetLogger(); logger != nil {
|
||||||
|
f = logger.Println
|
||||||
|
} else {
|
||||||
|
f = func(v ...any) {
|
||||||
|
msg.Verbose(fmt.Sprintln(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printMessageError(f, "cannot start container:", err)
|
||||||
k.exit(hst.ExitFailure)
|
k.exit(hst.ExitFailure)
|
||||||
}
|
}
|
||||||
if err := k.containerServe(z); err != nil {
|
if err := k.containerServe(z); err != nil {
|
||||||
printMessageError("cannot configure container:", err)
|
printMessageError(func(v ...any) { k.fatal(fmt.Sprintln(v)) }, "cannot configure container:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := k.seccompLoad(
|
if err := k.seccompLoad(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user