From: Cliff W. <cp...@sg...> - 2007-04-11 14:23:37
|
This is a fix for get_utsname(), for a community kernel. > > There is a new "init_uts_ns" struct uts_namespace for locating > > a system's identification. > > Michael Holzheu wrote: > I think we already have this functionality kl_linux_release(). > We probably should use that function to get the utsname. > Or am I missing something here? Indeed, kl_linux_release() does it, and more succinctly than my patch. But it only fetches it and then discards it. How about if we create a library kl_get_utsname() to be shared by both kl_linux_release() and get_utsname()? Signed-off-by: Cliff Wickman <cp...@sg...> --- lcrash/util.c | 18 +----------------- lib/libklib/include/klib.h | 2 ++ lib/libklib/kl_util.c | 31 +++++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 25 deletions(-) Index: lkcdutils/lcrash/util.c =================================================================== --- lkcdutils.orig/lcrash/util.c +++ lkcdutils/lcrash/util.c @@ -446,23 +446,7 @@ int task_cpu(void* tsp){ char * get_utsname(void) { - char *utsname; - syment_t *sp; - - if (!(sp = kl_lkup_symname("system_utsname"))) { - return(0); - } - utsname = (char *)kl_alloc_block(NEW_UTSNAME_SZ, K_TEMP); - if (KL_ERROR) { - return(0); - } - GET_BLOCK(sp->s_addr, NEW_UTSNAME_SZ, utsname); - if (KL_ERROR) { - kl_free_block(utsname); - return(0); - } - - return(utsname); + return (kl_get_utsname()); } /* Index: lkcdutils/lib/libklib/kl_util.c =================================================================== --- lkcdutils.orig/lib/libklib/kl_util.c +++ lkcdutils/lib/libklib/kl_util.c @@ -356,18 +356,14 @@ kl_get_structure(kaddr_t vaddr, char * n } /* - * linux_release() + * allocate a block and fill it with the utsname */ -int -kl_linux_release(void) +void * +kl_get_utsname(void) { - int i; - char *b, *n, revstr[KL_UTS_LEN]; - int revision = 0; - char *c; - void *utsname; syment_t *sp; kaddr_t addr; + void *utsname; if ((sp = kl_lkup_symname("system_utsname"))) addr = sp->s_addr; @@ -375,6 +371,7 @@ kl_linux_release(void) addr = sp->s_addr + kl_member_offset("uts_namespace", "name"); else return(0); + utsname = kl_alloc_block(NEW_UTSNAME_SZ, K_TEMP); if (KL_ERROR) { return(0); @@ -384,6 +381,24 @@ kl_linux_release(void) kl_free_block(utsname); return(0); } + return (utsname); +} + +/* + * linux_release() + */ +int +kl_linux_release(void) +{ + int i; + char *b, *n, revstr[KL_UTS_LEN]; + int revision = 0; + char *c; + void *utsname; + + utsname = kl_get_utsname(); + if (!utsname) + return(0); /* Try to make sure that we have a valid utsname struct. * If we don't, most likely we are using the wrong map Index: lkcdutils/lib/libklib/include/klib.h =================================================================== --- lkcdutils.orig/lib/libklib/include/klib.h +++ lkcdutils/lib/libklib/include/klib.h @@ -464,4 +464,6 @@ int kl_get_structure(kaddr_t, char*, uint64_t kl_get_bit_value(void*, unsigned int, unsigned int, unsigned int); void kl_s390tod_to_timeval(uint64_t, struct timeval*); +void *kl_get_utsname(void); + #endif /* __KLIB_H */ |