// SPDX-License-Identifier: GPL-3.0-or-later
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <sys/utsname.h>
#include "../libnetdata.h"
char *ebpf_user_config_dir = CONFIG_DIR;
char *ebpf_stock_config_dir = LIBCONFIG_DIR;
/*
static int clean_kprobe_event(FILE *out, char *filename, char *father_pid, netdata_ebpf_events_t *ptr)
{
int fd = open(filename, O_WRONLY | O_APPEND, 0);
if (fd < 0) {
if (out) {
fprintf(out, "Cannot open %s : %s\n", filename, strerror(errno));
}
return 1;
}
char cmd[1024];
int length = snprintf(cmd, 1023, "-:kprobes/%c_netdata_%s_%s", ptr->type, ptr->name, father_pid);
int ret = 0;
if (length > 0) {
ssize_t written = write(fd, cmd, strlen(cmd));
if (written < 0) {
if (out) {
fprintf(
out, "Cannot remove the event (%d, %d) '%s' from %s : %s\n", getppid(), getpid(), cmd, filename,
strerror((int)errno));
}
ret = 1;
}
}
close(fd);
return ret;
}
int clean_kprobe_events(FILE *out, int pid, netdata_ebpf_events_t *ptr)
{
debug(D_EXIT, "Cleaning parent process events.");
char filename[FILENAME_MAX + 1];
snprintf(filename, FILENAME_MAX, "%s%s", NETDATA_DEBUGFS, "kprobe_events");
char removeme[16];
snprintf(removeme, 15, "%d", pid);
int i;
for (i = 0; ptr[i].name; i++) {
if (clean_kprobe_event(out, filename, removeme, &ptr[i])) {
break;
}
}
return 0;
}
*/
//----------------------------------------------------------------------------------------------------------------------
/**
* Get Kernel version
*
* Get the current kernel from /proc and returns an integer value representing it