From 8797e54d98eb2e4c921f988dd85e05972c79b184 Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Thu, 13 Jul 2017 09:46:04 +0300 Subject: [PATCH] kernel: provide a helper to get the right utsname structure Also provide helpers to set the machine. --- include/sys/utsname.h | 10 ++++++++++ kernel/os/vers.c | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/sys/utsname.h b/include/sys/utsname.h index 884fa45b9a..858855553a 100644 --- a/include/sys/utsname.h +++ b/include/sys/utsname.h @@ -35,6 +35,10 @@ #include +#ifdef _KERNEL +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -101,6 +105,12 @@ extern int uname(struct utsname *); extern char *uts_nodename(void); /* + * Routines to access parts of the utsname. + */ +extern const struct utsname *utsname_get(bool alt); +extern void utsname_set_machine(const char *machine); + +/* * Alternate UNAME values to use if uarea->u_flags & U_FLAG_ALTUNAME is set. */ extern struct utsname utsname_alt; diff --git a/kernel/os/vers.c b/kernel/os/vers.c index 0cdd16ac96..33bd7fcbda 100644 --- a/kernel/os/vers.c +++ b/kernel/os/vers.c @@ -22,6 +22,7 @@ */ #include +#include struct utsname utsname = { .sysname = UTS_SYSNAME, @@ -38,3 +39,17 @@ struct utsname utsname_alt = { .version = "alternate-uname", .machine = UTS_PLATFORM, }; + +const struct utsname *utsname_get(bool alt) +{ + return alt ? &utsname_alt : &utsname; +} + +void utsname_set_machine(const char *machine) +{ + strncpy(utsname.machine, machine, _SYS_NMLN); + utsname.machine[_SYS_NMLN - 1] = '\0'; + + strncpy(utsname_alt.machine, machine, _SYS_NMLN); + utsname_alt.machine[_SYS_NMLN - 1] = '\0'; +} -- 2.11.4.GIT