Commit 9e608df7 authored by Brendan Gregg's avatar Brendan Gregg Committed by GitHub

Merge pull request #295 from iovisor/non_root

Better non-root error
parents e89957ff 22dc8d45
#include <iostream>
#include <signal.h>
#include <sys/resource.h>
#include <unistd.h>
#include "bpforc.h"
#include "bpftrace.h"
......@@ -53,6 +54,17 @@ static void enforce_infinite_rlimit() {
"\"ulimit -l 8192\" to fix the problem" << std::endl;
}
bool is_root()
{
if (geteuid() != 0)
{
std::cerr << "ERROR: bpftrace currently only supports running as the root user." << std::endl;
return false;
}
else
return true;
}
int main(int argc, char *argv[])
{
int err;
......@@ -112,6 +124,9 @@ int main(int argc, char *argv[])
// Listing probes
if (listing)
{
if (!is_root())
return 1;
if (optind == argc-1)
list_probes(argv[optind]);
else if (optind == argc)
......@@ -145,6 +160,9 @@ int main(int argc, char *argv[])
err = driver.parse_str(script);
}
if (!is_root())
return 1;
if (err)
return err;
......
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