Ver código fonte

When ctrl-C is pressed, ensure Borg actually exits (#1015).

Dan Helfman 3 meses atrás
pai
commit
2a16ffab1b
3 arquivos alterados com 9 adições e 3 exclusões
  1. 1 0
      NEWS
  2. 3 0
      borgmatic/signals.py
  3. 5 3
      tests/unit/test_signals.py

+ 1 - 0
NEWS

@@ -6,6 +6,7 @@
    using an environment variable.
  * #1013: Send database passwords to MongoDB via anonymous pipe, which is more secure than using
    "--password" on the command-line.
+ * #1015: When ctrl-C is pressed, ensure Borg actually exits.
  * Add a "verify_tls" option to the Uptime Kuma monitoring hook for disabling TLS verification.
 
 1.9.12

+ 3 - 0
borgmatic/signals.py

@@ -24,6 +24,9 @@ def handle_signal(signal_number, frame):
         logger.critical('Exiting due to TERM signal')
         sys.exit(EXIT_CODE_FROM_SIGNAL + signal.SIGTERM)
     elif signal_number == signal.SIGINT:
+        # Borg doesn't always exit on a SIGINT, so give it a little encouragement.
+        os.killpg(os.getpgrp(), signal.SIGTERM)
+
         raise KeyboardInterrupt()
 
 

+ 5 - 3
tests/unit/test_signals.py

@@ -26,7 +26,7 @@ def test_handle_signal_bails_on_recursion():
 def test_handle_signal_exits_on_sigterm():
     signal_number = module.signal.SIGTERM
     frame = flexmock(f_back=flexmock(f_code=flexmock(co_name='something')))
-    flexmock(module.os).should_receive('getpgrp').and_return(flexmock)
+    flexmock(module.os).should_receive('getpgrp').and_return(flexmock())
     flexmock(module.os).should_receive('killpg')
     flexmock(module.sys).should_receive('exit').with_args(
         module.EXIT_CODE_FROM_SIGNAL + signal_number
@@ -38,8 +38,10 @@ def test_handle_signal_exits_on_sigterm():
 def test_handle_signal_raises_on_sigint():
     signal_number = module.signal.SIGINT
     frame = flexmock(f_back=flexmock(f_code=flexmock(co_name='something')))
-    flexmock(module.os).should_receive('getpgrp').and_return(flexmock)
-    flexmock(module.os).should_receive('killpg')
+    process_group = flexmock()
+    flexmock(module.os).should_receive('getpgrp').and_return(process_group)
+    flexmock(module.os).should_receive('killpg').with_args(process_group, module.signal.SIGINT)
+    flexmock(module.os).should_receive('killpg').with_args(process_group, module.signal.SIGTERM)
     flexmock(module.sys).should_receive('exit').never()
 
     with pytest.raises(KeyboardInterrupt):