From 7386c5229413cf5854510293b5354c1edb72d33d Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 23 Sep 2005 23:52:26 +0000 Subject: Add '-q' option, which (when used with '-m' option) just tells if the given module is loaded or compiled into the kernel. This is useful mostly in startup scripts, when module should be loaded only if it wasn't compiled into the kernel nor already loaded, eg.: kldstat -q -m g_eli || kldload geom_eli.ko || err 1 'geom_eli module failed to load.' --- sbin/kldstat/kldstat.8 | 3 +++ sbin/kldstat/kldstat.c | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sbin/kldstat/kldstat.8 b/sbin/kldstat/kldstat.8 index b2b72c2..5a8565e 100644 --- a/sbin/kldstat/kldstat.8 +++ b/sbin/kldstat/kldstat.8 @@ -37,6 +37,7 @@ .Op Fl i Ar id .Op Fl n Ar filename .Nm +.Op Fl q .Op Fl m Ar modname .Sh DESCRIPTION The @@ -52,6 +53,8 @@ Be more verbose. Display the status of only the file with this ID. .It Fl n Ar filename Display the status of only the file with this filename. +.It Fl q +Only check if module is loaded or compiled into the kernel. .It Fl m Ar modname Display the status of only the module with this modname. .El diff --git a/sbin/kldstat/kldstat.c b/sbin/kldstat/kldstat.c index 20404d6..f9fd2c1 100644 --- a/sbin/kldstat/kldstat.c +++ b/sbin/kldstat/kldstat.c @@ -87,11 +87,12 @@ main(int argc, char** argv) int c; int verbose = 0; int fileid = 0; + int quiet = 0; char* filename = NULL; char* modname = NULL; char* p; - while ((c = getopt(argc, argv, "i:m:n:v")) != -1) + while ((c = getopt(argc, argv, "i:m:n:qv")) != -1) switch (c) { case 'i': fileid = (int)strtoul(optarg, &p, 10); @@ -104,6 +105,9 @@ main(int argc, char** argv) case 'n': filename = optarg; break; + case 'q': + quiet = 1; + break; case 'v': verbose = 1; break; @@ -120,8 +124,13 @@ main(int argc, char** argv) int modid; struct module_stat stat; - if ((modid = modfind(modname)) < 0) - err(1, "can't find module %s", modname); + if ((modid = modfind(modname)) < 0) { + if (!quiet) + warn("can't find module %s", modname); + return 1; + } else if (quiet) { + return 0; + } stat.version = sizeof(struct module_stat); if (modstat(modid, &stat) < 0) -- cgit v1.1