From a112a86e2222a85f910ec22d6e589f397d7dcbc4 Mon Sep 17 00:00:00 2001 From: Amaury Chamayou Date: Fri, 14 Jun 2019 10:56:35 +0100 Subject: [PATCH] Send SIGTERM to cchost if parent dies (#158) --- tests/infra/remote.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/infra/remote.py b/tests/infra/remote.py index 89a1d0d94..7c028de70 100644 --- a/tests/infra/remote.py +++ b/tests/infra/remote.py @@ -11,11 +11,25 @@ from contextlib import contextmanager import infra.path import json import uuid +import ctypes +import signal from loguru import logger as LOG DBG = os.getenv("DBG", "cgdb") +_libc = ctypes.CDLL("libc.so.6") + + +def _term_on_pdeathsig(): + # usr/include/linux/prctl.h: #define PR_SET_PDEATHSIG 1 + _libc.prctl(1, signal.SIGTERM) + + +def popen(*args, **kwargs): + kwargs["preexec_fn"] = _term_on_pdeathsig + return subprocess.Popen(*args, **kwargs) + @contextmanager def sftp_session(hostname): @@ -356,7 +370,7 @@ class LocalRemote(CmdMixin): LOG.info(f"[{self.hostname}] {cmd} (env: {self.env})") self.stdout = open(os.path.join(self.root, "out"), "wb") self.stderr = open(os.path.join(self.root, "err"), "wb") - self.proc = subprocess.Popen( + self.proc = popen( self.cmd, cwd=self.root, stdout=self.stdout,