init: update listeners when pressing <ENTER> on the serial console

This is useful when the network doesn’t come up correctly: you can connect a
network cable between your computer and the gokrazy machine, press <ENTER> on
the serial console and connect to gokrazy via its IPv6 link-local address (to
find the address, use ping6 ff02::1%eth0).
This commit is contained in:
Michael Stapelberg 2018-06-12 22:22:47 +02:00
parent 34f12d9ada
commit 238bbfa55e

View File

@ -8,6 +8,7 @@
package gokrazy
import (
"bufio"
"fmt"
"io/ioutil"
"log"
@ -149,6 +150,18 @@ func Supervise(commands []*exec.Cmd) error {
}
}()
go func() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if err := updateListeners("80"); err != nil {
log.Printf("updating listeners: %v", err)
}
}
if err := scanner.Err(); err != nil {
log.Print(err)
}
}()
return nil
}