core_trap.sh 732 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. # LinuxGSM core_trap.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles CTRL-C trap to give an exit code.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_exit_trap() {
  9. local saved_exit_status=$?
  10. echo -e ""
  11. if [ -z "${exitcode}" ]; then
  12. exitcode=${saved_exit_status}
  13. fi
  14. if [ -z "${exitcode}" ]; then
  15. exitcode=0
  16. fi
  17. if [ "$(type -t fn_stop_warn_players_cancel)" == "function" ]; then
  18. fn_stop_warn_players_cancel
  19. fi
  20. # CTRL-C exits LinuxGSM, including while one command is running another (e.g. restart running stop).
  21. unset exitbypass
  22. core_exit.sh
  23. }
  24. # trap to give an exit code.
  25. trap fn_exit_trap INT