aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cmd/hakurei/testsuite/main.go70
-rw-r--r--cmd/hakurei/testsuite/notify.go24
-rw-r--r--cmd/hakurei/testsuite/notify_rosa.go68
-rw-r--r--cmd/hakurei/testsuite/sandbox/main.go4
-rw-r--r--internal/rosa/package/basu.az8
-rw-r--r--internal/rosa/package/dbus.az20
-rw-r--r--internal/rosa/package/fontconfig.az21
-rw-r--r--internal/rosa/package/foot.az5
-rw-r--r--internal/rosa/package/kernel/arm64.config6
-rw-r--r--internal/rosa/package/lua/package.az2
-rw-r--r--internal/rosa/package/mako.az2
-rw-r--r--internal/rosa/package/noto.az15
-rw-r--r--internal/rosa/package/pipewire.az6
-rw-r--r--internal/rosa/package/pulseaudio.az3
-rw-r--r--internal/rosa/package/shared-mime-info/package.az3
-rw-r--r--internal/rosa/package/utf8proc.az6
-rw-r--r--internal/testsuite/testsuite.go74
17 files changed, 255 insertions, 82 deletions
diff --git a/cmd/hakurei/testsuite/main.go b/cmd/hakurei/testsuite/main.go
index 9e7455a5..220b8a2a 100644
--- a/cmd/hakurei/testsuite/main.go
+++ b/cmd/hakurei/testsuite/main.go
@@ -75,15 +75,14 @@ func checkHakurei(
dbusEnv string,
name, long string,
- scan, verbose, insecure bool,
- retry int,
+ flags, retry int,
processConfig func(c *hst.Config),
f func(p hst.State, pid int) error,
checkOutput func(output string) bool,
wantCode ...int,
) {
- if !scan && f != nil {
+ if flags&testsuite.SHScan == 0 && f != nil {
log.Fatalf("(%s) cannot inspect without scanning", name)
}
if checkOutput == nil {
@@ -137,12 +136,11 @@ func checkHakurei(
checkHakurei(
ctx, wg, cred, dbusEnv,
name, long,
- scan, verbose, insecure,
- retry-1,
+ flags, retry-1,
processConfig, f,
checkOutput, wantCode...,
)
- }, scan, false, verbose, insecure, c,
+ }, flags, c,
)
if f != nil {
@@ -151,7 +149,7 @@ func checkHakurei(
}
}
- if scan {
+ if flags&testsuite.SHScan != 0 {
testsuite.MustRun(
cred, testsuite.SessionEnv(dbusEnv),
"hakurei", "kill", p.ID.String(),
@@ -174,6 +172,7 @@ func main() {
defer swg.Wait()
dbusEnv := testsuite.MustStartSessionBus(&cred)
testsuite.MustStartSway(&swg, &cred, dbusEnv)
+ startMako(&swg, &cred, dbusEnv)
defer testsuite.TerminateSway(&cred)
pipewireVersion := testsuite.MustStartPipeWire(&cred, dbusEnv)
sessionEnv := testsuite.SessionEnv(dbusEnv)
@@ -350,7 +349,7 @@ func main() {
output,
)
}
- }, false, false, false, false, &hst.Config{
+ }, 0, &hst.Config{
Container: &hst.ContainerConfig{
Shell: absNonexistent,
Home: absNonexistent,
@@ -365,13 +364,13 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"indirect-termination", "indirect termination",
- true, false, false, 0, nil, nil, nil,
+ testsuite.SHScan, 0, nil, nil, nil,
)
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"immediate-termination", "immediate termination",
- true, false, false, 0, func(c *hst.Config) {
+ testsuite.SHScan, 0, func(c *hst.Config) {
c.Container.WaitDelay = -1
}, nil, nil, 254,
)
@@ -379,7 +378,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"shim-poke", "unexpected shim notification",
- true, true, false, 0, nil, func(p hst.State, pid int) error {
+ testsuite.SHScan|testsuite.SHVerbose, 0, nil, func(p hst.State, pid int) error {
if err := syscall.Kill(p.ShimPID, syscall.SIGCONT); err != nil {
return os.NewSyscallError("kill", err)
}
@@ -395,7 +394,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"reject-deprecated", "reject insecure configuration",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EPulse)
}, nil, func(output string) bool {
return output == "hakurei: enablement PulseAudio is insecure "+
@@ -406,7 +405,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"pipewire-pulse", "pipewire proxying behaviour",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EPipeWire)
c.Container.Path = prefix.Append("bin", "pactl")
c.Container.Args = []string{"pactl", "info"}
@@ -450,7 +449,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"pipewire-security", "pipewire SecurityContext",
- false, false, false, 32, func(c *hst.Config) {
+ 0, 32, func(c *hst.Config) {
c.Enablements = new(hst.EPipeWire)
c.Container.Path = prefix.Append("bin", "pactl")
c.Container.Args = []string{
@@ -467,7 +466,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"pipewire-direct-failure", "pipewire cover direct access",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EPipeWire)
c.Container.Path = prefix.Append("bin", "pw-dump")
c.Container.Args = []string{"pw-dump"}
@@ -479,7 +478,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"pipewire-direct", "pipewire direct access",
- false, false, true, 0, func(c *hst.Config) {
+ testsuite.SHInsecure, 0, func(c *hst.Config) {
c.Enablements = new(hst.EPipeWire)
c.DirectPipeWire = true
c.Container.Path = prefix.Append("bin", "pw-dump")
@@ -492,7 +491,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"wayland-client", "wayland client",
- true, false, false, 0, func(c *hst.Config) {
+ testsuite.SHScan, 0, func(c *hst.Config) {
c.Enablements = new(hst.EWayland)
c.Container.Path = prefix.Append("bin", "foot")
c.Container.Args = []string{"foot"}
@@ -502,7 +501,7 @@ func main() {
n.ID == "app.hakurei.wayland-client" &&
n.Instance == p.ID &&
n.AppID == "foot"
- })
+ }, "wayland client")
return nil
}, func(string) bool { return true }, 230,
)
@@ -510,7 +509,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"wayland-security-context", "wayland security-context-v1",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EWayland)
c.Container.Path = prefix.Append("bin", "wayland-info")
c.Container.Args = []string{"wayland-info"}
@@ -525,7 +524,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"wlr-screencopy-unstable-v1", "direct wlr-screencopy-unstable-v1",
- false, false, true, 0, func(c *hst.Config) {
+ testsuite.SHInsecure, 0, func(c *hst.Config) {
c.Enablements = new(hst.EWayland)
c.DirectWayland = true
c.Container.Path = prefix.Append("bin", "wayland-info")
@@ -543,18 +542,18 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"direct-wayland-client", "direct wayland client",
- true, false, true, 0, func(c *hst.Config) {
+ testsuite.SHScan|testsuite.SHInsecure, 0, func(c *hst.Config) {
c.Enablements = new(hst.EWayland)
c.DirectWayland = true
c.Container.Path = prefix.Append("bin", "foot")
c.Container.Args = []string{"foot"}
- }, func(p hst.State, pid int) error {
+ }, func(_ hst.State, _ int) error {
testsuite.PollSwayWindow(ctx, &cred, func(n *testsuite.SwayNode) bool {
return n.Sandbox == "" &&
n.ID == "" &&
n.Instance == hst.ID{} &&
n.AppID == "foot"
- })
+ }, "direct wayland client")
return nil
}, func(string) bool { return true }, 230,
)
@@ -563,7 +562,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"xwayland-client", "xwayland client",
- false, false, false, 32, func(c *hst.Config) {
+ 0, 32, func(c *hst.Config) {
c.Enablements = new(hst.EX11)
c.Container.Path = prefix.Append("bin", "xset")
c.Container.Args = []string{"xset", "q"}
@@ -576,7 +575,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"dbus", "proxied dbus call",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EDBus)
c.SessionBus = &hst.BusConfig{
Talk: []string{"org.freedesktop.Notifications"},
@@ -588,17 +587,14 @@ func main() {
"Test notification",
}
}, nil, func(output string) bool {
- return output == "GDBus.Error:"+
- "org.freedesktop.DBus.Error.ServiceUnknown: "+
- "The name org.freedesktop.Notifications "+
- "was not provided by any .service files\r\n"
- }, hst.ExitFailure,
+ return output == pdcOutput
+ }, pdcExit,
)
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"dbus reject", "rejected dbus call",
- false, false, false, 0, func(c *hst.Config) {
+ 0, 0, func(c *hst.Config) {
c.Enablements = new(hst.EDBus)
c.SessionBus = &hst.BusConfig{Filter: true}
c.Container.Path = prefix.Append("bin", "notify-send")
@@ -607,9 +603,11 @@ func main() {
"Test notification",
}
}, nil, func(output string) bool {
- return output == "GDBus.Error:"+
- "org.freedesktop.DBus.Error.ServiceUnknown: "+
+ const suffix = "GDBus.Error:" +
+ "org.freedesktop.DBus.Error.ServiceUnknown: " +
"org.freedesktop.DBus.Error.ServiceUnknown\r\n"
+ return output == suffix ||
+ output == "Failed to show notification: "+suffix
}, hst.ExitFailure,
)
@@ -722,7 +720,7 @@ func main() {
checkHakurei(
ctx, &wg, &cred, dbusEnv,
"setscheduler-"+strconv.Itoa(int(policy)), "setscheduler "+strconv.Quote(policy.String()),
- true, false, false, 0, func(c *hst.Config) {
+ testsuite.SHScan, 0, func(c *hst.Config) {
c.SchedPolicy = _policy
}, func(p hst.State, pid int) error {
got := -1
@@ -842,7 +840,7 @@ func main() {
"--numeric",
"/tmp/hakurei.0/runtime/"+strconv.Itoa(c.Identity),
))
- }, true, false, false, false, c,
+ }, testsuite.SHScan, c,
)
validatePresent("after first process")
@@ -852,7 +850,7 @@ func main() {
defer close(done)
onDone(err, output)
validatePresent("after second process termination")
- }, true, false, false, false, c,
+ }, testsuite.SHScan, c,
)
validatePresent("after second process")
diff --git a/cmd/hakurei/testsuite/notify.go b/cmd/hakurei/testsuite/notify.go
new file mode 100644
index 00000000..492d2ca7
--- /dev/null
+++ b/cmd/hakurei/testsuite/notify.go
@@ -0,0 +1,24 @@
+//go:build !rosa
+
+package main
+
+import (
+ "sync"
+ "syscall"
+
+ "hakurei.app/hst"
+)
+
+// startMako is a noop.
+func startMako(_ *sync.WaitGroup, _ *syscall.Credential, _ string) {}
+
+const (
+ // pdcExit is the expected error code of the proxied dbus call test.
+ pdcExit = hst.ExitFailure
+
+ // pdcOutput is the expected output of the proxied dbus call test.
+ pdcOutput = "GDBus.Error:" +
+ "org.freedesktop.DBus.Error.ServiceUnknown: " +
+ "The name org.freedesktop.Notifications " +
+ "was not provided by any .service files\r\n"
+)
diff --git a/cmd/hakurei/testsuite/notify_rosa.go b/cmd/hakurei/testsuite/notify_rosa.go
new file mode 100644
index 00000000..4b67611a
--- /dev/null
+++ b/cmd/hakurei/testsuite/notify_rosa.go
@@ -0,0 +1,68 @@
+//go:build rosa
+
+package main
+
+import (
+ "context"
+ "errors"
+ "log"
+ "os/exec"
+ "sync"
+ "sync/atomic"
+ "syscall"
+ "time"
+
+ "hakurei.app/internal/testsuite"
+)
+
+// startMako starts the mako notification daemon against sway and waits for it
+// to be ready. It terminates the program if mako terminates before it is ready,
+// or terminates with an unexpected exit status.
+func startMako(
+ wg *sync.WaitGroup,
+ cred *syscall.Credential,
+ dbusEnv string,
+) {
+ var makoReady atomic.Bool
+ wg.Go(func() {
+ // terminated on sway termination
+ _, done := testsuite.MustStartWith(
+ context.Background(), cred, false, []string{
+ testsuite.XDGRuntimeEnv,
+ testsuite.WaylandEnv,
+ dbusEnv,
+ }, nil,
+ "mako",
+ )
+ err := <-done
+
+ if !makoReady.Load() {
+ log.Fatalf("mako terminated before ready: %v", err)
+ }
+
+ if err == nil {
+ return
+ }
+
+ if e, ok := errors.AsType[*exec.ExitError](err); !ok {
+ log.Fatalf("mako terminated unexpectedly: %v", err)
+ } else if e.ExitCode() != 1 {
+ log.Fatalf("mako terminated with unexpected status: %v", err)
+ }
+ })
+ testsuite.Poll(
+ 50*time.Millisecond,
+ cred,
+ []string{dbusEnv},
+ "makoctl", "list",
+ )
+ makoReady.Store(true)
+}
+
+const (
+ // pdcExit is the expected error code of the proxied dbus call test.
+ pdcExit = 0
+
+ // pdcOutput is the expected output of the proxied dbus call test.
+ pdcOutput = ""
+)
diff --git a/cmd/hakurei/testsuite/sandbox/main.go b/cmd/hakurei/testsuite/sandbox/main.go
index 681718a7..e340b829 100644
--- a/cmd/hakurei/testsuite/sandbox/main.go
+++ b/cmd/hakurei/testsuite/sandbox/main.go
@@ -43,7 +43,7 @@ func mustStart(
)
var stat syscall.Stat_t
- pid = testsuite.MustScanFor(func(s *testsuite.StatScanner) bool {
+ pid = testsuite.MustScanFor(nil, func(s *testsuite.StatScanner) bool {
select {
case err := <-done:
if err == nil {
@@ -359,7 +359,7 @@ func main() {
if err != nil {
log.Fatalf("test case %s: %v\n%s", name, err, output)
}
- }, true, true, false, false, &tc.Hakurei,
+ }, testsuite.SHScan|testsuite.SHWait, &tc.Hakurei,
)
if err != nil {
diff --git a/internal/rosa/package/basu.az b/internal/rosa/package/basu.az
index cbd2dc03..2ef78b06 100644
--- a/internal/rosa/package/basu.az
+++ b/internal/rosa/package/basu.az
@@ -10,7 +10,13 @@ package basu {
compress = gzip;
};
- exec = meson {};
+ exec = meson {
+ test = arch {
+ default = unset;
+ // takes forever under qemu
+ cross = false;
+ };
+ };
tools = [
awk,
diff --git a/internal/rosa/package/dbus.az b/internal/rosa/package/dbus.az
index d5a38c8f..47c5890e 100644
--- a/internal/rosa/package/dbus.az
+++ b/internal/rosa/package/dbus.az
@@ -23,6 +23,12 @@ package dbus {
"inotify": "enabled";
"x11_autolaunch": "disabled";
};
+
+ test = arch {
+ default = unset;
+ // attempts to invoke shell scripts through qemu
+ cross = false;
+ };
};
inputs = [
@@ -47,12 +53,14 @@ package xdg-dbus-proxy {
setup = {
"man": "disabled";
};
- };
- inputs = [
- dbus,
- glib,
- ];
+ test = arch {
+ default = unset;
+ // attempts to run proxy binary as a shell script
+ cross = false;
+ };
+ };
- runtime = [ glib ];
+ tools = [ dbus ];
+ inputs = [ glib ];
}
diff --git a/internal/rosa/package/fontconfig.az b/internal/rosa/package/fontconfig.az
index 44824f92..7a6dacb0 100644
--- a/internal/rosa/package/fontconfig.az
+++ b/internal/rosa/package/fontconfig.az
@@ -11,27 +11,16 @@ package fontconfig {
checksum = "ZZzmt8fYh-3jKJ6vHXUDbeAWM2ilRusWxdynLt3Z4E_CQQ8cCwzpuAWACXmr9qHI";
};
- exec = make {
- generate = "NOCONFIGURE=1 ./autogen.sh";
- configure = {
- // configure attempts to run compiled binary
- "": "ac_cv_va_copy=yes";
+ exec = meson {
+ setup = {
+ "default-fonts-dirs": prefix+"/share/fonts";
};
};
- tools = [
- automake,
- libtool,
- pkgconf,
- gettext,
- gperf,
- gzip,
- python,
- ];
+ tools = [ gperf ];
inputs = [
- zlib,
- libexpat,
freetype,
+ libxml2,
];
}
diff --git a/internal/rosa/package/foot.az b/internal/rosa/package/foot.az
index 90d3cbe3..ffc21ab3 100644
--- a/internal/rosa/package/foot.az
+++ b/internal/rosa/package/foot.az
@@ -13,7 +13,10 @@ package foot {
exec = meson {};
- tools = [ ncurses ];
+ tools = [
+ ncurses,
+ wayland,
+ ];
inputs = [
xkbcommon,
diff --git a/internal/rosa/package/kernel/arm64.config b/internal/rosa/package/kernel/arm64.config
index 11ea92d1..1243fbf5 100644
--- a/internal/rosa/package/kernel/arm64.config
+++ b/internal/rosa/package/kernel/arm64.config
@@ -5066,8 +5066,10 @@ CONFIG_SERIAL_OF_PLATFORM=m
#
# Non-8250 serial port support
#
-CONFIG_SERIAL_AMBA_PL010=m
-CONFIG_SERIAL_AMBA_PL011=m
+CONFIG_SERIAL_AMBA_PL010=y
+CONFIG_SERIAL_AMBA_PL010_CONSOLE=y
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
# CONFIG_SERIAL_EARLYCON_SEMIHOST is not set
CONFIG_SERIAL_ATMEL=y
CONFIG_SERIAL_ATMEL_CONSOLE=y
diff --git a/internal/rosa/package/lua/package.az b/internal/rosa/package/lua/package.az
index 033af0fe..032a6681 100644
--- a/internal/rosa/package/lua/package.az
+++ b/internal/rosa/package/lua/package.az
@@ -25,7 +25,7 @@ package lua {
preMake = `
sed -i 's|@ROSA_PREFIX@|`+prefix+`|g' src/luaconf.h
`;
- make = [ "CC='clang -fPIC'", "all" ];
+ make = [ `CC="${CC:-clang} -fPIC"`, "all" ];
check = [ "test" ];
install = `
make INSTALL_TOP=/work`+prefix+` install
diff --git a/internal/rosa/package/mako.az b/internal/rosa/package/mako.az
index 488ae745..394af85e 100644
--- a/internal/rosa/package/mako.az
+++ b/internal/rosa/package/mako.az
@@ -16,6 +16,8 @@ package mako {
};
};
+ tools = [ wayland ];
+
inputs = [
basu,
pango,
diff --git a/internal/rosa/package/noto.az b/internal/rosa/package/noto.az
index aa017f89..14a09f74 100644
--- a/internal/rosa/package/noto.az
+++ b/internal/rosa/package/noto.az
@@ -13,8 +13,9 @@ package noto {
enterSource = true;
exec = generic {
chdir = false;
- install = `
-DEST=/work`+prefix+`/share/fonts/noto
+ build = `
+[ ! -d `+prefix+`/share/fonts ]
+DEST=`+prefix+`/share/fonts/noto
for font in $(ls -d fonts/*/); do
if [[ -d "$font"unhinted/variable-ttf ]]; then
install -m444 -vDt "$DEST" "$font"unhinted/variable-ttf/*.ttf
@@ -25,9 +26,17 @@ for font in $(ls -d fonts/*/); do
fi
done
rename -v 's/\[.*\]//' $DEST/*
+fc-cache -vf
+`;
+ install = `
+mkdir -p /work`+prefix+`/share
+mv `+prefix+`/share/fonts /work`+prefix+`/share
`;
};
- tools = [ rename ];
+ tools = [
+ rename,
+ fontconfig,
+ ];
cross = nil;
}
diff --git a/internal/rosa/package/pipewire.az b/internal/rosa/package/pipewire.az
index 53c8749c..b68b4cea 100644
--- a/internal/rosa/package/pipewire.az
+++ b/internal/rosa/package/pipewire.az
@@ -23,6 +23,12 @@ package wireplumber {
"elogind": "disabled";
"systemd": "disabled";
};
+
+ test = arch {
+ default = unset;
+ // tests fail under qemu
+ cross = false;
+ };
};
inputs = [
diff --git a/internal/rosa/package/pulseaudio.az b/internal/rosa/package/pulseaudio.az
index 2d882cfd..04de1da0 100644
--- a/internal/rosa/package/pulseaudio.az
+++ b/internal/rosa/package/pulseaudio.az
@@ -18,6 +18,8 @@ echo '`+version+`' > .tarball-version
exec = meson {
setup = {
+ "c_link_args": "-Wl,--undefined-version";
+
"daemon": "false";
"client": "true";
"doxygen": "false";
@@ -28,7 +30,6 @@ echo '`+version+`' > .tarball-version
tools = [
m4,
coreutils,
- binutils,
];
inputs = [
diff --git a/internal/rosa/package/shared-mime-info/package.az b/internal/rosa/package/shared-mime-info/package.az
index 5c459bdd..84f0aad8 100644
--- a/internal/rosa/package/shared-mime-info/package.az
+++ b/internal/rosa/package/shared-mime-info/package.az
@@ -44,6 +44,7 @@ cp -r ../extra/xdgmime subprojects/
inputs = [
glib,
+ libxml2,
error-standalone,
];
@@ -53,4 +54,6 @@ cp -r ../extra/xdgmime subprojects/
gettext,
libxml2,
];
+
+ native = [ shared-mime-info ];
}
diff --git a/internal/rosa/package/utf8proc.az b/internal/rosa/package/utf8proc.az
index a881c493..36e1d16a 100644
--- a/internal/rosa/package/utf8proc.az
+++ b/internal/rosa/package/utf8proc.az
@@ -14,5 +14,11 @@ package utf8proc {
cache = {
"UTF8PROC_ENABLE_TESTING": "ON";
};
+
+ test = arch {
+ default = unset;
+ // attempts to invoke binaries directly
+ cross = nil;
+ };
};
}
diff --git a/internal/testsuite/testsuite.go b/internal/testsuite/testsuite.go
index 30c21df8..32d5e1ba 100644
--- a/internal/testsuite/testsuite.go
+++ b/internal/testsuite/testsuite.go
@@ -537,7 +537,16 @@ func PollSwayWindow(
ctx context.Context,
cred *syscall.Credential,
f func(n *SwayNode) bool,
+ name string,
) *SwayNode {
+ m := time.NewTicker(1 * time.Second)
+ defer m.Stop()
+ go func() {
+ for range m.C {
+ log.Printf("still polling %s", name)
+ }
+ }()
+
var t SwayNode
for {
time.Sleep(25 * time.Millisecond)
@@ -617,7 +626,17 @@ func MustStartPipeWire(cred *syscall.Credential, dbusEnv string) (version string
// MustScanFor continuously scans the proc filesystem and calls f for each entry
// visited.
-func MustScanFor(f func(ps *StatScanner) bool) int {
+func MustScanFor(n func(), f func(ps *StatScanner) bool) int {
+ if n != nil {
+ m := time.NewTicker(1 * time.Second)
+ defer m.Stop()
+ go func() {
+ for range m.C {
+ n()
+ }
+ }()
+ }
+
var ps StatScanner
for ps.Scan() {
@@ -707,6 +726,17 @@ func LookupStore(cred *syscall.Credential, id hst.ID, p *hst.State) error {
return <-done
}
+const (
+ // SHScan enables startup notification and proc scanning for [StartHakurei].
+ SHScan = 1 << iota
+ // SHWait blocks [StartHakurei] on notify pipe.
+ SHWait
+ // SHVerbose enables hakurei verbose output in [StartHakurei].
+ SHVerbose
+ // SHInsecure enables insecure configuration in [StartHakurei].
+ SHInsecure
+)
+
// StartHakurei starts a hakurei container configured by c.
func StartHakurei(
ctx context.Context,
@@ -715,19 +745,19 @@ func StartHakurei(
dbusEnv string,
processCommand func(cmd *exec.Cmd),
onDone func(err error, output string),
- scan, wait, verbose, insecure bool,
+ flags int,
c *hst.Config,
) (p hst.State, pid int, err error) {
var hakureiFlags string
- if verbose {
+ if flags&SHVerbose != 0 {
hakureiFlags += " -v"
}
- if insecure {
+ if flags&SHInsecure != 0 {
hakureiFlags += " --insecure"
}
var notifySuffix string
- if wait {
+ if flags&SHWait != 0 {
notifySuffix += " 1>&3"
}
@@ -767,8 +797,13 @@ func StartHakurei(
processCommand(cmd)
}
+ var onDoneReached atomic.Bool
done := MustStart(cmd)
- wg.Go(func() { _err := <-done; onDone(_err, output.String()) })
+ wg.Go(func() {
+ _err := <-done
+ onDoneReached.Store(true)
+ onDone(_err, output.String())
+ })
if err = errors.Join(
_notify.Close(),
@@ -787,7 +822,7 @@ func StartHakurei(
return
}
- if !scan && len(cmd.ExtraFiles) != 3 {
+ if flags&SHScan == 0 && len(cmd.ExtraFiles) != 3 {
err = errors.Join(notify.Close(), ident.Close())
return
}
@@ -795,7 +830,7 @@ func StartHakurei(
var id hst.ID
if _, err = io.ReadFull(ident, id[:]); err != nil {
_, _ = notify.Close(), ident.Close()
- if !scan && errors.Is(err, io.EOF) {
+ if flags&SHScan == 0 && errors.Is(err, io.EOF) {
err = nil
}
return
@@ -804,12 +839,12 @@ func StartHakurei(
return
}
- if !scan {
+ if flags&SHScan == 0 {
err = notify.Close()
return
}
- if wait {
+ if flags&SHWait != 0 {
if _, err = io.ReadFull(notify, make([]byte, 8)); err != nil {
_ = notify.Close()
return
@@ -843,7 +878,20 @@ func StartHakurei(
}
var stat syscall.Stat_t
- pid = MustScanFor(func(ps *StatScanner) bool {
+ pid = MustScanFor(func() {
+ if onDoneReached.Load() {
+ log.Fatalf(
+ "%s terminated while scanning\n%s",
+ c.Container.Hostname,
+ output.String(),
+ )
+ }
+ log.Printf(
+ "still scanning for %s, output:\n%s",
+ c.Container.Hostname,
+ output.String(),
+ )
+ }, func(ps *StatScanner) bool {
select {
case err = <-done:
if err == nil {
@@ -909,7 +957,7 @@ func MustStartHakurei(
cred *syscall.Credential,
dbusEnv string,
onDone func(err error, output string),
- scan, wait, verbose, insecure bool,
+ flags int,
c *hst.Config,
) (p hst.State, pid int) {
_ctx, cancel := context.WithCancel(ctx)
@@ -920,7 +968,7 @@ func MustStartHakurei(
nil, func(err error, output string) {
defer cancel()
onDone(err, output)
- }, scan, wait, verbose, insecure, c,
+ }, flags, c,
)
if err != nil {
log.Printf(