Date: Tue, 27 Mar 2012 15:29:51 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r233560 - stable/9/sbin/kldload Message-ID: <201203271529.q2RFTprZ092279@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Tue Mar 27 15:29:51 2012 New Revision: 233560 URL: http://svn.freebsd.org/changeset/base/233560 Log: MFC r233109: Add option to ignore error codes if the module specified is already loaded. Modified: stable/9/sbin/kldload/kldload.8 stable/9/sbin/kldload/kldload.c Directory Properties: stable/9/sbin/kldload/ (props changed) Modified: stable/9/sbin/kldload/kldload.8 ============================================================================== --- stable/9/sbin/kldload/kldload.8 Tue Mar 27 15:27:36 2012 (r233559) +++ stable/9/sbin/kldload/kldload.8 Tue Mar 27 15:29:51 2012 (r233560) @@ -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 Modified: stable/9/sbin/kldload/kldload.c ============================================================================== --- stable/9/sbin/kldload/kldload.c Tue Mar 27 15:27:36 2012 (r233559) +++ stable/9/sbin/kldload/kldload.c Tue Mar 27 15:29:51 2012 (r233560) @@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <errno.h> #define PATHCTL "kern.module_path" @@ -129,7 +130,7 @@ path_check(const char *kldname, int quie 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],
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203271529.q2RFTprZ092279>