Skip to content

The agent that grows with you

fix(update): a timed-out probe on a host without perl is killed with its whole tree (review desk-noperl-timeout-leak)

Tekniumd549d5fb5c07
diff --git a/scripts/desktop-update/posix.sh b/scripts/desktop-update/posix.sh
index 2913120063d..7211725d5f5 100755
--- a/scripts/desktop-update/posix.sh
+++ b/scripts/desktop-update/posix.sh
@@ -183,7 +183,8 @@ run_bounded() { # seconds cmd... -> cmd's stdout; 124 when it had to be killed
if command -v perl >/dev/null 2>&1; then
perl -e 'setpgrp(0, 0); exec { $ARGV[0] } @ARGV or exit 127' "$@" > "$out" 2>/dev/null < /dev/null &
else
- "$@" > "$out" 2>/dev/null < /dev/null &
+ # No perl (minimal images): bash job control gives the job its own group.
+ set -m; "$@" > "$out" 2>/dev/null < /dev/null & set +m
fi
pid=$!
for ((i = 0; i < secs * 10; i++)); do kill -0 "$pid" 2>/dev/null || break; sleep 0.1; done
diff --git a/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py b/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py
index f8196ae9093..427eddb1e0f 100644
--- a/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py
+++ b/tests/scripts/desktop_update/test_desktop_update_posix_handoff_protocol.py
@@ -18,6 +18,7 @@ import os
from pathlib import Path
import re
import shlex
+import shutil
import signal
import subprocess
import time
@@ -381,15 +382,22 @@ def test_script_killed_before_the_delegate_line_appears_runs_no_update(tmp_path)
# ── bounded probes and the old-reader line-2 refresh ────────────────────────
-def test_timed_out_probe_is_killed_with_its_whole_process_tree(tmp_path):
[email protected]("perl", ["present", "absent"])
+def test_timed_out_probe_is_killed_with_its_whole_process_tree(tmp_path, perl):
body = POSIX.read_text(encoding="utf-8-sig")
found = re.search(r"^run_bounded\(\) \{.*?^\}\n", body, re.S | re.M)
assert found
run_bounded = found.group(0)
pidfile = tmp_path / "grandchild.pid"
+ env = {**os.environ, "TMPDIR": str(tmp_path)}
+ if perl == "absent": # a minimal image: only the tools the probe itself needs
+ bin_dir = tmp_path / "bin"; bin_dir.mkdir()
+ for tool in ("bash", "sleep", "mktemp", "rm", "cat"):
+ (bin_dir / tool).symlink_to(shutil.which(tool))
+ env["PATH"] = str(bin_dir)
code = (f"log() {{ :; }}\n{run_bounded}\n"
f"run_bounded 1 bash -c 'sleep 60 & echo $! > {shlex.quote(str(pidfile))}; wait'; echo \"rc=$?\"")
- out = subprocess.run(["bash", "-c", code], env={**os.environ, "TMPDIR": str(tmp_path)}, capture_output=True, text=True, encoding="utf-8", timeout=30)
+ out = subprocess.run([shutil.which("bash"), "-c", code], env=env, capture_output=True, text=True, encoding="utf-8", timeout=30)
assert "rc=124" in out.stdout, out
grandchild = int(pidfile.read_text(encoding="utf-8-sig"))
time.sleep(0.2)