CFR: sanity checking arguments to kldload(8)

From: Benno Rice <benno_at_jeamland.net>
Date: Wed, 3 Jun 2009 13:03:08 +1000
The attached patch performs some sanity checking on arguments passed  
to kldload(8).  Specifically, if an argument looks like a filename but  
lacks a path (eg, 'xfs.ko' as opposed to 'xfs' or './xfs.ko') it  
checks to see if a file with that name is in the current directory.   
If it is, it checks the current module path to see if a file with that  
name also exists there (possibly in an earlier entry if the current  
directory is in the module path), if so it warns the user that that  
module will be loaded and not the one in the current directory.  If  
not, it tells the user how to use a path to load the module.

A -q option is added to quieten the output if desired.

Sample output:

# sysctl kern.module_path
kern.module_path: /boot/kernel;/boot/modules
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# pwd
/boot/kernel
# kldload xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# cd /boot/modules
# pwd
/boot/modules
# ls
xfs.ko*		xfs.ko.symbols*
# kldload xfs.ko
kldload: xfs.ko will be loaded from /boot/kernel, not the current  
directory
kldload: to load from the current directory use ./xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# kldload -q xfs.ko
# kldstat
Id Refs Address    Size     Name
  1    3 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b0000    xfs.ko
# kldunload xfs
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# cd fnord
# pwd
/boot/modules/fnord
# ls
ibcs2.ko*		ibcs2.ko.symbols*
# ls /boot/kernel/ibcs2.ko
ls: /boot/kernel/ibcs2.ko: No such file or directory
# ls /boot/modules/ibcs2.ko
ls: /boot/modules/ibcs2.ko: No such file or directory
# kldload ibcs2.ko
kldload: ibcs2.ko is not in the module path
kldload: to load from the current directory use ./ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# kldload -q ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel
# kldload ./ibcs2.ko
# kldstat
Id Refs Address    Size     Name
  1    6 0xc0400000 cc016c   kernel
  2    1 0xc3a09000 b000     ibcs2.ko
# kldunload ibcs2
# kldstat
Id Refs Address    Size     Name
  1    1 0xc0400000 cc016c   kernel




-- 
Benno Rice
benno_at_jeamland.net




Received on Wed Jun 03 2009 - 01:18:49 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:49 UTC