From b9a3dd63ad6f3e4c6db7f8142bd903f0401a592d Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Thu, 26 Sep 2024 16:46:11 +0300 Subject: [PATCH] Always start conversion process in new session Start the conversion process in a new session, so that we can later on kill the process group, without killing the controlling script (i.e., the Dangezone UI). This should not affect the conversion process in any other way. --- dangerzone/isolation_provider/base.py | 5 +++++ dangerzone/isolation_provider/container.py | 3 +++ dangerzone/isolation_provider/dummy.py | 2 +- dangerzone/isolation_provider/qubes.py | 3 +++ tests/isolation_provider/test_dummy.py | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index 308a05e..6d9a082 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -259,6 +259,11 @@ class IsolationProvider(ABC): ) -> Iterator[subprocess.Popen]: """Start a conversion process, pass it to the caller, and then clean it up.""" p = self.start_doc_to_pixels_proc(document) + if platform.system() != "Windows": + assert os.getpgid(p.pid) != os.getpgid( + os.getpid() + ), "Parent shares same PGID with child" + try: yield p except errors.ConverterProcException as e: diff --git a/dangerzone/isolation_provider/container.py b/dangerzone/isolation_provider/container.py index 42c48f1..166c285 100644 --- a/dangerzone/isolation_provider/container.py +++ b/dangerzone/isolation_provider/container.py @@ -267,6 +267,9 @@ class Container(IsolationProvider): stdout=subprocess.PIPE, stderr=self.proc_stderr, startupinfo=startupinfo, + # Start the conversion process in a new session, so that we can later on + # kill the process group, without killing the controlling script. + start_new_session=True, ) def exec_container( diff --git a/dangerzone/isolation_provider/dummy.py b/dangerzone/isolation_provider/dummy.py index 45260d2..cd21743 100644 --- a/dangerzone/isolation_provider/dummy.py +++ b/dangerzone/isolation_provider/dummy.py @@ -73,7 +73,7 @@ class Dummy(IsolationProvider): pass def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: - return subprocess.Popen("True") + return subprocess.Popen("True", start_new_session=True) def terminate_doc_to_pixels_proc( self, document: Document, p: subprocess.Popen diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index aa59006..34cc900 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -67,6 +67,9 @@ class Qubes(IsolationProvider): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, + # Start the conversion process in a new session, so that we can later on + # kill the process group, without killing the controlling script. + start_new_session=True, ) if dev_mode: diff --git a/tests/isolation_provider/test_dummy.py b/tests/isolation_provider/test_dummy.py index e03a6ca..9ba155d 100644 --- a/tests/isolation_provider/test_dummy.py +++ b/tests/isolation_provider/test_dummy.py @@ -25,6 +25,7 @@ class DummyWait(Dummy): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + start_new_session=True, ) def terminate_doc_to_pixels_proc(