fix(ebpf.plugin): remove pid file on exit (#12379)
thiagoftsm committed
Mar 14, 2022 at 08:03 UTC
09c325c6d2c6e0aa5384ee6bade3e9bc727f75fa
2 files changed
+20
-1
collectors/ebpf.plugin/ebpf.c
+18
-1
@@ -300,6 +300,10 @@ static void ebpf_exit(int sig)
300
btf__free(default_btf);
301
#endif
302
303
+ char filename[FILENAME_MAX + 1];
304
+ ebpf_pid_file(filename, FILENAME_MAX);
305
+ unlink(filename);
306
+
307
exit(sig);
308
}
309
@@ -1830,6 +1834,19 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid)
1834
sleep_usec(USEC_PER_MS * 300);
1835
}
1836
1837
+/**
1838
+ * PID file
1839
+ *
1840
+ * Write the filename for PID inside the given vector.
1841
+ *
1842
+ * @param filename vector where we will store the name.
1843
+ * @param length number of bytes available in filename vector
1844
+ */
1845
+void ebpf_pid_file(char *filename, size_t length)
1846
+{
1847
+ snprintfz(filename, length, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir);
1848
+}
1849
+
1850
/**
1851
* Manage PID
1852
*
@@ -1840,7 +1857,7 @@ static void ebpf_kill_previous_process(char *filename, pid_t pid)
1857
static void ebpf_manage_pid(pid_t pid)
1858
{
1859
char filename[FILENAME_MAX + 1];
1843
- snprintfz(filename, FILENAME_MAX, "%s%s/ebpf.d/ebpf.pid", netdata_configured_host_prefix, ebpf_plugin_dir);
1860
+ ebpf_pid_file(filename, FILENAME_MAX);
1861
1862
ebpf_kill_previous_process(filename, pid);
1863
ebpf_update_pid_file(filename, pid);
collectors/ebpf.plugin/ebpf.h
+2
@@ -238,6 +238,8 @@ extern int ebpf_enable_tracepoint(ebpf_tracepoint_t *tp);
238
extern int ebpf_disable_tracepoint(ebpf_tracepoint_t *tp);
239
extern uint32_t ebpf_enable_tracepoints(ebpf_tracepoint_t *tps);
240
241
+extern void ebpf_pid_file(char *filename, size_t length);
242
+
243
#define EBPF_PROGRAMS_SECTION "ebpf programs"
244
245
#define EBPF_COMMON_DIMENSION_PERCENTAGE "%"