Skip to content

Commit e5b7c66

Browse files
committed
fix: remove Setsid from runWithoutReap to restore TTY
Commit 2ca0537 introduced Setsid=true in runWithoutReap(), which creates a new session for the child process and detaches it from the controlling terminal. This causes bash to fail with: bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell Setsid is only needed in runAndReap() where rootlesskit acts as init and needs session isolation for zombie reaping via Wait4(-1, ...). In the non-reaping path, the child should inherit the parent session to retain access to the TTY. Pdeathsig (PR_SET_PDEATHSIG) does not require Setsid. An integration test for runWithoutReap is added to prevent regressions. Fixes #557 Signed-off-by: fahed dorgaa <fahed.dorgaa@gmail.com>
1 parent 050dfb2 commit e5b7c66

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/main.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ jobs:
5454
run: docker run --rm --net=none --privileged rootlesskit:test-integration ./integration-systemd-socket.sh
5555
- name: "Integration test: pdeathsig"
5656
run: docker run --rm --privileged rootlesskit:test-integration ./integration-pdeathsig.sh
57+
- name: "Integration test: runWithoutReap"
58+
run: docker run --rm --privileged rootlesskit:test-integration ./integration-run-without-reap.sh
5759
- name: "Integration test: Network (network driver=slirp4netns)"
5860
run: |
5961
docker run --rm --privileged rootlesskit:test-integration ./integration-net.sh slirp4netns
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Integration test for runWithoutReap (--reaper=false path).
3+
# Regression test for https://github.com/rootless-containers/rootlesskit/issues/557
4+
source $(realpath $(dirname $0))/common.inc.sh
5+
6+
INFO "Testing runWithoutReap: command execution"
7+
out=$($ROOTLESSKIT --reaper=false echo hello 2>&1)
8+
if ! echo "$out" | grep -q "hello"; then
9+
ERROR "expected 'hello' in output, got: $out"
10+
exit 1
11+
fi
12+
13+
INFO "Testing runWithoutReap: exit code propagation"
14+
set +e
15+
$ROOTLESSKIT --reaper=false sh -c "exit 42" >/dev/null 2>&1
16+
code=$?
17+
set -e
18+
if [ $code != 42 ]; then
19+
ERROR "expected exit code 42, got $code"
20+
exit 1
21+
fi
22+
23+
INFO "Testing runWithoutReap: TTY preservation"
24+
# Use script(1) to allocate a PTY; verify the child sees a TTY
25+
# and does not print "cannot set terminal process group" (issue #557).
26+
tmp=$(mktemp -d)
27+
script -qec "$ROOTLESSKIT --reaper=false sh -c 'tty; echo DONE'" "$tmp/typescript" > "$tmp/out" 2>&1
28+
if grep -qi "cannot set terminal process group" "$tmp/out"; then
29+
ERROR "child lost its controlling terminal (setsid regression)"
30+
cat "$tmp/out"
31+
rm -rf "$tmp"
32+
exit 1
33+
fi
34+
if ! grep -q "DONE" "$tmp/out"; then
35+
ERROR "child did not complete"
36+
cat "$tmp/out"
37+
rm -rf "$tmp"
38+
exit 1
39+
fi
40+
rm -rf "$tmp"
41+
42+
INFO "===== All runWithoutReap tests passed ====="

pkg/child/child.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ func setMountPropagation(propagation string) error {
542542
}
543543

544544
func runWithoutReap(cmd *exec.Cmd) error {
545-
cmd.SysProcAttr.Setsid = true
546545
if err := cmd.Start(); err != nil {
547546
return err
548547
}

0 commit comments

Comments
 (0)