Skip to content

UnixLocal PTY children can inherit ignored SIGINT and miss Ctrl-C interrupts #3074

@Aphroq

Description

@Aphroq

Summary

UnixLocalSandboxSession PTY children appear to inherit the parent process SIGINT disposition. If the parent is temporarily ignoring SIGINT, writing \x03 to a TTY-backed subprocess does not interrupt the child as expected.

Reproduction

The existing PTY interrupt behavior can fail with a long-running TTY process such as sleep 30 when the parent process is ignoring SIGINT.

A minimal repro shape is:

  1. Set the parent process handler for SIGINT to SIG_IGN
  2. Start a PTY-backed subprocess via UnixLocalSandboxSession.pty_exec_start(..., tty=True)
  3. Write \x03 with pty_write_stdin
  4. Observe that the subprocess remains alive instead of exiting with signal SIGINT

Expected behavior

PTY-backed children should treat Ctrl-C as an interrupt regardless of whether the parent process is temporarily ignoring SIGINT.

Actual behavior

The child can inherit the ignored SIGINT disposition, so terminal-generated Ctrl-C is ignored and the subprocess remains running.

Root cause hypothesis

In the UnixLocal PTY path, the child preexec_fn creates a new session and sets the controlling terminal, but it does not restore SIGINT to SIG_DFL before exec. That makes PTY behavior depend on the parent's current signal disposition.

Proposed fix

Reset SIGINT to SIG_DFL in the PTY child preexec_fn before exec, and add a regression test that temporarily sets the parent handler to SIG_IGN and verifies that \x03 still interrupts the child.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions