fix: prevent graceful shutdown message on normal exit (#9244)

This commit is contained in:
Teppei Fukuda
2025-07-25 12:51:40 +04:00
committed by GitHub
parent 77bab7b6d2
commit 6095984d53
2 changed files with 3 additions and 4 deletions

View File

@@ -42,8 +42,7 @@ func run() error {
}
// Set up signal handling for graceful shutdown
ctx, stop := commands.NotifyContext(context.Background())
defer stop()
ctx := commands.NotifyContext(context.Background())
app := commands.NewApp()
return app.ExecuteContext(ctx)

View File

@@ -15,7 +15,7 @@ import (
// When a signal is received, Trivy will attempt to gracefully shut down by canceling
// the context and waiting for all operations to complete. If users want to force an
// immediate exit, they can send a second SIGINT or SIGTERM signal.
func NotifyContext(parent context.Context) (context.Context, context.CancelFunc) {
func NotifyContext(parent context.Context) context.Context {
ctx, stop := signal.NotifyContext(parent, os.Interrupt, syscall.SIGTERM)
// Start a goroutine to handle cleanup when context is done
@@ -33,5 +33,5 @@ func NotifyContext(parent context.Context) (context.Context, context.CancelFunc)
stop()
}()
return ctx, stop
return ctx
}