Skip to content

pty: Send SIGHUP to foreground process group when master is closed#12855

Merged
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tanyifeng:pty-sighup-on-master-close
Apr 16, 2026
Merged

pty: Send SIGHUP to foreground process group when master is closed#12855
copybara-service[bot] merged 1 commit intogoogle:masterfrom
tanyifeng:pty-sighup-on-master-close

Conversation

@tanyifeng
Copy link
Copy Markdown
Contributor

@tanyifeng tanyifeng commented Apr 2, 2026

pty: Send SIGHUP to foreground process group on master close

When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.

@tanyifeng
Copy link
Copy Markdown
Contributor Author

Reproducer

# In a gVisor container — child should be killed when expect exits
docker run --runtime=runsc --rm alpine sh -c '
apk add --no-cache expect procps >/dev/null 2>&1

cat > /tmp/test.exp << "END"
spawn sleep 300
expect timeout
END

expect -f /tmp/test.exp &
PID=$!
sleep 2

SLEEP_PID=$(ps -ef | awk "/sleep 300/ && !/awk|sh -c/ {print \$2}" | head -1)
echo "Sleep PID: $SLEEP_PID"

kill $PID 2>/dev/null
sleep 2

if [ -n "$SLEEP_PID" ] && kill -0 "$SLEEP_PID" 2>/dev/null; then
    echo "BUG: sleep process still running after expect exit"
else
    echo "OK: sleep process terminated"
fi
'

Before fix: sleep 300 remains running after expect exits.
After fix: sleep 300 receives SIGHUP and terminates, matching Linux behavior.

Comment thread pkg/sentry/fsimpl/devpts/devpts.go Outdated
@tanyifeng tanyifeng force-pushed the pty-sighup-on-master-close branch from 5042b00 to b773847 Compare April 14, 2026 14:28
@ayushr2 ayushr2 requested a review from shailend-g April 14, 2026 16:58
Comment thread test/syscalls/linux/pty.cc Outdated
When the PTY master is closed, send SIGHUPto the foreground
process group of the session that has the slave as its controlling
terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link)
behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet)
are never notified of the hangup and remain running indefinitely.

Signed-off-by: Tan Yifeng <yiftan@tencent.com>
@tanyifeng tanyifeng force-pushed the pty-sighup-on-master-close branch from b773847 to 1686126 Compare April 15, 2026 03:14
copybara-service Bot pushed a commit that referenced this pull request Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126
PiperOrigin-RevId: 900302848
copybara-service Bot pushed a commit that referenced this pull request Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126
PiperOrigin-RevId: 900302848
copybara-service Bot pushed a commit that referenced this pull request Apr 15, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126
PiperOrigin-RevId: 900302848
copybara-service Bot pushed a commit that referenced this pull request Apr 16, 2026
When the PTY master is closed, send SIGHUPto the foreground process group of the session that has the slave as its controlling terminal. This matches Linux's pty_close() -> tty_vhangup(tty->link) behavior (drivers/tty/pty.c).

Without this, child processes spawned via PTY (e.g. by expect/telnet) are never notified of the hangup and remain running indefinitely.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#12855 from tanyifeng:pty-sighup-on-master-close 1686126
PiperOrigin-RevId: 900302848
@copybara-service copybara-service Bot merged commit b5e83db into google:master Apr 16, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants