diff --git a/HISTORY b/HISTORY index 404e9c1..d50e084 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ -Version 1.51 2021-05-26 +Version 1.51 2021-05-27 * fast_mblock.[hc]: support batch alloc and batch free * uniq_skiplist.[hc]: init function add parameter: allocator_use_lock * add function normalize_path_ex and normalize_uri * use libcurl to fetch URL resource + * add function get_kernel_version Version 1.50 2021-05-11 * add function is_digital_string diff --git a/src/system_info.c b/src/system_info.c index 50e5e9b..d77b493 100644 --- a/src/system_info.c +++ b/src/system_info.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -785,7 +786,7 @@ int get_sysinfo(struct fast_sysinfo *info) if (sysctl(mib, 2, &sw_usage, &size, NULL, 0) != 0) { logError("file: "__FILE__", line: %d, " \ - "call sysctl fail, " \ + "call sysctl fail, " \ "errno: %d, error info: %s", \ __LINE__, errno, STRERROR(errno)); } @@ -802,3 +803,35 @@ int get_sysinfo(struct fast_sysinfo *info) #endif #endif +int get_kernel_version(Version *version) +{ + struct utsname name; + char *p; + int numbers[2]; + int i; + + if (uname(&name) < 0) + { + logError("file: "__FILE__", line: %d, " + "call uname fail, errno: %d, error info: %s", + __LINE__, errno, STRERROR(errno)); + return errno != 0 ? errno : EFAULT; + } + + numbers[0] = numbers[1] = 0; + p = name.release; + for (i=0; i<2; i++) { + p = strchr(p, '.'); + if (p == NULL) { + break; + } + + p++; + numbers[i] = strtol(p, NULL, 10); + } + + version->major = strtol(name.release, NULL, 10); + version->minor = numbers[0]; + version->patch = numbers[1]; + return 0; +} diff --git a/src/system_info.h b/src/system_info.h index 08c2e9b..df60e0c 100644 --- a/src/system_info.h +++ b/src/system_info.h @@ -161,6 +161,9 @@ int get_mounted_filesystems(struct fast_statfs *stats, int get_processes(struct fast_process_info **processes, int *count); int get_sysinfo(struct fast_sysinfo *info); + +int get_kernel_version(Version *version); + #endif #ifdef __cplusplus