From 24e85f818119c56ac69d228f6d07224111a0d88d Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Wed, 11 Feb 2009 16:18:24 +0000 Subject: [PATCH] Survive "/sys is not mounted" modprobe used to be able to work if /proc was not mounted; the tests required it. Let's keep it that way with /sys too. Signed-off-by: Alan Jenkins --- modprobe.c | 11 +++++------ tests/test-modprobe/02sys.sh | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/modprobe.c b/modprobe.c index 6bc2617..2f72040 100644 --- a/modprobe.c +++ b/modprobe.c @@ -761,7 +761,11 @@ static int module_in_kernel(const char *modname, unsigned int *usecount) const int ATTR_LEN = 16; char attr[ATTR_LEN]; - /* Find module. We assume sysfs is mounted. */ + /* Check sysfs is mounted */ + if (stat("/sys/module", &finfo) < 0) + return -1; + + /* Find module. */ nofail_asprintf(&name, "/sys/module/%s", modname); ret = stat(name, &finfo); free(name); @@ -1533,11 +1537,6 @@ static void handle_module(const char *modname, const char *cmdline_opts, int flags) { - struct stat finfo; - - if (stat("/sys/module", &finfo) < 0) - fatal("/sys is not mounted.\n"); - if (list_empty(todo_list)) { const char *command; diff --git a/tests/test-modprobe/02sys.sh b/tests/test-modprobe/02sys.sh index e8967a2..264b2be 100755 --- a/tests/test-modprobe/02sys.sh +++ b/tests/test-modprobe/02sys.sh @@ -45,6 +45,10 @@ MODTEST_OVERRIDE10=/sys/module/export_nodep_$BITNESS/initstate MODTEST_OVERRIDE_WITH10=tests/tmp/sys/module/export_nodep_$BITNESS/initstate export MODTEST_OVERRIDE10 MODTEST_OVERRIDE_WITH10 +MODTEST_OVERRIDE11=/sys/module +MODTEST_OVERRIDE_WITH11=tests/tmp/sys/module +export MODTEST_OVERRIDE11 MODTEST_OVERRIDE_WITH11 + # Now create modules.dep cat > tests/tmp/modules.dep <&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 " ] + # Now make a fake /sys/module structure for the test mkdir -p tests/tmp/sys/module mkdir -p tests/tmp/sys/module/noexport_nodep_$BITNESS @@ -65,11 +83,6 @@ mkdir -p tests/tmp/sys/module/export_nodep_$BITNESS touch tests/tmp/sys/module/noexport_nodep_$BITNESS/initstate touch tests/tmp/sys/module/export_nodep_$BITNESS/initstate -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`) - -# TODO: maybe make this more complete (like the original 02proc.sh) - # Test load the modules [ "`./modprobe noexport_nodep-$BITNESS 2>&1`" = "INIT_MODULE: $SIZE_NOEXPORT_NODEP " ] -- 2.11.4.GIT