summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorthiagoftsm <thiagoftsm@gmail.com>2020-04-14 10:34:52 +0000
committerGitHub <noreply@github.com>2020-04-14 10:34:52 +0000
commit4c535a60d16335421d28bd2e1b12d659dcd89bde (patch)
tree081b0e07a0cc474e41563a7bb67f9fe3abecade9 /libnetdata
parent57ee9f4303e9496ae6cce214ccf4a54e5bcbda0a (diff)
Fixes compatibility with RH 7.x family (#8694)
Brings eBPF collector to RH 7.x family.
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/ebpf/ebpf.c44
-rw-r--r--libnetdata/ebpf/ebpf.h25
2 files changed, 68 insertions, 1 deletions
diff --git a/libnetdata/ebpf/ebpf.c b/libnetdata/ebpf/ebpf.c
index 6c49706893..ea1fc37e1b 100644
--- a/libnetdata/ebpf/ebpf.c
+++ b/libnetdata/ebpf/ebpf.c
@@ -91,8 +91,50 @@ int get_kernel_version() {
return ((int)(str2l(major)*65536) + (int)(str2l(minor)*256) + (int)str2l(patch));
}
+int get_redhat_release()
+{
+ char buffer[256];
+ int major,minor;
+ FILE *fp = fopen("/etc/redhat-release", "r");
+
+ if (fp) {
+ major = 0;
+ minor = -1;
+ size_t length = fread(buffer, sizeof(char), 255, fp);
+ if (length > 4 ) {
+ buffer[length] = '\0';
+ char *end = strchr(buffer, '.');
+ char *start;
+ if (end) {
+ *end = 0x0;
+
+ if (end > buffer) {
+ start = end - 1;
+
+ major = strtol( start, NULL, 10);
+ start = ++end;
+
+ end++;
+ if(end) {
+ end = 0x00;
+ minor = strtol( start, NULL, 10);
+ } else {
+ minor = -1;
+ }
+ }
+ }
+ }
+
+ fclose(fp);
+ return ((major*256) + minor);
+ } else {
+ return -1;
+ }
+}
+
static int has_ebpf_kernel_version(int version) {
- return (version >= 264960);
+ //Kernel 4.11.0 or RH > 7.5
+ return (version >= NETDATA_MINIMUM_EBPF_KERNEL || get_redhat_release() >= NETDATA_MINIMUM_RH_VERSION);
}
int has_condition_to_run(int version) {
diff --git a/libnetdata/ebpf/ebpf.h b/libnetdata/ebpf/ebpf.h
index 382f549e7b..e7cd651a67 100644
--- a/libnetdata/ebpf/ebpf.h
+++ b/libnetdata/ebpf/ebpf.h
@@ -3,6 +3,30 @@
# define NETDATA_DEBUGFS "/sys/kernel/debug/tracing/"
+/**
+ * The next magic number is got doing the following math:
+ * 294960 = 4*65536 + 11*256 + 0
+ *
+ * For more details, please, read /usr/include/linux/version.h
+ */
+# define NETDATA_MINIMUM_EBPF_KERNEL 264960
+
+/**
+ * The RedHat magic number was got doing:
+ *
+ * 1797 = 7*256 + 5
+ *
+ * For more details, please, read /usr/include/linux/version.h
+ * in any Red Hat installation.
+ */
+# define NETDATA_MINIMUM_RH_VERSION 1797
+
+/**
+ * 2048 = 8*256 + 0
+ */
+# define NETDATA_RH_8 2048
+
+
typedef struct netdata_ebpf_events {
char type;
char *name;
@@ -11,6 +35,7 @@ typedef struct netdata_ebpf_events {
extern int clean_kprobe_events(FILE *out, int pid, netdata_ebpf_events_t *ptr);
extern int get_kernel_version();
+extern int get_redhat_release();
extern int has_condition_to_run(int version);
#endif