From 537053c5fd6c3d84d0fb73d675fe926d470c82d5 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Fri, 24 Feb 2017 08:23:35 -0800 Subject: [PATCH] Error out if gdb isn't installed. --- lptrace | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) -- 2.43.0