aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-03 02:20:18 +0900
committerOphestra <cat@gensokyo.uk>2025-11-03 02:20:18 +0900
commit9a2a7b749f41f73c2c11e4a4557516307838457b (patch)
tree78b102428a8ba3e78a394e0036427a98340385cb
parentec5cb9400c944f8769924a86e1fb741d2c08ba91 (diff)
cmd/hakurei/print: handle nil config
There is nothing to print in this case, and such a nil check is missing. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/hakurei/print.go27
-rw-r--r--cmd/hakurei/print_test.go1
2 files changed, 17 insertions, 11 deletions
diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go
index c6f060a8..51358585 100644
--- a/cmd/hakurei/print.go
+++ b/cmd/hakurei/print.go
@@ -44,7 +44,8 @@ func printShowSystem(output io.Writer, short, flagJSON bool) {
func printShowInstance(
output io.Writer, now time.Time,
instance *hst.State, config *hst.Config,
- short, flagJSON bool) (valid bool) {
+ short, flagJSON bool,
+) (valid bool) {
valid = true
if flagJSON {
@@ -66,6 +67,11 @@ func printShowInstance(
}
}
+ if config == nil {
+ // nothing to print
+ return
+ }
+
if instance != nil {
t.Printf("State\n")
t.Printf(" Instance:\t%s (%d -> %d)\n", instance.ID.String(), instance.PID, instance.ShimPID)
@@ -84,14 +90,13 @@ func printShowInstance(
t.Printf(" Groups:\t%s\n", strings.Join(config.Groups, ", "))
}
if config.Container != nil {
- params := config.Container
- if params.Home != nil {
- t.Printf(" Home:\t%s\n", params.Home)
+ if config.Container.Home != nil {
+ t.Printf(" Home:\t%s\n", config.Container.Home)
}
- if params.Hostname != "" {
- t.Printf(" Hostname:\t%s\n", params.Hostname)
+ if config.Container.Hostname != "" {
+ t.Printf(" Hostname:\t%s\n", config.Container.Hostname)
}
- flags := params.Flags.String()
+ flags := config.Container.Flags.String()
// this is included in the upper hst.Config struct but is relevant here
const flagDirectWayland = "directwl"
@@ -105,11 +110,11 @@ func printShowInstance(
}
t.Printf(" Flags:\t%s\n", flags)
- if params.Path != nil {
- t.Printf(" Path:\t%s\n", params.Path)
+ if config.Container.Path != nil {
+ t.Printf(" Path:\t%s\n", config.Container.Path)
}
- if len(params.Args) > 0 {
- t.Printf(" Arguments:\t%s\n", strings.Join(params.Args, " "))
+ if len(config.Container.Args) > 0 {
+ t.Printf(" Arguments:\t%s\n", strings.Join(config.Container.Args, " "))
}
}
t.Printf("\n")
diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go
index 98ca8061..b9344b53 100644
--- a/cmd/hakurei/print_test.go
+++ b/cmd/hakurei/print_test.go
@@ -59,6 +59,7 @@ func TestPrintShowInstance(t *testing.T) {
want string
valid bool
}{
+ {"nil", nil, nil, false, false, "Error: invalid configuration!\n\n", false},
{"config", nil, hst.Template(), false, false, `App
Identity: 9 (org.chromium.Chromium)
Enablements: wayland, dbus, pulseaudio