Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbpf-tools: display pid instead of tid #3499

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions libbpf-tools/execsnoop.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ int tracepoint__syscalls__sys_enter_execve(struct trace_event_raw_sys_enter* ctx
if (!event)
return 0;

event->pid = pid;
event->tgid = tgid;
event->pid = tgid;
event->uid = uid;
task = (struct task_struct*)bpf_get_current_task();
event->ppid = (pid_t)BPF_CORE_READ(task, real_parent, tgid);
Expand Down
28 changes: 14 additions & 14 deletions libbpf-tools/execsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const char *argp_program_version = "execsnoop 0.1";
const char *argp_program_bug_address =
"https://github.com/iovisor/bcc/tree/master/libbpf-tools";
const char argp_program_doc[] =
"Trace open family syscalls\n"
"Trace exec syscalls\n"
"\n"
"USAGE: execsnoop [-h] [-T] [-t] [-x] [-u UID] [-q] [-n NAME] [-l LINE] [-U]\n"
" [--max-args MAX_ARGS]\n"
Expand All @@ -56,16 +56,16 @@ const char argp_program_doc[] =
" ./execsnoop -l tpkg # only print command where arguments contains \"tpkg\"";

static const struct argp_option opts[] = {
{ "time", 'T', NULL, 0, "include time column on output (HH:MM:SS)"},
{ "timestamp", 't', NULL, 0, "include timestamp on output"},
{ "fails", 'x', NULL, 0, "include failed exec()s"},
{ "uid", 'u', "UID", 0, "trace this UID only"},
{ "quote", 'q', NULL, 0, "Add quotemarks (\") around arguments"},
{ "name", 'n', "NAME", 0, "only print commands matching this name, any arg"},
{ "line", 'l', "LINE", 0, "only print commands where arg contains this line"},
{ "print-uid", 'U', NULL, 0, "print UID column"},
{ "time", 'T', NULL, 0, "include time column on output (HH:MM:SS)" },
{ "timestamp", 't', NULL, 0, "include timestamp on output" },
{ "fails", 'x', NULL, 0, "include failed exec()s" },
{ "uid", 'u', "UID", 0, "trace this UID only" },
{ "quote", 'q', NULL, 0, "Add quotemarks (\") around arguments" },
{ "name", 'n', "NAME", 0, "only print commands matching this name, any arg" },
{ "line", 'l', "LINE", 0, "only print commands where arg contains this line" },
{ "print-uid", 'U', NULL, 0, "print UID column" },
{ "max-args", MAX_ARGS_KEY, "MAX_ARGS", 0,
"maximum number of arguments parsed and displayed, defaults to 20"},
"maximum number of arguments parsed and displayed, defaults to 20" },
{ "verbose", 'v', NULL, 0, "Verbose debug output" },
{ NULL, 'h', NULL, OPTION_HIDDEN, "Show the full help" },
{},
Expand Down Expand Up @@ -129,8 +129,8 @@ static error_t parse_arg(int key, char *arg, struct argp_state *state)
return 0;
}

int libbpf_print_fn(enum libbpf_print_level level,
const char *format, va_list args)
static int libbpf_print_fn(enum libbpf_print_level level,
const char *format, va_list args)
{
if (level == LIBBPF_DEBUG && !env.verbose)
return 0;
Expand Down Expand Up @@ -209,7 +209,7 @@ static void print_args(const struct event *e, bool quote)
}
}

void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
const struct event *e = data;
time_t t;
Expand Down Expand Up @@ -243,7 +243,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
putchar('\n');
}

void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)
static void handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)
{
fprintf(stderr, "Lost %llu events on CPU #%d!\n", lost_cnt, cpu);
}
Expand Down
3 changes: 1 addition & 2 deletions libbpf-tools/execsnoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
#define LAST_ARG (FULL_MAX_ARGS_ARR - ARGSIZE)

struct event {
char comm[TASK_COMM_LEN];
pid_t pid;
pid_t tgid;
pid_t ppid;
uid_t uid;
int retval;
int args_count;
unsigned int args_size;
char comm[TASK_COMM_LEN];
char args[FULL_MAX_ARGS_ARR];
};

Expand Down