]> khamidou — GitHub mirrors - lptrace.git/commitdiff
Error out if gdb isn't installed. master
authorKarim Hamidou <khamidou@gmail.com>
Fri, 24 Feb 2017 16:23:35 +0000 (08:23 -0800)
committerKarim Hamidou <khamidou@gmail.com>
Fri, 24 Feb 2017 16:23:50 +0000 (08:23 -0800)
lptrace

diff --git a/lptrace b/lptrace
index dbed96f2228fbeed6664346c23bb80ee76a552cd..5e5ccb2c3037f9bf27fd31e8b2392660739c85d2 100644 (file)
--- a/lptrace
+++ b/lptrace
@@ -1,7 +1,6 @@
 #!/usr/bin/env python2
 # lptrace - Copyright (c) 2016 Karim Hamidou.
 # Portions inspired by Pyrasite.
 #!/usr/bin/env python2
 # lptrace - Copyright (c) 2016 Karim Hamidou.
 # Portions inspired by Pyrasite.
-
 import os
 import sys
 import signal
 import os
 import sys
 import signal
@@ -84,6 +83,11 @@ def inject(pid, code):
     out, err = p.communicate()
 
 
     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",
 def main():
     parser = OptionParser()
     parser.add_option("-p", "--process", dest="pid",
@@ -101,6 +105,10 @@ def main():
 
     pid = int(options.pid)
 
 
     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)
     if os.geteuid() != 0:
         print "Error: you must be root to run lptrace. Exiting."
         sys.exit(-1)