Skip to content

Commit

Permalink
Always start conversion process in new session
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apyrgio committed Oct 7, 2024
1 parent 8d856ff commit b9a3dd6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dangerzone/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ def doc_to_pixels_proc(
) -> 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:
Expand Down
3 changes: 3 additions & 0 deletions dangerzone/isolation_provider/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def exec(
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(
Expand Down
2 changes: 1 addition & 1 deletion dangerzone/isolation_provider/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def pixels_to_pdf(
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
Expand Down
3 changes: 3 additions & 0 deletions dangerzone/isolation_provider/qubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
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:
Expand Down
1 change: 1 addition & 0 deletions tests/isolation_provider/test_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
start_new_session=True,
)

def terminate_doc_to_pixels_proc(
Expand Down

0 comments on commit b9a3dd6

Please sign in to comment.