Skip to content

Commit

Permalink
Merge pull request #73 from vasilevalex/defaults_fix
Browse files Browse the repository at this point in the history
Move default parameter values from code
  • Loading branch information
liviuchircu authored Dec 14, 2020
2 parents 0523e15 + 2c437e2 commit 7b16a38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
8 changes: 8 additions & 0 deletions opensipscli/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

import os
import time

VERSION = '0.1.0'

Expand Down Expand Up @@ -77,6 +78,13 @@
# diagnose module
"diagnose_listen_ip": "127.0.0.1",
"diagnose_listen_port": "8899",

# trace module
"trace_listen_ip": "127.0.0.1",
"trace_listen_port": "0",

# trap module
"trap_file": '/tmp/gdb_opensips_{}'.format(time.strftime('%Y%m%d_%H%M%S'))
}

# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
12 changes: 3 additions & 9 deletions opensipscli/modules/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,9 @@ def do_trace(self, params):

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if cfg.exists("trace_listen_ip"):
trace_ip = cfg.get("trace_listen_ip")
else:
trace_ip = "127.0.0.1"
if cfg.exists("trace_listen_port"):
trace_port = cfg.get("trace_listen_port")
else:
trace_port = 0
s.bind((trace_ip, int(trace_port)))
trace_ip = cfg.get("trace_listen_ip")
trace_port = int(cfg.get("trace_listen_port"))
s.bind((trace_ip, trace_port))
if trace_port == 0:
trace_port = s.getsockname()[1]
s.listen(1)
Expand Down
25 changes: 14 additions & 11 deletions opensipscli/modules/trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
from threading import Thread
import subprocess
import shutil
import time
import os

PROCESS_NAME = 'opensips'
TRAP_FILE_NAME = '/tmp/gdb_opensips_{}'.format(time.strftime('%Y%m%d_%H%M%S'))

class trap(Module):

Expand All @@ -43,7 +41,18 @@ def get_pids(self):
except:
self.pids = []

def get_gdb_output(self, process, pid):
def get_gdb_output(self, pid):
if os.path.islink("/proc/{}/exe".format(pid)):
# get process line of pid
process = os.readlink("/proc/{}/exe".format(pid))
else:
logger.error("could not find OpenSIPS process {} running on local machine".format(pid))
return -1
# Check if process is opensips (can be different if CLI is running on another host)
path, filename = os.path.split(process)
if filename != PROCESS_NAME:
logger.error("process ID {} is not OpenSIPS process".format(pid))
return -1
logger.debug("Dumping backtrace for {} pid {}".format(process, pid))
cmd = ["gdb", process, pid, "-batch", "--eval-command", "bt full"]
out = subprocess.check_output(cmd)
Expand All @@ -56,10 +65,7 @@ def do_trap(self, params):
self.gdb_outputs = {}
self.process_info = ""

if cfg.exists("trap_file"):
trap_file = cfg.get("trap_file")
else:
trap_file = TRAP_FILE_NAME
trap_file = cfg.get("trap_file")

logger.info("Trapping {} in {}".format(PROCESS_NAME, trap_file))
if params and len(params) > 0:
Expand All @@ -83,12 +89,9 @@ def do_trap(self, params):

logger.debug("Dumping PIDs: {}".format(", ".join(self.pids)))

# get process line of first pid
process = os.readlink("/proc/{}/exe".format(self.pids[0]))

threads = []
for pid in self.pids:
thread = Thread(target=self.get_gdb_output, args=(process, pid))
thread = Thread(target=self.get_gdb_output, args=(pid,))
thread.start()
threads.append(thread)

Expand Down

0 comments on commit 7b16a38

Please sign in to comment.