From: Karim Hamidou Date: Fri, 24 Feb 2017 16:23:35 +0000 (-0800) Subject: Error out if gdb isn't installed. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;ds=inline;p=lptrace.git Error out if gdb isn't installed. --- diff --git a/lptrace b/lptrace index dbed96f..5e5ccb2 100644 --- a/lptrace +++ b/lptrace @@ -1,7 +1,6 @@ #!/usr/bin/env python2 # lptrace - Copyright (c) 2016 Karim Hamidou. # Portions inspired by Pyrasite. - import os import sys import signal @@ -84,6 +83,11 @@ def inject(pid, code): out, err = p.communicate() +def cmd_exists(cmd): + return subprocess.call("type " + cmd, shell=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 + + def main(): parser = OptionParser() parser.add_option("-p", "--process", dest="pid", @@ -101,6 +105,10 @@ def main(): pid = int(options.pid) + if not cmd_exists('gdb'): + print "Error: lptrace requires GDB >= 7.x. Exiting." + sys.exit(-1) + if os.geteuid() != 0: print "Error: you must be root to run lptrace. Exiting." sys.exit(-1)