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

This commit is contained in:
Dan Helfman
2025-03-02 10:32:57 -08:00
parent 4b2f7e03af
commit 2a16ffab1b
3 changed files with 9 additions and 3 deletions
+1
View File
@@ -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
View File
@@ -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
View File
@@ -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):