From 63b33f0e8a8352c77c483c0c4db2d7b6ed74fb3b Mon Sep 17 00:00:00 2001 From: Erik Crevel Date: Thu, 30 Mar 2017 22:24:37 +0100 Subject: [PATCH] Make python3 compatible (still compatible with python2). Compatibility applies to both this program and the programs it targets. --- lptrace | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lptrace b/lptrace index 5e5ccb2..16b08b0 100644 --- a/lptrace +++ b/lptrace @@ -30,26 +30,26 @@ untrace_fn = """import sys ; sys.settrace(None)""" def runfile(pid, script): with tempfile.NamedTemporaryFile() as tmp: name = tmp.name - tmp.write(script) + tmp.write(script.encode('utf-8')) tmp.file.flush() - os.chmod(tmp.name, 0666) + os.chmod(tmp.name, 0o666) - cmd = 'execfile(\\"{}\\")'.format(name) + cmd = 'exec(open(\\"{}\\", \\"r\\").read())'.format(name) inject(pid, cmd) def strace(pid): fifo_name = tempfile.mktemp() os.mkfifo(fifo_name) - os.chmod(fifo_name, 0777) + os.chmod(fifo_name, 0o777) trace_code = trace_fn % fifo_name runfile(pid, trace_code) # Remove the trace if the user types Ctrl-C: def sigint_handler(signal, frame): - print 'Received Ctrl-C, quitting' + print('Received Ctrl-C, quitting') runfile(pid, untrace_fn) sys.exit(0) @@ -59,7 +59,7 @@ def strace(pid): while True: data = fd.read() if data != '': - print data + print(data) def pdb_prompt(pid): @@ -100,17 +100,17 @@ def main(): (options, args) = parser.parse_args() if options.pid is None: - print "You need to specify a process to attach to." + print("You need to specify a process to attach to.") sys.exit(-1) pid = int(options.pid) if not cmd_exists('gdb'): - print "Error: lptrace requires GDB >= 7.x. Exiting." + 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." + print("Error: you must be root to run lptrace. Exiting.") sys.exit(-1) if options.debugger is True: