1
0
mirror of https://github.com/libuv/libuv synced 2025-03-28 21:13:16 +00:00

unix: get mainline kernel version in Ubuntu (#4131)

In Ubuntu, the kernel version reported by `uname()` follows the
versioning format that Ubuntu uses for their kernels which does not have
a direct correspondence with the mainline kernel version they're based
on. Get that version from `/proc/version_signature` as documented in:

https://wiki.ubuntu.com/Kernel/FAQ#Kernel.2FFAQ.2FGeneralVersionRunning.How_can_we_determine_the_version_of_the_running_kernel.3F
This commit is contained in:
Santiago Gimeno 2023-08-30 21:30:59 +02:00
parent 0a02887e62
commit e2c8fed7b3

View File

@ -323,11 +323,22 @@ unsigned uv__kernel_version(void) {
unsigned major;
unsigned minor;
unsigned patch;
char v_sig[256];
version = atomic_load_explicit(&cached_version, memory_order_relaxed);
if (version != 0)
return version;
/* Check /proc/version_signature first as it's the way to get the mainline
* kernel version in Ubuntu. The format is:
* Ubuntu ubuntu_kernel_version mainline_kernel_version
* For example:
* Ubuntu 5.15.0-79.86-generic 5.15.111
*/
if (0 == uv__slurp("/proc/version_signature", v_sig, sizeof(v_sig)))
if (3 == sscanf(v_sig, "Ubuntu %*s %u.%u.%u", &major, &minor, &patch))
goto calculate_version;
if (-1 == uname(&u))
return 0;
@ -359,6 +370,7 @@ unsigned uv__kernel_version(void) {
}
}
calculate_version:
version = major * 65536 + minor * 256 + patch;
atomic_store_explicit(&cached_version, version, memory_order_relaxed);