diff options
| author | pooka <pooka@NetBSD.org> | 2010-03-19 16:25:33 +0000 |
|---|---|---|
| committer | pooka <pooka@NetBSD.org> | 2010-03-19 16:25:33 +0000 |
| commit | 23d5534a559e2cb5bdf8d04a70ec625e54471e43 (patch) | |
| tree | c82e79c531b45b51c3bf23e380e10b187c7010fa /sbin/modstat | |
| parent | 8058413106db4da60769583b1e0d575046b1ecfb (diff) | |
Avoid known unknown if the kernel presents us with an unknown
unknown for module class and/or source.
related to PR kern/43014
Diffstat (limited to 'sbin/modstat')
| -rw-r--r-- | sbin/modstat/main.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/sbin/modstat/main.c b/sbin/modstat/main.c index 975b7adb473..c17fa138dae 100644 --- a/sbin/modstat/main.c +++ b/sbin/modstat/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.9 2010/03/05 10:27:16 pooka Exp $ */ +/* $NetBSD: main.c,v 1.10 2010/03/19 16:25:33 pooka Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: main.c,v 1.9 2010/03/05 10:27:16 pooka Exp $"); +__RCSID("$NetBSD: main.c,v 1.10 2010/03/19 16:25:33 pooka Exp $"); #endif /* !lint */ #include <sys/module.h> @@ -51,12 +51,14 @@ static const char *classes[] = { "exec", "secmodel", }; +const unsigned int class_max = __arraycount(classes); static const char *sources[] = { "builtin", "boot", "filesys", }; +const unsigned int source_max = __arraycount(sources); int main(int argc, char **argv) @@ -104,6 +106,9 @@ main(int argc, char **argv) len = iov.iov_len / sizeof(modstat_t); qsort(iov.iov_base, len, sizeof(modstat_t), modstatcmp); for (ms = iov.iov_base; len != 0; ms++, len--) { + const char *class; + const char *source; + if (name != NULL && strcmp(ms->ms_name, name) != 0) { continue; } @@ -117,9 +122,18 @@ main(int argc, char **argv) } else { snprintf(sbuf, sizeof(sbuf), "%u", ms->ms_size); } + if (ms->ms_class <= class_max) + class = classes[ms->ms_class]; + else + class = "UNKNOWN"; + if (ms->ms_source < source_max) + source = sources[ms->ms_source]; + else + source = "UNKNOWN"; + printf("%-16s %-10s %-10s %-5d %-8s %s\n", - ms->ms_name, classes[ms->ms_class], sources[ms->ms_source], - ms->ms_refcnt, sbuf, ms->ms_required); + ms->ms_name, class, source, ms->ms_refcnt, sbuf, + ms->ms_required); } exit(EXIT_SUCCESS); @@ -143,4 +157,3 @@ modstatcmp(const void *a, const void *b) return strcmp(msa->ms_name, msb->ms_name); } - |
