[sr-dev] git:master: utils/kamctl: new command 'trap'

Ovidiu Sas osas at voipembedded.com
Tue Dec 17 18:55:10 CET 2013


Module: sip-router
Branch: master
Commit: 71380228bf5804f51292205de2dfae1b4945b9de
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=71380228bf5804f51292205de2dfae1b4945b9de

Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date:   Tue Dec 17 12:53:20 2013 -0500

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

---

 utils/kamctl/kamctl      |   28 ++++++++++++++++++++++++++++
 utils/kamctl/kamctl.base |   12 +++++++++++-
 utils/kamctl/kamctlrc    |    3 +++
 3 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 80a626e..e6c87f1 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -2644,6 +2644,29 @@ extcmd() {
 	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
@@ -2825,6 +2848,11 @@ case $1 in
 		tls_ca "$@"
 		;;
 
+	trap)
+		require_ctlengine
+		kamailio_trap
+		;;
+
 	start)
 		kamailio_start
 		;;
diff --git a/utils/kamctl/kamctl.base b/utils/kamctl/kamctl.base
index 27532a3..62d4c9b 100644
--- a/utils/kamctl/kamctl.base
+++ b/utils/kamctl/kamctl.base
@@ -53,6 +53,15 @@ if [ -z "$AWK" ] ; then
 	fi
 	AWK="$TOOLPATH"
 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
 	locate_tool md5sum md5
 	if [ -z "$TOOLPATH" ] ; then
@@ -340,9 +349,10 @@ DIALPLAN_ATTRS_COLUMN=attrs
 
 usage_base() {
 	echo
-	mecho " -- command 'start|stop|restart'"
+	mecho " -- command 'start|stop|restart|trap'"
 	echo
 cat <<EOF
+ trap ............................... trap with gdb Kamailio processes
  restart ............................ restart Kamailio
  start .............................. start Kamailio
  stop ............................... stop Kamailio
diff --git a/utils/kamctl/kamctlrc b/utils/kamctl/kamctlrc
index 472d991..3ffad11 100644
--- a/utils/kamctl/kamctlrc
+++ b/utils/kamctl/kamctlrc
@@ -69,6 +69,9 @@
 # awk tool
 # AWK="awk"
 
+# gdb tool
+# GDB="gdb"
+
 # 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.
 #




More information about the sr-dev mailing list