metropolis/node/core: fix invalid write in console setup
When configuring the console writers, we are iterating over a slice of
console structs, this is fine by itself, but we are also storing a
reference to the logtree reader. Since we are iterating over a struct
value and aren't using a pointer, this write won't persist into the
underlying slice and we cannot close the reader anymore. By using a
pointer to a struct instead of the raw value the issue is fixed.
Change-Id: Iaf753345cd275a03aecf9748b344c60eefcf9d69
Reviewed-on: https://review.monogon.dev/c/monogon/+/2973
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/cloud/agent/main.go b/cloud/agent/main.go
index cdd5dc1..16d5b17 100644
--- a/cloud/agent/main.go
+++ b/cloud/agent/main.go
@@ -3,7 +3,6 @@
import (
"context"
"fmt"
- "io"
"os"
"regexp"
@@ -33,8 +32,8 @@
consoles["ttyS0"] = true
lt := logtree.New()
- for p := range consoles {
- f, err := os.OpenFile("/dev/"+p, os.O_WRONLY, 0)
+ for path := range consoles {
+ f, err := os.OpenFile("/dev/"+path, os.O_WRONLY, 0)
if err != nil {
continue
}
@@ -42,12 +41,12 @@
if err != nil {
panic(fmt.Errorf("could not set up root log reader: %v", err))
}
- go func(path string, f io.Writer) {
+ go func() {
for {
p := <-reader.Stream
fmt.Fprintf(f, "%s\n", p.String())
}
- }(p, f)
+ }()
}
sCtx := context.Background()