Skip to content

Commit

Permalink
fix: change so that second SIGINT signal immediately exits program (#…
Browse files Browse the repository at this point in the history
…2598)

## Description

This changes the behavior so that the second SIGINT signal immediately
exits. This is useful if a process is not quitting in context cancel or
if it is taking too long to quit.

## Related Issue

Relates to #2594 

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
phillebaba authored Jun 7, 2024
1 parent 245b36b commit 7ad3e53
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"context"
"embed"
"os"
"os/signal"
"syscall"

Expand All @@ -22,8 +23,22 @@ var cosignPublicKey string
var zarfSchema embed.FS

func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
first := true
for {
<-signalCh
if first {
first = false
cancel()
continue
}
os.Exit(1)
}
}()

config.CosignPublicKey = cosignPublicKey
lint.ZarfSchema = zarfSchema
Expand Down

0 comments on commit 7ad3e53

Please sign in to comment.