Skip to content

Commit

Permalink
[interactive] Set signal state for SIGTTIN, SIGTTOU, etc.
Browse files Browse the repository at this point in the history
Apparently job control shells need this.  Still needs more testing.

Also test signal state against bin/osh.
  • Loading branch information
Andy C committed Feb 4, 2022
1 parent 39538f9 commit 830648a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions core/pyos.py
Expand Up @@ -271,18 +271,24 @@ def __call__(self, sig_num, unused_frame):
def SignalState_AfterForkingChild():
# type: () -> None
"""Not a member of SignalState since we didn't do dependency injection."""
# Respond to Ctrl-\ (core dump)
signal.signal(signal.SIGQUIT, signal.SIG_DFL)

# Python sets SIGPIPE handler to SIG_IGN by default. Child processes
# shouldn't have this.
# https://docs.python.org/2/library/signal.html
# See Python/pythonrun.c.
signal.signal(signal.SIGPIPE, signal.SIG_DFL)

# Respond to Ctrl-\ (core dump)
signal.signal(signal.SIGQUIT, signal.SIG_DFL)

# Child processes should get Ctrl-Z.
signal.signal(signal.SIGTSTP, signal.SIG_DFL)

# More signals from
# https://www.gnu.org/software/libc/manual/html_node/Launching-Jobs.html
signal.signal(signal.SIGTTOU, signal.SIG_DFL)
signal.signal(signal.SIGTTIN, signal.SIG_DFL)
signal.signal(signal.SIGCHLD, signal.SIG_DFL)


class SignalState(object):
"""All changes to global signal state go through this object."""
Expand All @@ -306,6 +312,12 @@ def InitInteractiveShell(self, display):
# This prevents Ctrl-Z from suspending OSH in interactive mode.
signal.signal(signal.SIGTSTP, signal.SIG_IGN)

# More signals from
# https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html
signal.signal(signal.SIGTTOU, signal.SIG_IGN)
signal.signal(signal.SIGTTIN, signal.SIG_IGN)
signal.signal(signal.SIGCHLD, signal.SIG_IGN)

# Register a callback to receive terminal width changes.
# NOTE: In line_input.c, we turned off rl_catch_sigwinch.

Expand Down
4 changes: 2 additions & 2 deletions devtools/sigparse.sh
Expand Up @@ -34,7 +34,7 @@ report() {
}

compare-shells() {
local -a shells=(bash dash mksh zsh osh)
local -a shells=(bash dash mksh zsh bin/osh)

# Hm non-interactive shells have consistency.
# SIGCHLD and SIGINT are caught in bash, dash, zsh, mksh. mksh catches
Expand Down Expand Up @@ -62,7 +62,7 @@ compare-shells() {

local more_flags=''
case $sh in
(bash|osh)
(bash|bin/osh)
more_flags='--rcfile /dev/null'
;;
esac
Expand Down

0 comments on commit 830648a

Please sign in to comment.