瀏覽代碼

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
Thomas Waldmann 2 年之前
父節點
當前提交
7a31978c55
共有 2 個文件被更改,包括 5 次插入5 次删除
  1. 3 3
      src/borg/archiver.py
  2. 2 2
      src/borg/helpers/process.py

+ 3 - 3
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

+ 2 - 2
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