Skip to content

Commit 916ab3f

Browse files
authored
Merge pull request #42 from OpenCloudOS/dev
some small optimization
2 parents faf3642 + 05cd0e4 commit 916ab3f

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

src/dropreason.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ static bool drop_reason_inited = false;
1818
bool drop_reason_support()
1919
{
2020
return simple_exec("cat /sys/kernel/debug/tracing/events/skb/"
21-
"kfree_skb/format | grep NOT_SPECIFIED") == 0;
21+
"kfree_skb/format 2>/dev/null | "
22+
"grep NOT_SPECIFIED") == 0;
2223
}
2324

2425
static int parse_reason_enum()

src/trace.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,39 @@ static int trace_prepare_traces()
375375
int trace_prepare()
376376
{
377377
trace_t *trace;
378+
int err;
378379

379-
if (trace_prepare_args())
380-
return -1;
380+
err = trace_prepare_args();
381+
if (err)
382+
goto err;
381383

382-
if (trace_prepare_traces())
383-
return -1;
384+
err = trace_prepare_traces();
385+
if (err)
386+
goto err;
384387

385388
if (trace_ctx.args.show_traces) {
386389
trace_show(&root_group);
387390
exit(0);
388391
}
389392

393+
if (geteuid() != 0) {
394+
pr_err("Please run as root!\n");
395+
err = -EPERM;
396+
goto err;
397+
}
398+
399+
#ifndef COMPAT_MODE
400+
if (!file_exist("/sys/kernel/btf/vmlinux")) {
401+
pr_err("BTF is not support by your kernel, please compile"
402+
"this tool with \"COMPAT=1\"\n");
403+
err = -ENOTSUP;
404+
goto err;
405+
}
406+
#endif
407+
390408
return 0;
409+
err:
410+
return err;
391411
}
392412

393413
static int trace_bpf_load()

0 commit comments

Comments
 (0)