freebsd-dev/usr.sbin/asf/asf_kld.c
Yaroslav Tykhiy 0e4e809602 Give a major overhaul to asf(8).
The improvements are:

- can get the kld info from core files via kvm(3);
- can use kldstat(2) directly, which is a piece of cake;
- can use .symbols or whatever, which allows for use by
  non-developers when reporting system crashes -- now asf(8)
  can be mentioned in the handbook at last;
- speed (no more double fts(3) per loaded module);
- various bugs fixed.

At the same time, the new asf(8) should stay compatible with
the old one, bar bugs.  Perhaps some defaults may be changed
later to match today's state of affairs.

Reviewed by:	grog
MFC after:	1 month
Sponsored by:	RiNet (Cronyx Plus LLC)
2006-06-18 11:14:40 +00:00

60 lines
2.0 KiB
C

/*-
* Copyright (c) 2006 The FreeBSD Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/linker.h>
#include <err.h>
#include <string.h>
#include "asf.h"
/*
* Get the linker file list using the kld interface.
* Works with a live kernel only.
*/
void
asf_kld()
{
struct kld_file_stat kfs;
int fid = 0; /* indicates the beginning of the linker file list */
while ((fid = kldnext(fid)) != 0) {
if (fid == -1)
err(2, "kldnext");
kfs.version = sizeof(kfs); /* must be set for kldstat(2) */
/* Get info on this linker file */
if (kldstat(fid, &kfs) == -1)
err(2, "kldstat");
if (strcmp(kfs.name, KERNFILE) == 0)
continue;
/* Add to our list of linker files */
kfile_add(kfs.name, kfs.address);
}
}