Serge Bazanski | f71fe92 | 2023-03-22 01:10:37 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | ) |
| 7 | |
| 8 | var logC = make(chan string) |
| 9 | |
| 10 | // logPiper pipes log entries submitted via logf and panicf into whatever |
| 11 | // consoles are available to the system. |
| 12 | func 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. |
| 31 | func 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. |
| 37 | func 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 | } |