blob: cb7dee6429c50b26b7290713e711042c90a2caf3 [file] [log] [blame]
Serge Bazanskif71fe922023-03-22 01:10:37 +01001package main
2
3import (
4 "fmt"
5 "os"
6)
7
8var logC = make(chan string)
9
10// logPiper pipes log entries submitted via logf and panicf into whatever
11// consoles are available to the system.
12func logPiper() {
13 var consoles []*os.File
14 for _, p := range []string{"/dev/tty0", "/dev/ttyS0"} {
15 f, err := os.OpenFile(p, os.O_WRONLY, 0)
16 if err != nil {
17 continue
18 }
19 consoles = append(consoles, f)
20 }
21
22 for {
23 s := <-logC
24 for _, c := range consoles {
25 fmt.Fprintf(c, "%s\n", s)
26 }
27 }
28}
29
30// logf logs some format/args into the active consoles.
31func logf(format string, args ...any) {
32 s := fmt.Sprintf(format, args...)
33 logC <- s
34}
35
36// panicf aborts the installation process with a given format/args.
37func panicf(format string, args ...any) {
38 s := fmt.Sprintf(format, args...)
39 // We don't need to print `s` here, as it's gonna get printed by the recovery
40 // code in main.
41 panic(s)
42}