ftp.nice.ch/pub/next/unix/admin/sysinfo.1.1.0.s.tar.gz#/kernel.c

This is kernel.c in view mode; [Download] [Up]

/*
 * 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.10 1992/11/24 04:05:57 mcooper Exp mcooper $";
#endif

/*
 * $Log: kernel.c,v $
 * Revision 1.10  1992/11/24  04:05:57  mcooper
 * New/cleaner KVM/nlist interface.
 *
 * Revision 1.9  1992/07/07  23:28:38  mcooper
 * Put wrapper macro around nlist stuff to fix NeXT/Mach declaration
 * problem.  Now works with NeXT 2.* cc compiler.
 *
 * 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>

#if	defined(HAVE_KVM)
char 	VersionSYM[] = "_version";

/*
 * Get kernel version string by reading the
 * symbol "version" from the kernel.
 */
extern char *GetKernelVersionFromVersion()
{
    struct nlist	       *nlptr;
    static char			Buf[BUFSIZ];
    register char	       *p;
    kvm_t		       *kd;

    if (kd = KVMopen()) {
	if ((nlptr = KVMnlist(kd, VersionSYM, (struct nlist *)NULL)) == NULL)
	    return((char *) NULL);


	if (CheckNlist(nlptr))
	    return((char *) NULL);

	if (KVMread(kd, nlptr->n_value, (char *) Buf, sizeof(Buf))) {
	    if (Debug) Error("Read of \"%s\" from kernel failed.",
			     VersionSYM);
	    Buf[0] = C_NULL;
	}
    }

    if (kd)
	KVMclose(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 */

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.