2017-01-24 23:15:38 +00:00
|
|
|
# vim: set filetype=expect:
|
|
|
|
#
|
|
|
|
# Test signal handling for interactive shells.
|
|
|
|
|
2020-03-01 21:27:34 +00:00
|
|
|
set pid [spawn $fish]
|
|
|
|
expect_prompt
|
|
|
|
|
2020-03-03 12:30:53 +00:00
|
|
|
# Verify that the fish_postexec handler is called after SIGINT.
|
|
|
|
send_line "function postexec --on-event fish_postexec; echo fish_postexec spotted; end"
|
|
|
|
expect_prompt
|
|
|
|
send_line read
|
|
|
|
expect -re "\\r\\n?read> $"
|
|
|
|
exec -- kill -INT $pid
|
|
|
|
expect "fish_postexec spotted"
|
2020-03-31 18:27:17 +00:00
|
|
|
expect_prompt
|
|
|
|
|
|
|
|
# Verify that the fish_kill_signal is set.
|
|
|
|
send_line "functions -e postexec; function postexec --on-event fish_postexec; echo fish_kill_signal \$fish_kill_signal; end"
|
|
|
|
expect_prompt
|
|
|
|
send_line "sleep 5"
|
|
|
|
sleep 0.100
|
|
|
|
exec -- pkill -INT sleep -P $pid
|
|
|
|
expect "fish_kill_signal 2"
|
|
|
|
expect_prompt
|
|
|
|
|
|
|
|
send_line "sleep 5"
|
|
|
|
sleep 0.100
|
|
|
|
exec -- pkill -TERM sleep -P $pid
|
|
|
|
expect "fish_kill_signal 15"
|
|
|
|
expect_prompt
|
2020-03-03 12:30:53 +00:00
|
|
|
|
2017-01-24 23:15:38 +00:00
|
|
|
# Verify that sending SIGHUP to the shell, such as will happen when the tty is
|
|
|
|
# closed by the terminal, terminates the shell and the foreground command and
|
|
|
|
# any background commands run from that shell.
|
|
|
|
send "sleep 130 &\r"
|
|
|
|
expect_prompt
|
|
|
|
send "sleep 131 &\r"
|
|
|
|
expect_prompt
|
|
|
|
send "sleep 132\r"
|
2018-03-24 17:15:56 +00:00
|
|
|
exec -- kill -HUP $pid
|
2017-01-24 23:15:38 +00:00
|
|
|
|
|
|
|
# Verify the spawned fish shell has exited.
|
|
|
|
catch {expect default exp_continue} output
|
|
|
|
wait
|
|
|
|
|
2018-03-24 17:15:56 +00:00
|
|
|
# Verify all child processes have been killed. We don't use `-p $pid` because
|
2017-01-24 23:15:38 +00:00
|
|
|
# if the shell has a bug the child processes might have been reparented to pid
|
|
|
|
# 1 rather than killed.
|
|
|
|
set status [catch {exec pgrep -l -f "sleep 13"} output]
|
|
|
|
if {$status == 0} {
|
|
|
|
puts stderr "Commands spawned by the shell still running after SIGHUP"
|
|
|
|
puts stderr $output
|
|
|
|
}
|