diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2022-03-14 08:03:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 10:03:27 +0200 |
commit | 09c325c6d2c6e0aa5384ee6bade3e9bc727f75fa (patch) | |
tree | f71e0fc42b4ec50131ebc752d4820f34348b7f8e /collectors | |
parent | d52f0f0aec909137230d1dca6e9e2844a63566b2 (diff) |
fix(ebpf.plugin): remove pid file on exit (#12379)
Diffstat (limited to 'collectors')
-rw-r--r-- | collectors/ebpf.plugin/ebpf.c | 19 | ||||
-rw-r--r-- | collectors/ebpf.plugin/ebpf.h | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index f90712f2ef..778c2bd96e 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -300,6 +300,10 @@ static void ebpf_exit(int sig) btf__free(default_btf); #endif + char filename[FILENAME_MAX + 1]; + ebpf_pid_file(filename, FILENAME_MAX); + unlink(filename); + exit(sig); } @@ -1831,6 +1835,19 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid) } /** + * PID file + * + * Write the filename for PID inside the given vector. + * + * @param filename vector where we will store the name. + * @param length number of bytes available in filename vector + */ +void ebpf_pid_file(char *filename, size_t length) +{ + snprintfz(filename, length, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir); +} + +/** * Manage PID * * This function kills another instance of eBPF whether it is necessary and update the file content. @@ -1840,7 +1857,7 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid) static void ebpf_manage_pid(pid_t pid) { char filename[FILENAME_MAX + 1]; - snprintfz(filename, FILENAME_MAX, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir); + ebpf_pid_file(filename, FILENAME_MAX); ebpf_kill_previous_process(filename, pid); ebpf_update_pid_file(filename, pid); diff --git a/collectors/ebpf.plugin/ebpf.h b/collectors/ebpf.plugin/ebpf.h index b2e52946d2..5cc8cad257 100644 --- a/collectors/ebpf.plugin/ebpf.h +++ b/collectors/ebpf.plugin/ebpf.h @@ -238,6 +238,8 @@ extern int ebpf_enable_tracepoint(ebpf_tracepoint_t *tp); extern int ebpf_disable_tracepoint(ebpf_tracepoint_t *tp); extern uint32_t ebpf_enable_tracepoints(ebpf_tracepoint_t *tps); +extern void ebpf_pid_file(char *filename, size_t length); + #define EBPF_PROGRAMS_SECTION "ebpf programs" #define EBPF_COMMON_DIMENSION_PERCENTAGE "%" |