diff --git a/sbin/kldload/kldload.8 b/sbin/kldload/kldload.8 index 91b0c86c6d23..1adbe5202fd2 100644 --- a/sbin/kldload/kldload.8 +++ b/sbin/kldload/kldload.8 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 5, 2009 +.Dd March 18, 2012 .Dt KLDLOAD 8 .Os .Sh NAME @@ -33,7 +33,7 @@ .Nd load a file into the kernel .Sh SYNOPSIS .Nm -.Op Fl qv +.Op Fl nqv .Ar .Sh DESCRIPTION The @@ -62,6 +62,8 @@ in the current directory. .Pp The following options are available: .Bl -tag -width indent +.It Fl n +Don't try to load module if already loaded. .It Fl v Be more verbose. .It Fl q diff --git a/sbin/kldload/kldload.c b/sbin/kldload/kldload.c index 4d8d20a21843..84589eb49b12 100644 --- a/sbin/kldload/kldload.c +++ b/sbin/kldload/kldload.c @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #define PATHCTL "kern.module_path" @@ -129,7 +130,7 @@ path_check(const char *kldname, int quiet) static void usage(void) { - fprintf(stderr, "usage: kldload [-qv] file ...\n"); + fprintf(stderr, "usage: kldload [-nqv] file ...\n"); exit(1); } @@ -141,12 +142,14 @@ main(int argc, char** argv) int fileid; int verbose; int quiet; + int check_loaded; errors = 0; verbose = 0; quiet = 0; + check_loaded = 0; - while ((c = getopt(argc, argv, "qv")) != -1) { + while ((c = getopt(argc, argv, "nqv")) != -1) { switch (c) { case 'q': quiet = 1; @@ -156,6 +159,9 @@ main(int argc, char** argv) verbose = 1; quiet = 0; break; + case 'n': + check_loaded = 1; + break; default: usage(); } @@ -170,8 +176,14 @@ main(int argc, char** argv) if (path_check(argv[0], quiet) == 0) { fileid = kldload(argv[0]); if (fileid < 0) { - warn("can't load %s", argv[0]); - errors++; + if (check_loaded != 0 && errno == EEXIST) { + if (verbose) + printf("%s is already " + "loaded\n", argv[0]); + } else { + warn("can't load %s", argv[0]); + errors++; + } } else { if (verbose) printf("Loaded %s, id=%d\n", argv[0],