Skip to content

Commit a8170cc

Browse files
committed
Do not create new Unix session for subprocesses
This fixes a bug where subprocesses would not be terminated upon termination of `litani run-build`. Prior to this commit, every Litani job would run its command in a fresh Unix session. This disconnected the command from the controlling terminal, such that a signal delivered from the terminal would not reach the command. Thus, users who sent INT to `litani run-build` by pressing Ctrl-C would observe that `litani run-build`, `ninja`, and all of the `litani exec` invocations would terminate, but the job commands would be reparented to init(1) and continue to run with no controlling terminal. This commit ensures that job commands once again receive the INT, TERM, and KILL signals. This reverts commit 241c5e8.
1 parent f8d6079 commit a8170cc

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/process.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import logging
2121
import os
2222
import platform
23-
import signal
2423
import subprocess
2524
import sys
2625

@@ -219,19 +218,18 @@ async def __call__(self):
219218

220219
proc = await asyncio.create_subprocess_shell(
221220
self.command, stdout=asyncio.subprocess.PIPE, stderr=pipe,
222-
cwd=self.cwd, env=env, start_new_session=True)
221+
cwd=self.cwd, env=env)
223222
self.proc = proc
224223

225224
timeout_reached = False
226225
try:
227226
out, err = await asyncio.wait_for(
228227
proc.communicate(), timeout=self.timeout)
229228
except asyncio.TimeoutError:
230-
pgid = os.getpgid(proc.pid)
231-
os.killpg(pgid, signal.SIGTERM)
229+
proc.terminate()
232230
await asyncio.sleep(1)
233231
try:
234-
os.killpg(pgid, signal.SIGKILL)
232+
proc.kill()
235233
except ProcessLookupError:
236234
pass
237235
out, err = await proc.communicate()

0 commit comments

Comments
 (0)