Browse code

kamctl: added pstrap command

- use ps to get list of PIDs for Kamailio instance, instead of RPC
core.psx

(cherry picked from commit 97ec85559f1e33405fff2320443dc86d2df13456)

Daniel-Constantin Mierla authored on 07/07/2020 16:57:27
Showing 2 changed files
... ...
@@ -2909,7 +2909,7 @@ extcmd() {
2909 2909
 }
2910 2910
 
2911 2911
 ##### ================================================ #####
2912
-### trap with gdb kamailio processes
2912
+### trap with gdb kamailio processes using RPC core.psx
2913 2913
 #
2914 2914
 
2915 2915
 kamailio_trap() {
... ...
@@ -2935,6 +2935,35 @@ kamailio_trap() {
2935 2935
 	echo "."
2936 2936
 }
2937 2937
 
2938
+##### ================================================ #####
2939
+### trap with gdb kamailio processes using ps command
2940
+#
2941
+
2942
+kamailio_pstrap() {
2943
+	if [ -z "$GDB" ] ; then
2944
+		merr "'gdb' tool not found: set GDB variable to correct tool path"
2945
+		exit
2946
+	fi
2947
+	DATE=`/bin/date +%Y%m%d_%H%M%S`
2948
+	LOG_FILE=/tmp/gdb_kamailio_${DATE}.txt
2949
+	minfo "Trap file: $LOG_FILE"
2950
+	ps axw | grep kamailio | grep -v grep | sort > $LOG_FILE
2951
+	echo "" >> $LOG_FILE
2952
+	echo "" >> $LOG_FILE
2953
+	echo -n "Trapping Kamailio with gdb: "
2954
+	PID_TIMESTAMP_VECTOR=`ps axw | grep kamailio | grep -v grep | sort | awk '{print $1}'`
2955
+	for pid in $PID_TIMESTAMP_VECTOR
2956
+	do
2957
+		echo -n "."
2958
+		PID=`echo $pid | cut -d '-' -f 1`
2959
+		echo "" >> $LOG_FILE
2960
+		echo "---start $PID -----------------------------------------------------" >> $LOG_FILE
2961
+		$GDB kamailio $PID -batch --eval-command="bt full" >> $LOG_FILE 2>&1
2962
+		echo "---end $PID -------------------------------------------------------" >> $LOG_FILE
2963
+	done
2964
+	echo "."
2965
+}
2966
+
2938 2967
 #
2939 2968
 ##### ================================================ #####
2940 2969
 ### main command switch
... ...
@@ -3147,6 +3176,10 @@ case $1 in
3147 3176
 		kamailio_trap
3148 3177
 		;;
3149 3178
 
3179
+	pstrap)
3180
+		kamailio_pstrap
3181
+		;;
3182
+
3150 3183
 	start)
3151 3184
 		kamailio_start
3152 3185
 		;;
... ...
@@ -368,7 +368,8 @@ usage_base() {
368 368
 	mecho " -- command 'start|stop|restart|trap'"
369 369
 	echo
370 370
 cat <<EOF
371
- trap ............................... trap with gdb Kamailio processes
371
+ trap ............................... trap with gdb Kamailio processes using RPC
372
+ pstrap ............................. trap with gdb Kamailio processes using ps
372 373
  restart ............................ restart Kamailio
373 374
  start .............................. start Kamailio
374 375
  stop ............................... stop Kamailio