Fix ebpf exit (#12590)
thiagoftsm committed
Apr 4, 2022 at 12:32 UTC
012f8c1d317bf15a54dc0346b6655e1e838cdfc6
1 file changed
+11
-4
collectors/ebpf.plugin/ebpf.c
+11
-4
@@ -212,6 +212,7 @@ void clean_loaded_events()
212
static void ebpf_exit(int sig)
213
{
214
close_ebpf_plugin = 1;
215
+ static int remove_pid = 0;
216
217
// When both threads were not finished case I try to go in front this address, the collector will crash
218
if (!thread_finished) {
@@ -296,13 +297,19 @@ static void ebpf_exit(int sig)
297
*/
298
299
#ifdef LIBBPF_MAJOR_VERSION
299
- if (default_btf)
300
+ if (default_btf) {
301
btf__free(default_btf);
302
+ default_btf = NULL;
303
+ }
304
#endif
305
303
- char filename[FILENAME_MAX + 1];
304
- ebpf_pid_file(filename, FILENAME_MAX);
305
- unlink(filename);
306
+ if (!remove_pid) {
307
+ remove_pid = 1;
308
+ char filename[FILENAME_MAX + 1];
309
+ ebpf_pid_file(filename, FILENAME_MAX);
310
+ if (unlink(filename))
311
+ error("Cannot remove PID file %s", filename);
312
+ }
313
314
exit(sig);
315
}