@@ -117,6 +117,10 @@ type Config struct {
117
117
// NetNS represents the path to a network namespace handle. If present, the
118
118
// application will use this to join the associated network namespace
119
119
NetNS string
120
+
121
+ // ForwardSignals is an optional list of signals to catch and forward to
122
+ // firecracker. If not provided, the default signals will be used.
123
+ ForwardSignals []os.Signal
120
124
}
121
125
122
126
// Validate will ensure that the required fields are set and that
@@ -481,20 +485,7 @@ func (m *Machine) startVMM(ctx context.Context) error {
481
485
close (errCh )
482
486
}()
483
487
484
- // Set up a signal handler and pass INT, QUIT, and TERM through to firecracker
485
- sigchan := make (chan os.Signal )
486
- signal .Notify (sigchan , os .Interrupt ,
487
- syscall .SIGQUIT ,
488
- syscall .SIGTERM ,
489
- syscall .SIGHUP ,
490
- syscall .SIGABRT )
491
- m .logger .Debugf ("Setting up signal handler" )
492
- go func () {
493
- if sig , ok := <- sigchan ; ok {
494
- m .logger .Printf ("Caught signal %s" , sig )
495
- m .cmd .Process .Signal (sig )
496
- }
497
- }()
488
+ m .setupSignals ()
498
489
499
490
// Wait for firecracker to initialize:
500
491
err = m .waitForSocket (time .Duration (m .client .firecrackerInitTimeout )* time .Second , errCh )
@@ -513,8 +504,6 @@ func (m *Machine) startVMM(ctx context.Context) error {
513
504
m .fatalErr = err
514
505
}
515
506
516
- signal .Stop (sigchan )
517
- close (sigchan )
518
507
close (m .exitCh )
519
508
}()
520
509
@@ -885,3 +874,38 @@ func (m *Machine) waitForSocket(timeout time.Duration, exitchan chan error) erro
885
874
}
886
875
}
887
876
}
877
+
878
+ // Set up a signal handler to pass through to firecracker
879
+ func (m * Machine ) setupSignals () {
880
+ signals := m .Cfg .ForwardSignals
881
+
882
+ if signals == nil {
883
+ signals = []os.Signal {
884
+ os .Interrupt ,
885
+ syscall .SIGQUIT ,
886
+ syscall .SIGTERM ,
887
+ syscall .SIGHUP ,
888
+ syscall .SIGABRT ,
889
+ }
890
+ }
891
+
892
+ if len (signals ) == 0 {
893
+ return
894
+ }
895
+
896
+ m .logger .Debugf ("Setting up signal handler: %v" , signals )
897
+ sigchan := make (chan os.Signal )
898
+ signal .Notify (sigchan , signals ... )
899
+
900
+ go func () {
901
+ select {
902
+ case sig := <- sigchan :
903
+ m .logger .Printf ("Caught signal %s" , sig )
904
+ m .cmd .Process .Signal (sig )
905
+ case <- m .exitCh :
906
+ }
907
+
908
+ signal .Stop (sigchan )
909
+ close (sigchan )
910
+ }()
911
+ }
0 commit comments