sigint1.tests 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # What should happen if non-interactive shell gets SIGINT?
  2. (sleep 1; echo Sending SIGINT to main shell PID; exec kill -INT $$) &
  3. # We create a child which exits with 0 even on SIGINT
  4. # (The complex command is necessary only if SIGINT is generated by ^C,
  5. # in this testcase even bare "sleep 2" would do because
  6. # in the testcase we don't send SIGINT *to the child*...)
  7. $THIS_SH -c 'trap "exit 0" SIGINT; sleep 2'
  8. # In one second, we (main shell) get SIGINT here.
  9. # The question is whether we should, or should not, exit.
  10. # bash will not stop here. It will execute next command(s).
  11. # The rationale for this is described here:
  12. # http://www.cons.org/cracauer/sigint.html
  13. #
  14. # Basically, bash will not exit on SIGINT immediately if it waits
  15. # for a child. It will wait for the child to exit.
  16. # If child exits NOT by dying on SIGINT, then bash will not exit.
  17. #
  18. # The idea is that the following script:
  19. # | emacs file.txt
  20. # | more cmds
  21. # User may use ^C to interrupt editor's ops like search. But then
  22. # emacs exits normally. User expects that script doesn't stop.
  23. #
  24. # This is a nice idea, but detecting "did process really exit
  25. # with SIGINT?" is racy. Consider:
  26. # | bash -c 'while true; do /bin/true; done'
  27. # When ^C is pressed while bash waits for /bin/true to exit,
  28. # it may happen that /bin/true exits with exitcode 0 before
  29. # ^C is delivered to it as SIGINT. bash will see SIGINT, then
  30. # it will see that child exited with 0, and bash will NOT EXIT.
  31. # Therefore we do not implement bash behavior.
  32. # I'd say that emacs need to put itself into a separate pgrp
  33. # to isolate shell from getting stray SIGINTs from ^C.
  34. echo Next command after SIGINT was executed