home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume26
/
sysinfo-1.0
/
part01
/
kernel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-10
|
2KB
|
104 lines
/*
* Copyright (c) 1992 Michael A. Cooper.
* This software may be freely distributed provided it is not sold for
* profit and the author is credited appropriately.
*/
#ifndef lint
static char *RCSid = "$Header: /src/common/usc/bin/sysinfo/RCS/kernel.c,v 1.8 1992/04/26 23:32:06 mcooper Exp $";
#endif
/*
* $Log: kernel.c,v $
* Revision 1.8 1992/04/26 23:32:06 mcooper
* Add Copyright notice
*
* Revision 1.7 1992/04/17 01:07:59 mcooper
* More de-linting
*
* Revision 1.6 1992/04/16 02:25:39 mcooper
* Bug fixes, de-linting, and other changes found with CodeCenter.
*
* Revision 1.5 1992/03/31 02:36:06 mcooper
* Change "nl" to "VersionNL".
*
* Revision 1.4 1992/03/31 01:55:17 mcooper
* Use new CheckNlist to check nlist success.
*
* Revision 1.3 1992/03/31 00:15:09 mcooper
* Add error check for nlist.n_type.
*
* Revision 1.2 1992/03/22 00:55:41 mcooper
* Use new GetNlName() to get n_name out of a struct nlist.
*
* Revision 1.1 1992/03/22 00:20:10 mcooper
* Initial revision
*
*/
/*
* Kernel related functions.
*/
#include <stdio.h>
#include "system.h"
#include "defs.h"
#if defined(HAVE_NLIST)
#include <fcntl.h>
#include <nlist.h>
struct nlist VersionNL[] = {
#define N_VERSION 0
#if defined(COFF)
{ "version" }, /* 0 */
#else
{ "_version" },
#endif /* COFF */
{ 0 },
};
#if defined(HAVE_KVM)
/*
* Get kernel version string by reading the
* symbol "version" from the kernel.
*/
extern char *GetKernelVersionFromVersion()
{
static char Buf[BUFSIZ];
register char *p;
kvm_t *kd;
if (kd = KVM_open(VersionNL)) {
/*
* See if we got a valid entry
*/
if (CheckNlist(&VersionNL[N_VERSION]))
return((char *) NULL);
if (KVM_read(kd, VersionNL[N_VERSION].n_value, (char *) Buf,
sizeof(Buf))) {
if (Debug) Error("Read of \"%s\" from kernel failed.",
GetNlName(VersionNL[N_VERSION]));
Buf[0] = C_NULL;
}
}
if (kd)
KVM_close(kd);
#if defined(KERNSTR_END)
/*
* Truncate extraneous info
*/
if (Buf[0])
if ((p = index(Buf, KERNSTR_END)) != NULL)
*p = C_NULL;
#endif /* KERNSTR_END */
return( (Buf[0]) ? Buf : (char *) NULL);
}
#endif /* HAVE_KVM */
#endif /* HAVE_NLIST */