Hold a fatal error on the framebuffer and reboot in five minutes rather than exiting, since init's death drops the kernel's panic screen over the cause
This commit is contained in:
@@ -457,6 +457,7 @@ func (d *direction) start(wg *sync.WaitGroup, done *atomic.Bool, rxReady *sync.W
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
w.run(done)
|
||||
}()
|
||||
}
|
||||
@@ -473,6 +474,7 @@ func (d *direction) start(wg *sync.WaitGroup, done *atomic.Bool, rxReady *sync.W
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
w.run(done)
|
||||
}()
|
||||
}
|
||||
@@ -481,6 +483,7 @@ func (d *direction) start(wg *sync.WaitGroup, done *atomic.Bool, rxReady *sync.W
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
sender.run(done, startTx)
|
||||
}()
|
||||
|
||||
@@ -488,12 +491,14 @@ func (d *direction) start(wg *sync.WaitGroup, done *atomic.Bool, rxReady *sync.W
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
receiver.run(done)
|
||||
}()
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
d.poller.run(done, startTx)
|
||||
}()
|
||||
}
|
||||
@@ -536,10 +541,8 @@ func main() {
|
||||
nsPerM := flag.Float64("ns-per-m", 4.85, "mean of both directions, per metre of cable")
|
||||
flag.Parse()
|
||||
|
||||
// Nothing here is recoverable by the time it reaches this point, and as PID 1
|
||||
// a plain exit would panic the kernel anyway with less to show for it.
|
||||
if err := run(*aName, *bName, *nsPerM); err != nil {
|
||||
panic(err)
|
||||
fatal(err)
|
||||
}
|
||||
// A clean return is ctrl-alt-delete, which the kernel hands PID 1 as a
|
||||
// SIGINT. Exiting on it would panic the kernel over the reboot it was asking
|
||||
@@ -581,7 +584,16 @@ func (s *sampler) run(done *atomic.Bool, startTx <-chan struct{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func run(aName, bName string, nsPerM float64) error {
|
||||
func run(aName, bName string, nsPerM float64) (err error) {
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
if os.Getpid() != 1 {
|
||||
panic(p)
|
||||
}
|
||||
err = fmt.Errorf("%v", p)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := reportChecks("BOOT", bootstrap()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -670,6 +682,7 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
samp.run(&done, startTx)
|
||||
}()
|
||||
// Not gated on startTx: the cycle and the connected verdict are wanted the
|
||||
@@ -677,6 +690,7 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer holdPanic()
|
||||
noise.run(&done)
|
||||
}()
|
||||
// Every return from here on stops the workers before the deferred closes
|
||||
@@ -693,7 +707,17 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
}
|
||||
wg.Wait()
|
||||
}()
|
||||
rxReady.Wait()
|
||||
// A worker that panics before signalling ready would hang a bare Wait.
|
||||
ready := make(chan struct{})
|
||||
go func() {
|
||||
rxReady.Wait()
|
||||
close(ready)
|
||||
}()
|
||||
select {
|
||||
case <-ready:
|
||||
case p := <-fatalCh:
|
||||
return fmt.Errorf("%v", p)
|
||||
}
|
||||
|
||||
sig := make(chan os.Signal, 1)
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||
@@ -726,6 +750,8 @@ func run(aName, bName string, nsPerM float64) error {
|
||||
stats := &streamTable{cols: intervalCols, headerEvery: 20}
|
||||
for {
|
||||
select {
|
||||
case p := <-fatalCh:
|
||||
return fmt.Errorf("%v", p)
|
||||
case <-sig:
|
||||
return nil
|
||||
case <-space:
|
||||
|
||||
Reference in New Issue
Block a user