Răsfoiți Sursa

exitcode trap

designed to give and exit code at anytime if ctrl-c is pressed
Daniel Gibbs 10 ani în urmă
părinte
comite
4716aeb182

+ 4 - 0
lgsm/functions/core_exit.sh

@@ -23,6 +23,8 @@ if [ -n "${exitcode}" ]&&[ "${exitcode}" != "0" ]; then
 		fn_script_log_warn "${function_selfname} exiting with code: ${exitcode}"
 	fi
 	fn_exit_dev_debug
+	# remove trap.
+	trap - INT
 	exit ${exitcode}
 elif [ -n "${exitbypass}" ]; then
 	unset exitbypass
@@ -30,6 +32,8 @@ else
 	fn_script_log_pass "${function_selfname} exiting with code: ${exitcode}"
 	exitcode=0
 	fn_exit_dev_debug
+	# remove trap.
+	trap - INT
 	exit ${exitcode}
 fi
 

+ 7 - 0
lgsm/functions/core_functions.sh

@@ -88,6 +88,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_core_dl
 }
 
+core_trap.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_core_dl
+}
+
 core_messages.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_core_dl
@@ -471,6 +476,8 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+# Calls the global Ctrl-C trap
+core_trap.sh
 
 # Calls on-screen messages
 core_messages.sh

+ 14 - 0
lgsm/functions/core_trap.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+# LGSM core_trap.sh function
+# Author: Daniel Gibbs
+# Website: https://gameservermanagers.com
+lgsm_version="210516"
+
+# Description: handles ctrl-C trap to give an exitcode.
+
+fn_exit_trap(){
+	core_exit.sh
+}
+
+# trap to remove lockfile on quit.
+trap fn_exit_trap INT