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
This commit is contained in:
Thomas Waldmann 2022-08-06 12:48:54 +02:00
parent 0ab82d57e4
commit 4d570497be
3 changed files with 17 additions and 6 deletions

View File

@ -26,7 +26,7 @@ from ..helpers import dir_is_tagged
from ..helpers import log_multi from ..helpers import log_multi
from ..helpers import basic_json_data, json_print from ..helpers import basic_json_data, json_print
from ..helpers import flags_root, flags_dir, flags_special_follow, flags_special from ..helpers import flags_root, flags_dir, flags_special_follow, flags_special
from ..helpers import sig_int from ..helpers import sig_int, ignore_sigint
from ..helpers import iter_separated from ..helpers import iter_separated
from ..patterns import PatternMatcher from ..patterns import PatternMatcher
from ..platform import get_flags from ..platform import get_flags
@ -68,7 +68,7 @@ class CreateMixIn:
if not dry_run: if not dry_run:
try: try:
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: except (FileNotFoundError, PermissionError) as e:
self.print_error("Failed to execute command: %s", e) self.print_error("Failed to execute command: %s", e)
return self.exit_code return self.exit_code
@ -89,7 +89,7 @@ class CreateMixIn:
paths_sep = eval_escapes(args.paths_delimiter) if args.paths_delimiter is not None else "\n" paths_sep = eval_escapes(args.paths_delimiter) if args.paths_delimiter is not None else "\n"
if args.paths_from_command: if args.paths_from_command:
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: except (FileNotFoundError, PermissionError) as e:
self.print_error("Failed to execute command: %s", e) self.print_error("Failed to execute command: %s", e)
return self.exit_code return self.exit_code

View File

@ -31,7 +31,8 @@ from .parseformat import Location, location_validator, archivename_validator
from .parseformat import BaseFormatter, ArchiveFormatter, ItemFormatter, file_status from .parseformat import BaseFormatter, ArchiveFormatter, ItemFormatter, file_status
from .parseformat import swidth_slice, ellipsis_truncate from .parseformat import swidth_slice, ellipsis_truncate
from .parseformat import BorgJsonEncoder, basic_json_data, json_print, json_dump, prepare_dump_dict from .parseformat import BorgJsonEncoder, basic_json_data, json_print, json_dump, prepare_dump_dict
from .process import daemonize, daemonizing, signal_handler, raising_signal_handler, sig_int, SigHup, SigTerm from .process import daemonize, daemonizing
from .process import signal_handler, raising_signal_handler, sig_int, ignore_sigint, SigHup, SigTerm
from .process import popen_with_error_handling, is_terminal, prepare_subprocess_env, create_filter_process from .process import popen_with_error_handling, is_terminal, prepare_subprocess_env, create_filter_process
from .progress import ProgressIndicatorPercent, ProgressIndicatorEndless, ProgressIndicatorMessage from .progress import ProgressIndicatorPercent, ProgressIndicatorEndless, ProgressIndicatorMessage
from .time import parse_timestamp, timestamp, safe_timestamp, safe_s, safe_ns, MAX_S, SUPPORT_32BIT_PLATFORMS from .time import parse_timestamp, timestamp, safe_timestamp, safe_s, safe_ns, MAX_S, SUPPORT_32BIT_PLATFORMS

View File

@ -336,11 +336,21 @@ def create_filter_process(cmd, stream, stream_close, inbound=True):
# for us to do something while we block on the process for something different. # for us to do something while we block on the process for something different.
if inbound: if inbound:
proc = popen_with_error_handling( proc = popen_with_error_handling(
cmd, stdout=subprocess.PIPE, stdin=filter_stream, log_prefix="filter-process: ", env=env cmd,
stdout=subprocess.PIPE,
stdin=filter_stream,
log_prefix="filter-process: ",
env=env,
preexec_fn=ignore_sigint,
) )
else: else:
proc = popen_with_error_handling( proc = popen_with_error_handling(
cmd, stdin=subprocess.PIPE, stdout=filter_stream, log_prefix="filter-process: ", env=env cmd,
stdin=subprocess.PIPE,
stdout=filter_stream,
log_prefix="filter-process: ",
env=env,
preexec_fn=ignore_sigint,
) )
if not proc: if not proc:
raise Error(f"filter {cmd}: process creation failed") raise Error(f"filter {cmd}: process creation failed")