mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Add handling of interrupting signals to ETUI
Signed-off-by: Dan Luhring <dan.luhring@anchore.com>
This commit is contained in:
parent
8d838b18a8
commit
5370daf027
@ -23,7 +23,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/logger"
|
"github.com/anchore/syft/internal/logger"
|
||||||
|
|
||||||
@ -102,6 +104,8 @@ func OutputToEphemeralTUI(workerErrs <-chan error, subscription *partybus.Subscr
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
syftUIHandler := ui.NewHandler()
|
syftUIHandler := ui.NewHandler()
|
||||||
|
|
||||||
|
signals := interruptingSignals()
|
||||||
|
|
||||||
eventLoop:
|
eventLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -154,8 +158,23 @@ eventLoop:
|
|||||||
log.Errorf("cancelled (%+v)", err)
|
log.Errorf("cancelled (%+v)", err)
|
||||||
}
|
}
|
||||||
break eventLoop
|
break eventLoop
|
||||||
|
case <-signals:
|
||||||
|
break eventLoop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func interruptingSignals() chan os.Signal {
|
||||||
|
c := make(chan os.Signal, 1) // Note: A buffered channel is recommended for this; see https://golang.org/pkg/os/signal/#Notify
|
||||||
|
|
||||||
|
interruptions := []os.Signal{
|
||||||
|
syscall.SIGINT,
|
||||||
|
syscall.SIGTERM,
|
||||||
|
}
|
||||||
|
|
||||||
|
signal.Notify(c, interruptions...)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user