Skip to content

Commit

Permalink
example/ringbuffer: fix comm len
Browse files Browse the repository at this point in the history
The Linux kernel uses TASK_COMM_LEN to limit the length of the comm string.
By default TASK_COMM_LEN is set to 16. For simplicity set TASK_COMM_LEN to
16 if it is not defined. As an alternative one could also include
linux/sched.h.

Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl authored and lmb committed Aug 5, 2024
1 parent 0cb38bf commit ccdd12c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/ringbuffer/bpf_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified examples/ringbuffer/bpf_bpfeb.o
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/ringbuffer/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified examples/ringbuffer/bpf_bpfel.o
Binary file not shown.
8 changes: 6 additions & 2 deletions examples/ringbuffer/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

#include "common.h"

#ifndef TASK_COMM_LEN
#define TASK_COMM_LEN 16
#endif

char __license[] SEC("license") = "Dual MIT/GPL";

struct event {
u32 pid;
u8 comm[80];
u8 comm[TASK_COMM_LEN];
};

struct {
Expand All @@ -29,7 +33,7 @@ int kprobe_execve(struct pt_regs *ctx) {
}

task_info->pid = tgid;
bpf_get_current_comm(&task_info->comm, 80);
bpf_get_current_comm(&task_info->comm, TASK_COMM_LEN);

bpf_ringbuf_submit(task_info, 0);

Expand Down

0 comments on commit ccdd12c

Please sign in to comment.