Skip to content

Commit abbc0d7

Browse files
committed
example/ringbuffer: fix comm len
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 <dev@der-flo.net>
1 parent 88e8f88 commit abbc0d7

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

examples/ringbuffer/bpf_bpfeb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ringbuffer/bpf_bpfeb.o

16 Bytes
Binary file not shown.

examples/ringbuffer/bpf_bpfel.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ringbuffer/bpf_bpfel.o

16 Bytes
Binary file not shown.

examples/ringbuffer/ringbuffer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
#include "common.h"
44

5+
#ifndef TASK_COMM_LEN
6+
#define TASK_COMM_LEN 16
7+
#endif
8+
59
char __license[] SEC("license") = "Dual MIT/GPL";
610

711
struct event {
812
u32 pid;
9-
u8 comm[80];
13+
u8 comm[TASK_COMM_LEN];
1014
};
1115

1216
struct {
@@ -29,7 +33,7 @@ int kprobe_execve(struct pt_regs *ctx) {
2933
}
3034

3135
task_info->pid = tgid;
32-
bpf_get_current_comm(&task_info->comm, 80);
36+
bpf_get_current_comm(&task_info->comm, TASK_COMM_LEN);
3337

3438
bpf_ringbuf_submit(task_info, 0);
3539

0 commit comments

Comments
 (0)