aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Masters <jcm@jonmasters.org>2010-01-15 02:02:48 -0500
committerJon Masters <jcm@jonmasters.org>2010-01-15 02:02:48 -0500
commit29fc24a592a9e155a1bfd22e270b0b2c7c54871f (patch)
treed157729384fa767fc08e2272db7061f89247903e
parent70c4f735aa41f2f7db3a4e4488f3a98feaf1c729 (diff)
parent77e210c6be85871c655243fdd08da283167aca5b (diff)
downloadmodule-init-tools-29fc24a592a9e155a1bfd22e270b0b2c7c54871f.tar.gz
Merge branch 'master' of ../module-init-tools_alan
-rw-r--r--modprobe.c138
-rwxr-xr-xtests/test-modprobe/02proc.sh103
-rwxr-xr-xtests/test-modprobe/04config.sh72
-rwxr-xr-xtests/test-modprobe/12whitespace.sh57
-rwxr-xr-xtests/test-modprobe/22recursiveinstall.sh6
-rwxr-xr-xtests/test-modprobe/27cmdline-install-remove.sh3
6 files changed, 326 insertions, 53 deletions
diff --git a/modprobe.c b/modprobe.c
index f97f17d..6743759 100644
--- a/modprobe.c
+++ b/modprobe.c
@@ -520,6 +520,59 @@ static char *add_extra_options(const char *modname,
return optstring;
}
+/* Is module in /proc/modules? If so, fill in usecount if not NULL.
+ 0 means no, 1 means yes, -1 means unknown.
+ */
+static int module_in_procfs(const char *modname, unsigned int *usecount)
+{
+ FILE *proc_modules;
+ char *line;
+
+again:
+ /* Might not be mounted yet. Don't fail. */
+ proc_modules = fopen("/proc/modules", "r");
+ if (!proc_modules)
+ return -1;
+
+ while ((line = getline_wrapped(proc_modules, NULL)) != NULL) {
+ char *entry = strtok(line, " \n");
+
+ if (entry && streq(entry, modname)) {
+ /* If it exists, usecount is the third entry. */
+ if (!strtok(NULL, " \n"))
+ goto out;
+
+ if (!(entry = strtok(NULL, " \n"))) /* usecount */
+ goto out;
+ else
+ if (usecount)
+ *usecount = atoi(entry);
+
+ /* Followed by - then status. */
+ if (strtok(NULL, " \n")
+ && (entry = strtok(NULL, " \n")) != NULL) {
+ /* No locking, we might hit cases
+ * where module is in flux. Spin. */
+ if (streq(entry, "Loading")
+ || streq(entry, "Unloading")) {
+ usleep(100000);
+ free(line);
+ fclose(proc_modules);
+ goto again;
+ }
+ }
+
+ out:
+ free(line);
+ fclose(proc_modules);
+ return 1;
+ }
+ free(line);
+ }
+ fclose(proc_modules);
+ return 0;
+}
+
/* Read sysfs attribute into a buffer.
* returns: 1 = ok, 0 = attribute missing,
* -1 = file error (or empty file, but we don't care).
@@ -559,7 +612,7 @@ static int module_builtin(const char *dirname, const char *modname)
/* Is module in /sys/module? If so, fill in usecount if not NULL.
0 means no, 1 means yes, -1 means unknown.
*/
-static int module_in_kernel(const char *modname, unsigned int *usecount)
+static int module_in_sysfs(const char *modname, unsigned int *usecount)
{
int ret;
char *name;
@@ -579,14 +632,26 @@ static int module_in_kernel(const char *modname, unsigned int *usecount)
if (ret < 0)
return (errno == ENOENT) ? 0 : -1; /* Not found or unknown. */
- /* Wait for the existing module to either go live or disappear. */
nofail_asprintf(&name, "/sys/module/%s/initstate", modname);
- while (1) {
- ret = read_attribute(name, attr, ATTR_LEN);
- if (ret != 1 || streq(attr, "live\n"))
- break;
+ ret = read_attribute(name, attr, ATTR_LEN);
+ if (ret == 0) {
+ free(name);
+ nofail_asprintf(&name, "/sys/module/%s", modname);
+ if (stat(name, &finfo) < 0) {
+ /* module was removed before we could read initstate */
+ ret = 0;
+ } else {
+ /* initstate not available (2.6.19 or earlier) */
+ ret = -1;
+ }
+ free(name);
+ return ret;
+ }
+ /* Wait for the existing module to either go live or disappear. */
+ while (ret == 1 && !streq(attr, "live\n")) {
usleep(100000);
+ ret = read_attribute(name, attr, ATTR_LEN);
}
free(name);
@@ -605,6 +670,22 @@ static int module_in_kernel(const char *modname, unsigned int *usecount)
return 1;
}
+/* Is module loaded? If so, fill in usecount if not NULL.
+ 0 means no, 1 means yes, -1 means unknown.
+ */
+static int module_in_kernel(const char *modname, unsigned int *usecount)
+{
+ int result;
+
+ result = module_in_sysfs(modname, usecount);
+ if (result != -1)
+ return result;
+
+ /* /sys/module/%s/initstate is only available since 2.6.20,
+ fallback to /proc/modules to get module state on earlier kernels. */
+ return module_in_procfs(modname, usecount);
+}
+
void dump_modversions(const char *filename, errfn_t error)
{
struct elf_file *module;
@@ -1114,6 +1195,7 @@ static int insmod(struct list_head *list,
const char *command;
struct module *mod = list_entry(list->next, struct module, list);
int rc = 0;
+ int already_loaded;
/* Take us off the list. */
list_del(&mod->list);
@@ -1140,8 +1222,9 @@ static int insmod(struct list_head *list,
}
/* Don't do ANYTHING if already in kernel. */
- if (!(flags & mit_ignore_loaded)
- && module_in_kernel(newname ?: mod->modname, NULL) == 1) {
+ already_loaded = module_in_kernel(newname ?: mod->modname, NULL);
+
+ if (!(flags & mit_ignore_loaded) && already_loaded == 1) {
if (flags & mit_first_time)
error("Module %s already in kernel.\n",
newname ?: mod->modname);
@@ -1150,10 +1233,18 @@ static int insmod(struct list_head *list,
command = find_command(mod->modname, commands);
if (command && !(flags & mit_ignore_commands)) {
- close_file(fd);
- do_command(mod->modname, command, flags & mit_dry_run, error,
- "install", cmdline_opts);
- goto out_optstring;
+ if (already_loaded == -1) {
+ warn("/sys/module/ not present or too old,"
+ " and /proc/modules does not exist.\n");
+ warn("Ignoring install commands for %s"
+ " in case it is already loaded.\n",
+ newname ?: mod->modname);
+ } else {
+ close_file(fd);
+ do_command(mod->modname, command, flags & mit_dry_run,
+ error, "install", cmdline_opts);
+ goto out_optstring;
+ }
}
module = grab_elf_file_fd(mod->filename, fd);
@@ -1214,6 +1305,7 @@ static void rmmod(struct list_head *list,
const char *command;
unsigned int usecount = 0;
struct module *mod = list_entry(list->next, struct module, list);
+ int exists;
/* Take first one off the list. */
list_del(&mod->list);
@@ -1221,17 +1313,27 @@ static void rmmod(struct list_head *list,
if (!name)
name = mod->modname;
+ /* Don't do ANYTHING if not loaded. */
+ exists = module_in_kernel(name, &usecount);
+ if (exists == 0)
+ goto nonexistent_module;
+
/* Even if renamed, find commands to orig. name. */
command = find_command(mod->modname, commands);
if (command && !(flags & mit_ignore_commands)) {
- do_command(mod->modname, command, flags & mit_dry_run, error,
- "remove", cmdline_opts);
- goto remove_rest;
+ if (exists == -1) {
+ warn("/sys/module/ not present or too old,"
+ " and /proc/modules does not exist.\n");
+ warn("Ignoring remove commands for %s"
+ " in case it is not loaded.\n",
+ mod->modname);
+ } else {
+ do_command(mod->modname, command, flags & mit_dry_run,
+ error, "remove", cmdline_opts);
+ goto remove_rest;
+ }
}
- if (module_in_kernel(name, &usecount) == 0)
- goto nonexistent_module;
-
if (usecount != 0) {
if (!(flags & mit_ignore_loaded))
error("Module %s is in use.\n", name);
diff --git a/tests/test-modprobe/02proc.sh b/tests/test-modprobe/02proc.sh
new file mode 100755
index 0000000..d7db770
--- /dev/null
+++ b/tests/test-modprobe/02proc.sh
@@ -0,0 +1,103 @@
+#! /bin/sh
+
+# Test handling of /proc/modules.
+
+BITNESS=32
+
+rm -rf tests/tmp/*
+
+# Create inputs
+MODULE_DIR=tests/tmp/lib/modules/$MODTEST_UNAME
+mkdir -p $MODULE_DIR
+ln tests/data/$BITNESS/normal/export_nodep-$BITNESS.ko \
+ tests/data/$BITNESS/normal/noexport_nodep-$BITNESS.ko \
+ $MODULE_DIR
+
+mkdir tests/tmp/proc
+
+# Now create modules.dep
+cat > tests/tmp/lib/modules/$MODTEST_UNAME/modules.dep <<EOF
+noexport_nodep-$BITNESS.ko:
+export_nodep-$BITNESS.ko:
+EOF
+
+SIZE_NOEXPORT_NODEP=$(echo `wc -c < tests/data/$BITNESS/normal/noexport_nodep-$BITNESS.ko`)
+SIZE_EXPORT_NODEP=$(echo `wc -c < tests/data/$BITNESS/normal/export_nodep-$BITNESS.ko`)
+
+# If it can't open /proc/modules, it should try anyway.
+rm -f tests/tmp/proc/modules
+
+[ "`modprobe noexport_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP " ]
+[ "`modprobe export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
+
+[ "`modprobe -r noexport_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_nodep_$BITNESS EXCL " ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+
+# If it doesn't exist in /proc/modules, remove should succeed.
+touch tests/tmp/proc/modules
+[ "`modprobe noexport_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP " ]
+[ "`modprobe export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
+[ "`modprobe -r -v noexport_nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -r -v export_nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -r -v noexport-nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -r -v export-nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+# ... unless --first-time is specified (won't print status due to set -e).
+[ "`modprobe --first-time -r noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is not in kernel." ]
+[ "`modprobe --first-time -r export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is not in kernel." ]
+[ "`modprobe --first-time -r noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is not in kernel." ]
+[ "`modprobe --first-time -r export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is not in kernel." ]
+
+# Old-style /proc (no unload support).
+echo "noexport_nodep_$BITNESS $SIZE_NOEXPORT_NODEP" > tests/tmp/proc/modules
+echo "export_nodep_$BITNESS $SIZE_EXPORT_NODEP" >> tests/tmp/proc/modules
+
+# If it does exist, insertion should "succeed".
+[ "`modprobe -v noexport_nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -v export_nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -v noexport-nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+[ "`modprobe -v export-nodep-$BITNESS 2>&1; echo $?`" = "0" ]
+# .. unless --first-time is specified.
+[ "`modprobe --first-time noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+
+# Removal should still try.
+[ "`modprobe -r noexport_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_nodep_$BITNESS EXCL " ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+
+# New-style /proc without unload support
+echo "noexport_nodep_$BITNESS $SIZE_NOEXPORT_NODEP - -" > tests/tmp/proc/modules
+echo "export_nodep_$BITNESS $SIZE_EXPORT_NODEP - -" >> tests/tmp/proc/modules
+
+[ "`modprobe --first-time noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+# Removal should still try.
+[ "`modprobe -r noexport_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_nodep_$BITNESS EXCL " ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+
+# Should fail if refcounts non-zero. Old-style
+echo "noexport_nodep_$BITNESS $SIZE_NOEXPORT_NODEP 1" > tests/tmp/proc/modules
+echo "export_nodep_$BITNESS $SIZE_EXPORT_NODEP 1" >> tests/tmp/proc/modules
+
+[ "`modprobe -r noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is in use." ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is in use." ]
+[ "`modprobe -r noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is in use." ]
+[ "`modprobe -r export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is in use." ]
+
+# New-style /proc
+echo "noexport_nodep_$BITNESS $SIZE_NOEXPORT_NODEP 1 -" > tests/tmp/proc/modules
+echo "export_nodep_$BITNESS $SIZE_EXPORT_NODEP 1 something_else, extrafield" >> tests/tmp/proc/modules
+
+[ "`modprobe --first-time noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS already in kernel." ]
+[ "`modprobe --first-time export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS already in kernel." ]
+
+[ "`modprobe -r noexport_nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is in use." ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is in use." ]
+[ "`modprobe -r noexport-nodep-$BITNESS 2>&1`" = "FATAL: Module noexport_nodep_$BITNESS is in use." ]
+[ "`modprobe -r export-nodep-$BITNESS 2>&1`" = "FATAL: Module export_nodep_$BITNESS is in use." ]
+
diff --git a/tests/test-modprobe/04config.sh b/tests/test-modprobe/04config.sh
index cb85422..342cc18 100755
--- a/tests/test-modprobe/04config.sh
+++ b/tests/test-modprobe/04config.sh
@@ -88,38 +88,29 @@ SIZE_NOEXPORT_DEP=`wc -c < tests/data/$BITNESS/normal/noexport_dep-$BITNESS.ko`
SIZE_EXPORT_DEP=`wc -c < tests/data/$BITNESS/normal/export_dep-$BITNESS.ko`
SIZE_NOEXPORT_DOUBLEDEP=`wc -c < tests/data/$BITNESS/normal/noexport_doubledep-$BITNESS.ko`
-# Test ignoring install & remove.
+# Empty /sys/module/ for install commands
+mkdir -p tests/tmp/sys/module
+# Test ignoring install commands
[ "`modprobe --ignore-install export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
[ "`modprobe -i export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
[ "`modprobe -i foo 2>&1`" = "FATAL: Module foo not found." ]
-[ "`modprobe -r --ignore-remove export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
-[ "`modprobe -r -i export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
-[ "`modprobe -i -r foo 2>&1`" = "FATAL: Module foo not found." ]
-# Test install & remove (fake modules)
+# Test install commands (fake modules)
[ "`modprobe foo 2>&1`" = "SYSTEM: echo Installing foo" ]
[ "`modprobe bar 2>&1`" = "SYSTEM: echo Installing bar" ]
[ "`modprobe baz 2>&1`" = "SYSTEM: echo Installing baz" ]
-[ "`modprobe -r foo 2>&1`" = "SYSTEM: echo Removing foo" ]
-[ "`modprobe -r bar 2>&1`" = "SYSTEM: echo Removing bar" ]
-[ "`modprobe -r baz 2>&1`" = "SYSTEM: echo Removing baz" ]
-# Test install & remove of a what is also a real module.
+# Test install of a what is also a real module.
[ "`modprobe export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep" ]
-[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Removing export_nodep" ]
-# Test install & remove of what is also a real module via dependency.
+# Test install of what is also a real module via dependency.
[ "`modprobe noexport_dep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep
INIT_MODULE: $SIZE_NOEXPORT_DEP I am noexport_dep" ]
-[ "`modprobe -r noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
-SYSTEM: echo Removing export_nodep" ]
-# Test ignoring install & remove: only effects commandline.
+# Test ignoring install commands: only effects commandline.
[ "`modprobe -i noexport_dep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep
INIT_MODULE: $SIZE_NOEXPORT_DEP I am noexport_dep" ]
-[ "`modprobe -r -i noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
-SYSTEM: echo Removing export_nodep" ]
# Test options
[ "`modprobe noexport_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP I am noexport_nodep" ]
@@ -173,6 +164,39 @@ INIT_MODULE: $SIZE_NOEXPORT_DOUBLEDEP I am noexport_doubledep I am alias to noex
# Test tab-to-spaces conversion, and \ wrapping.
[ "`modprobe alias_to_noexport_nodep-$BITNESS_with_tabbed_options 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP I am noexport_nodep index=0 id=\"Thinkpad\" isapnp=0 port=0x530 cport=0x538 fm_port=0x388 mpu_port=-1 mpu_irq=-1 irq=9 dma1=1 dma2=3 enable=1 isapnp=0" ]
+# Populate /sys/module/ for remove commands
+mkdir -p tests/tmp/sys/module/noexport_nodep_$BITNESS
+mkdir -p tests/tmp/sys/module/noexport_dep_$BITNESS
+mkdir -p tests/tmp/sys/module/noexport_doubledep_$BITNESS
+mkdir -p tests/tmp/sys/module/export_nodep_$BITNESS
+mkdir -p tests/tmp/sys/module/export_dep_$BITNESS
+echo live > tests/tmp/sys/module/noexport_nodep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/noexport_dep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/noexport_doubledep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/export_nodep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/export_dep_$BITNESS/initstate
+
+# Test ignoring remove commands.
+[ "`modprobe -r --ignore-remove export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+[ "`modprobe -r -i export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+[ "`modprobe -i -r foo 2>&1`" = "FATAL: Module foo not found." ]
+
+# Test remove commands (fake modules)
+[ "`modprobe -r foo 2>&1`" = "SYSTEM: echo Removing foo" ]
+[ "`modprobe -r bar 2>&1`" = "SYSTEM: echo Removing bar" ]
+[ "`modprobe -r baz 2>&1`" = "SYSTEM: echo Removing baz" ]
+
+# Test remove of a what is also a real module.
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Removing export_nodep" ]
+
+# Test remove of what is also a real module via dependency.
+[ "`modprobe -r noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
+SYSTEM: echo Removing export_nodep" ]
+
+# Test ignoring remove commands: only effects commandline.
+[ "`modprobe -r -i noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
+SYSTEM: echo Removing export_nodep" ]
+
# Test aliases doing removal.
[ "`modprobe -r alias_to_noexport_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_nodep_$BITNESS EXCL " ]
[ "`modprobe -r alias_to_noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
@@ -186,3 +210,19 @@ SYSTEM: echo Removing export_nodep" ]
[ "`modprobe -r alias_to_foo 2>&1`" = "SYSTEM: echo Removing foo" ]
[ "`modprobe -r alias_to_bar 2>&1`" = "SYSTEM: echo Removing bar" ]
[ "`modprobe -r alias_to_baz 2>&1`" = "SYSTEM: echo Removing baz" ]
+
+# Now test install precaution in the absence of /sys/modules
+rm -r tests/tmp/sys/module
+
+# Test install and remove commands (fake modules)
+# No caution necessary here
+[ "`modprobe foo 2>&1`" = "SYSTEM: echo Installing foo" ]
+[ "`modprobe -r foo 2>&1`" = "SYSTEM: echo Removing foo" ]
+
+# Test install and remove of a what is also a real module.
+[ "`modprobe export_nodep-$BITNESS 2>&1`" = "WARNING: /sys/module/ not present or too old, and /proc/modules does not exist.
+WARNING: Ignoring install commands for export_nodep_$BITNESS in case it is already loaded.
+INIT_MODULE: $SIZE_EXPORT_NODEP " ]
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "WARNING: /sys/module/ not present or too old, and /proc/modules does not exist.
+WARNING: Ignoring remove commands for export_nodep_$BITNESS in case it is not loaded.
+DELETE_MODULE: export_nodep_32 EXCL " ]
diff --git a/tests/test-modprobe/12whitespace.sh b/tests/test-modprobe/12whitespace.sh
index 159c4c2..5a1d817 100755
--- a/tests/test-modprobe/12whitespace.sh
+++ b/tests/test-modprobe/12whitespace.sh
@@ -82,38 +82,29 @@ SIZE_NOEXPORT_DEP=`wc -c < tests/data/$BITNESS/normal/noexport_dep-$BITNESS.ko`
SIZE_EXPORT_DEP=`wc -c < tests/data/$BITNESS/normal/export_dep-$BITNESS.ko`
SIZE_NOEXPORT_DOUBLEDEP=`wc -c < tests/data/$BITNESS/normal/noexport_doubledep-$BITNESS.ko`
-# Test ignoring install & remove.
+# Empty /sys/module/ for install commands
+mkdir -p tests/tmp/sys/module
+# Test ignoring install commands.
[ "`modprobe --ignore-install export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
[ "`modprobe -i export_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP " ]
[ "`modprobe -i foo 2>&1`" = "FATAL: Module foo not found." ]
-[ "`modprobe -r --ignore-remove export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
-[ "`modprobe -r -i export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
-[ "`modprobe -i -r foo 2>&1`" = "FATAL: Module foo not found." ]
-# Test install & remove (fake modules)
+# Test install commands (fake modules)
[ "`modprobe foo 2>&1`" = "SYSTEM: echo Installing foo" ]
[ "`modprobe bar 2>&1`" = "SYSTEM: echo Installing bar" ]
[ "`modprobe baz 2>&1`" = "SYSTEM: echo Installing baz" ]
-[ "`modprobe -r foo 2>&1`" = "SYSTEM: echo Removing foo" ]
-[ "`modprobe -r bar 2>&1`" = "SYSTEM: echo Removing bar" ]
-[ "`modprobe -r baz 2>&1`" = "SYSTEM: echo Removing baz" ]
-# Test install & remove of a what is also a real module.
+# Test install of a what is also a real module.
[ "`modprobe export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep" ]
-[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Removing export_nodep" ]
-# Test install & remove of what is also a real module via dependency.
+# Test install of what is also a real module via dependency.
[ "`modprobe noexport_dep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep
INIT_MODULE: $SIZE_NOEXPORT_DEP I am noexport_dep" ]
-[ "`modprobe -r noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
-SYSTEM: echo Removing export_nodep" ]
-# Test ignoring install & remove: only effects commandline.
+# Test ignoring install commands: only effects commandline.
[ "`modprobe -i noexport_dep-$BITNESS 2>&1`" = "SYSTEM: echo Installing export_nodep
INIT_MODULE: $SIZE_NOEXPORT_DEP I am noexport_dep" ]
-[ "`modprobe -r -i noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
-SYSTEM: echo Removing export_nodep" ]
# Test options
[ "`modprobe noexport_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP I am noexport_nodep" ]
@@ -164,6 +155,40 @@ INIT_MODULE: $SIZE_NOEXPORT_DOUBLEDEP I am noexport_doubledep I am alias to noex
[ "`modprobe alias_to_bar 2>&1`" = "SYSTEM: echo Installing bar" ]
[ "`modprobe alias_to_baz 2>&1`" = "SYSTEM: echo Installing baz" ]
+# Populate /sys/module/ for remove commands
+mkdir -p tests/tmp/sys/module/noexport_nodep_$BITNESS
+mkdir -p tests/tmp/sys/module/noexport_dep_$BITNESS
+mkdir -p tests/tmp/sys/module/noexport_doubledep_$BITNESS
+mkdir -p tests/tmp/sys/module/export_nodep_$BITNESS
+mkdir -p tests/tmp/sys/module/export_dep_$BITNESS
+echo live > tests/tmp/sys/module/noexport_nodep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/noexport_dep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/noexport_doubledep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/export_nodep_$BITNESS/initstate
+echo live > tests/tmp/sys/module/export_dep_$BITNESS/initstate
+
+# Test ignoring remove commands.
+
+[ "`modprobe -r --ignore-remove export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+[ "`modprobe -r -i export_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: export_nodep_$BITNESS EXCL " ]
+[ "`modprobe -i -r foo 2>&1`" = "FATAL: Module foo not found." ]
+
+# Test remove commands (fake modules)
+[ "`modprobe -r foo 2>&1`" = "SYSTEM: echo Removing foo" ]
+[ "`modprobe -r bar 2>&1`" = "SYSTEM: echo Removing bar" ]
+[ "`modprobe -r baz 2>&1`" = "SYSTEM: echo Removing baz" ]
+
+# Test remove of a what is also a real module.
+[ "`modprobe -r export_nodep-$BITNESS 2>&1`" = "SYSTEM: echo Removing export_nodep" ]
+
+# Test remove of what is also a real module via dependency.
+[ "`modprobe -r noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
+SYSTEM: echo Removing export_nodep" ]
+
+# Test ignoring remove commands: only effects commandline.
+[ "`modprobe -r -i noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
+SYSTEM: echo Removing export_nodep" ]
+
# Test aliases doing removal.
[ "`modprobe -r alias_to_noexport_nodep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_nodep_$BITNESS EXCL " ]
[ "`modprobe -r alias_to_noexport_dep-$BITNESS 2>&1`" = "DELETE_MODULE: noexport_dep_$BITNESS EXCL
diff --git a/tests/test-modprobe/22recursiveinstall.sh b/tests/test-modprobe/22recursiveinstall.sh
index 0c98e1a..53b0c60 100755
--- a/tests/test-modprobe/22recursiveinstall.sh
+++ b/tests/test-modprobe/22recursiveinstall.sh
@@ -28,7 +28,7 @@ mkdir -p tests/tmp/sys/module
[ "`modprobe noexport_dep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_EXPORT_NODEP
INIT_MODULE: $SIZE_NOEXPORT_DEP " ]
-# Check it's happy if we tell it dep is already instealled
+# Check it's happy if we tell it dep is already installed
mkdir -p tests/tmp/sys/module
mkdir -p tests/tmp/sys/module/export_nodep_$BITNESS
echo "live" >tests/tmp/sys/module/export_nodep_$BITNESS/initstate
@@ -37,7 +37,7 @@ echo "live" >tests/tmp/sys/module/export_nodep_$BITNESS/initstate
# If there's an install command, it will be done.
# Clean up sysfs (so we don't think it's loaded)
-rm -rf tests/tmp/sys
+rm -rf tests/tmp/sys/module/*
mkdir -p tests/tmp/etc/modprobe.d
echo "install export_nodep-$BITNESS COMMAND" > tests/tmp/etc/modprobe.d/modprobe.conf
@@ -53,7 +53,7 @@ echo "live" >tests/tmp/sys/module/export_nodep_$BITNESS/initstate
# Do dependencies even if install command.
# clean up sysfs (so we don't think it's loaded)
-rm -rf tests/tmp/sys
+rm -rf tests/tmp/sys/module/*
echo "install noexport_dep-$BITNESS COMMAND" > tests/tmp/etc/modprobe.d/modprobe.conf
diff --git a/tests/test-modprobe/27cmdline-install-remove.sh b/tests/test-modprobe/27cmdline-install-remove.sh
index fef02ff..9411222 100755
--- a/tests/test-modprobe/27cmdline-install-remove.sh
+++ b/tests/test-modprobe/27cmdline-install-remove.sh
@@ -19,6 +19,9 @@ echo "options noexport_nodep-$BITNESS file-options" > tests/tmp/etc/modprobe.d/m
echo "install noexport_nodep-$BITNESS modprobe --ignore-install noexport_nodep-$BITNESS \$CMDLINE_OPTS" >> tests/tmp/etc/modprobe.d/modprobe.conf
echo "install othertarget echo \$CMDLINE_OPTS otheropts" >> tests/tmp/etc/modprobe.d/modprobe.conf
+# Empty /sys/module/ for install commands
+mkdir -p tests/tmp/sys/module
+
# With quoted args
[ "`modprobe noexport_nodep-$BITNESS 'foo="bar baz"' 2>&1`" = "SYSTEM: modprobe --ignore-install noexport_nodep-$BITNESS foo=\"bar baz\"" ]
# With unquoted args