Browse Source

utils/kamctl: new command 'trap'
- useful to get a full bt dump of all kamailio processes
- handy in dead-lock investigatigations

Ovidiu Sas 11 years ago
parent
commit
71380228bf
3 changed files with 42 additions and 1 deletions
  1. 28 0
      utils/kamctl/kamctl
  2. 11 1
      utils/kamctl/kamctl.base
  3. 3 0
      utils/kamctl/kamctlrc

+ 28 - 0
utils/kamctl/kamctl

@@ -2644,6 +2644,29 @@ extcmd() {
 	exit 1
 	exit 1
 }
 }
 
 
+##### ================================================ #####
+### trap with gdb kamailio processes
+#
+
+kamailio_trap() {
+	DATE=`/bin/date +%Y%m%d_%H%M%S`
+	LOG_FILE=/tmp/gdb_kamailio_$DATE
+	minfo "Trap file: $LOG_FILE"
+	$SERCTLCMD ps > $LOG_FILE
+	echo -n "Trapping Kamailio with gdb: "
+	PID_TIMESTAMP_VECTOR=`sed -e 's/\([0-9]*\).*/\1/' $LOG_FILE`
+	for pid in $PID_TIMESTAMP_VECTOR
+	do
+		echo -n "."
+		PID=`echo $pid | cut -d '-' -f 1`
+		echo "" >> $LOG_FILE
+		echo "---start $PID -----------------------------------------------------" >> $LOG_FILE
+		$GDB kamailio $PID -batch --eval-command="bt full" &>> $LOG_FILE
+		echo "---end $PID -------------------------------------------------------" >> $LOG_FILE
+	done
+	echo "."
+}
+
 #
 #
 ##### ================================================ #####
 ##### ================================================ #####
 ### main command switch
 ### main command switch
@@ -2825,6 +2848,11 @@ case $1 in
 		tls_ca "$@"
 		tls_ca "$@"
 		;;
 		;;
 
 
+	trap)
+		require_ctlengine
+		kamailio_trap
+		;;
+
 	start)
 	start)
 		kamailio_start
 		kamailio_start
 		;;
 		;;

+ 11 - 1
utils/kamctl/kamctl.base

@@ -53,6 +53,15 @@ if [ -z "$AWK" ] ; then
 	fi
 	fi
 	AWK="$TOOLPATH"
 	AWK="$TOOLPATH"
 fi
 fi
+if [ -z "$GDB" ] ; then
+	locate_tool gdb
+	if [ -z "$TOOLPATH" ] ; then
+		# now error, but we can look for alternative names if it is the case
+		echo "error: 'gdb' tool not found: set GDB variable to correct tool path"
+		exit
+	fi
+	GDB="$TOOLPATH"
+fi
 if [ -z "$MD5" ]; then
 if [ -z "$MD5" ]; then
 	locate_tool md5sum md5
 	locate_tool md5sum md5
 	if [ -z "$TOOLPATH" ] ; then
 	if [ -z "$TOOLPATH" ] ; then
@@ -340,9 +349,10 @@ DIALPLAN_ATTRS_COLUMN=attrs
 
 
 usage_base() {
 usage_base() {
 	echo
 	echo
-	mecho " -- command 'start|stop|restart'"
+	mecho " -- command 'start|stop|restart|trap'"
 	echo
 	echo
 cat <<EOF
 cat <<EOF
+ trap ............................... trap with gdb Kamailio processes
  restart ............................ restart Kamailio
  restart ............................ restart Kamailio
  start .............................. start Kamailio
  start .............................. start Kamailio
  stop ............................... stop Kamailio
  stop ............................... stop Kamailio

+ 3 - 0
utils/kamctl/kamctlrc

@@ -69,6 +69,9 @@
 # awk tool
 # awk tool
 # AWK="awk"
 # AWK="awk"
 
 
+# gdb tool
+# GDB="gdb"
+
 # If you use a system with a grep and egrep that is not 100% gnu grep compatible,
 # If you use a system with a grep and egrep that is not 100% gnu grep compatible,
 # e.g. solaris, install the gnu grep (ggrep) and specify this below.
 # e.g. solaris, install the gnu grep (ggrep) and specify this below.
 #
 #