mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
perf tools: Make fetch_kernel_version() publicly available
There are 2 places in llvm-utils.c which find kernel version information through uname. This patch extracts the uname related code into a fetch_kernel_version() function and puts it into util.h so it can be reused. Signed-off-by: Wang Nan <wangnan0@huawei.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446818135-87310-1-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
45825d8ab8
commit
07bc5c699a
3 changed files with 50 additions and 34 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "debug.h"
|
||||
#include <api/fs/fs.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/utsname.h>
|
||||
#ifdef HAVE_BACKTRACE_SUPPORT
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
@ -665,3 +666,32 @@ bool find_process(const char *name)
|
|||
closedir(dir);
|
||||
return ret ? false : true;
|
||||
}
|
||||
|
||||
int
|
||||
fetch_kernel_version(unsigned int *puint, char *str,
|
||||
size_t str_size)
|
||||
{
|
||||
struct utsname utsname;
|
||||
int version, patchlevel, sublevel, err;
|
||||
|
||||
if (uname(&utsname))
|
||||
return -1;
|
||||
|
||||
if (str && str_size) {
|
||||
strncpy(str, utsname.release, str_size);
|
||||
str[str_size - 1] = '\0';
|
||||
}
|
||||
|
||||
err = sscanf(utsname.release, "%d.%d.%d",
|
||||
&version, &patchlevel, &sublevel);
|
||||
|
||||
if (err != 3) {
|
||||
pr_debug("Unablt to get kernel version from uname '%s'\n",
|
||||
utsname.release);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (puint)
|
||||
*puint = (version << 16) + (patchlevel << 8) + sublevel;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue