From 1c9ae819878a34bfc9b992f93d24b9fb625146d3 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 18 Nov 2020 10:29:03 -0800 Subject: [PATCH] Fix signal forwarding from borgmatic to Borg resulting in recursion traceback (#368). --- NEWS | 1 + borgmatic/signals.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 00fff24..0c708d8 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ * #355: Fix traceback when a database hook value is null in a configuration file. * #361: Merge override values when specifying the "--override" flag multiple times. The previous behavior was to take the value of the last "--override" flag only. + * #368: Fix signal forwarding from borgmatic to Borg resulting in recursion traceback. 1.5.10 * #347: Add hooks that run for the "extract" action: "before_extract" and "after_extract". diff --git a/borgmatic/signals.py b/borgmatic/signals.py index 51b9272..a8b4299 100644 --- a/borgmatic/signals.py +++ b/borgmatic/signals.py @@ -4,8 +4,13 @@ import signal def _handle_signal(signal_number, frame): # pragma: no cover ''' - Send the signal to all processes in borgmatic's process group, which includes child process. + Send the signal to all processes in borgmatic's process group, which includes child processes. ''' + # Prevent infinite signal handler recursion. If the parent frame is this very same handler + # function, we know we're recursing. + if frame.f_back.f_code.co_name == _handle_signal.__name__: + return + os.killpg(os.getpgrp(), signal_number)