Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Mar 2012 09:45:43 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r233109 - head/sbin/kldload
Message-ID:  <201203180945.q2I9jhIE011537@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Sun Mar 18 09:45:43 2012
New Revision: 233109
URL: http://svn.freebsd.org/changeset/base/233109

Log:
  Add option to ignore error codes if the module specified is already loaded.
  
  MFC after:	1 week

Modified:
  head/sbin/kldload/kldload.8
  head/sbin/kldload/kldload.c

Modified: head/sbin/kldload/kldload.8
==============================================================================
--- head/sbin/kldload/kldload.8	Sun Mar 18 09:19:40 2012	(r233108)
+++ head/sbin/kldload/kldload.8	Sun Mar 18 09:45:43 2012	(r233109)
@@ -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: head/sbin/kldload/kldload.c
==============================================================================
--- head/sbin/kldload/kldload.c	Sun Mar 18 09:19:40 2012	(r233108)
+++ head/sbin/kldload/kldload.c	Sun Mar 18 09:45:43 2012	(r233109)
@@ -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?201203180945.q2I9jhIE011537>