Commit a4a2de34 authored by Brendan Gregg's avatar Brendan Gregg

check effective userid on run #850

parent 5f7f019e
......@@ -282,12 +282,13 @@ class BPF(object):
print(log_buf.value.decode(), file=sys.stderr)
if fd < 0:
atexit.register(self.donothing)
if ct.get_errno() == errno.EPERM:
raise Exception("Need super-user privilges to run")
errstr = os.strerror(ct.get_errno())
if self.debug & DEBUG_BPF:
raise Exception("Failed to load BPF program %s: %s" %
(func_name, errstr))
else:
raise Exception("Failed to load BPF program %s: %s" % (func_name, errstr))
raise Exception("Failed to load BPF program %s: %s" %
(func_name, errstr))
fn = BPF.Function(self, func_name, fd)
self.funcs[func_name] = fn
......@@ -1027,6 +1028,9 @@ class BPF(object):
except KeyboardInterrupt:
exit()
def donothing(self):
"""the do nothing exit handler"""
def cleanup(self):
for k, v in list(self.open_kprobes.items()):
lib.perf_reader_free(v)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment