From 7a31978c55067929436a9f6904e5f8e9c6b663f5 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 6 Aug 2022 12:48:54 +0200 Subject: [PATCH] ctrl-c must not kill other subprocesses, fixes #6912 There are some other places with subprocesses: - borg create --content-from-command - borg create --paths-from-command - (de)compression filter process of import-tar / export-tar --- src/borg/archiver.py | 6 +++--- src/borg/helpers/process.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 68f6cd233..8afc40792 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -73,7 +73,7 @@ try: from .helpers import umount from .helpers import flags_root, flags_dir, flags_special_follow, flags_special from .helpers import msgpack - from .helpers import sig_int + from .helpers import sig_int, ignore_sigint from .helpers import iter_separated from .helpers import get_tar_filter from .nanorst import rst_to_terminal @@ -527,7 +527,7 @@ class Archiver: if not dry_run: try: try: - proc = subprocess.Popen(args.paths, stdout=subprocess.PIPE) + proc = subprocess.Popen(args.paths, stdout=subprocess.PIPE, preexec_fn=ignore_sigint) except (FileNotFoundError, PermissionError) as e: self.print_error('Failed to execute command: %s', e) return self.exit_code @@ -546,7 +546,7 @@ class Archiver: paths_sep = eval_escapes(args.paths_delimiter) if args.paths_delimiter is not None else '\n' if args.paths_from_command: try: - proc = subprocess.Popen(args.paths, stdout=subprocess.PIPE) + proc = subprocess.Popen(args.paths, stdout=subprocess.PIPE, preexec_fn=ignore_sigint) except (FileNotFoundError, PermissionError) as e: self.print_error('Failed to execute command: %s', e) return self.exit_code diff --git a/src/borg/helpers/process.py b/src/borg/helpers/process.py index e58b919b6..3dd19c7a4 100644 --- a/src/borg/helpers/process.py +++ b/src/borg/helpers/process.py @@ -328,10 +328,10 @@ def create_filter_process(cmd, stream, stream_close, inbound=True): # for us to do something while we block on the process for something different. if inbound: proc = popen_with_error_handling(cmd, stdout=subprocess.PIPE, stdin=filter_stream, - log_prefix='filter-process: ', env=env) + log_prefix='filter-process: ', env=env, preexec_fn=ignore_sigint) else: proc = popen_with_error_handling(cmd, stdin=subprocess.PIPE, stdout=filter_stream, - log_prefix='filter-process: ', env=env) + log_prefix='filter-process: ', env=env, preexec_fn=ignore_sigint) if not proc: raise Error(f'filter {cmd}: process creation failed') stream = proc.stdout if inbound else proc.stdin