Skip to content

Commit

Permalink
[eBPF] Fix version retrieval issue on some Debian systems
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjiping committed Jun 14, 2024
1 parent e091e09 commit 85155e2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions agent/src/ebpf/user/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,21 @@ int fetch_kernel_version(int *major, int *minor, int *rev, int *num)
}
}

bool has_error = false;
uname(&sys_info);

// e.g.: 3.10.0-940.el7.centos.x86_64, 4.19.17-1.el7.x86_64
if (sscanf(sys_info.release, "%u.%u.%u-%u", major, minor, rev, num) !=
4)
return ETR_INVAL;
4) {
// uname -r (4.19.117.bsk.7-business-amd64)
has_error = true;
}

// Get the real version of Debian
//#1 SMP Debian 4.19.289-2 (2023-08-08)
// # uname -v (4.19.117.bsk.business.1 SMP Debian 4.19.117.business.1 Wed)
// #1 SMP Debian 4.19.289-2 (2023-08-08)
// e.g.:
// uname -v (4.19.117.bsk.business.1 SMP Debian 4.19.117.business.1 Wed)
// uname -v (#business SMP Debian 4.19.117.bsk.7-business Fri Sep 10 11:57:17)
if (strstr(sys_info.version, "Debian")) {
if ((sscanf(sys_info.version, "%*s %*s %*s %u.%u.%u-%u %*s",
major, minor, rev, num) != 4) &&
Expand All @@ -607,7 +612,17 @@ int fetch_kernel_version(int *major, int *minor, int *rev, int *num)
(sscanf(sys_info.version, "%*s %*s %*s %*s %u.%u.%u-%u %*s",
major, minor, rev, num) != 4)
)
return ETR_INVAL;
has_error = true;
else
has_error = false;
}

if (has_error) {
ebpf_warning
("release %s version %s (major %d minor %d rev %d num %d)\n",
sys_info.release, sys_info.version, major, minor, rev,
num);
return ETR_INVAL;
}

return ETR_OK;
Expand Down

0 comments on commit 85155e2

Please sign in to comment.