2 * Copyright (c) 2002, 2003 Greg Lehey
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * This software is provided by the author ``as is'' and any express
15 * or implied warranties, including, but not limited to, the implied
16 * warranties of merchantability and fitness for a particular purpose
17 * are disclaimed. In no event shall the author be liable for any
18 * direct, indirect, incidental, special, exemplary, or consequential
19 * damages (including, but not limited to, procurement of substitute
20 * goods or services; loss of use, data, or profits; or business
21 * interruption) however caused and on any theory of liability,
22 * whether in contract, strict liability, or tort (including
23 * negligence or otherwise) arising in any way out of the use of this
24 * software, even if advised of the possibility of such damage.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
40 * Get the linker file list from kldstat(8) output.
41 * The "run" flag tells if kldstat(8) should run now.
42 * Of course, kldstat(1) can run in a live system only, but its output
43 * can be saved beforehand and fed to this function later via stdin.
49 char *token[MAXTOKEN];
56 if ((kldstat = popen("kldstat", "r")) == NULL)
57 err(2, "can't start kldstat");
61 while (fgets(buf, sizeof(buf), kldstat)) {
62 /* Skip header line and main kernel file */
63 if (buf[0] == 'I' || strstr(buf, KERNFILE))
65 tokens = tokenize(buf, token, MAXTOKEN);
68 base = (caddr_t)(uintptr_t)strtoumax(token[2], &endp, 16);
69 if (endp == NULL || *endp != '\0')
71 kfile_add(token[4], base);