aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Dechamps <[email protected]>2012-07-04 15:56:40 +0200
committerBrian Behlendorf <[email protected]>2012-07-26 13:45:33 -0700
commitf09398cec665259a4c2f96726680fbd3b0a3bac3 (patch)
tree6d0a0ac214722eebcfb4675ce37d56e4b67f8877
parent2ee4a18b2ac9c155e099db06cec320bd8cee3150 (diff)
Use /sys/module instead of /proc/modules.
When libzfs checks if the module is loaded or not, it currently reads /proc/modules and searches for a line matching the module name. Unfortunately, if the module is included in the kernel itself (built-in module), then /proc/modules won't list it, so libzfs will wrongly conclude that the module is not loaded, thus making all ZFS userspace tools unusable. Fortunately, all loaded modules appear as directories in /sys/module, even built-in ones. Thus we can use /sys/module in lieu of /proc/modules to fix the issue. As a bonus, the code for checking becomes much simpler. Signed-off-by: Brian Behlendorf <[email protected]> Issue #851
-rw-r--r--lib/libzfs/libzfs_util.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c
index 982a6f05f..5618a5cd3 100644
--- a/lib/libzfs/libzfs_util.c
+++ b/lib/libzfs/libzfs_util.c
@@ -608,27 +608,13 @@ libzfs_print_on_error(libzfs_handle_t *hdl, boolean_t printerr)
static int
libzfs_module_loaded(const char *module)
{
- FILE *f;
- int result = 0;
- char name[256];
+ const char path_prefix[] = "/sys/module/";
+ char path[256];
- f = fopen("/proc/modules", "r");
- if (f == NULL)
- return -1;
+ memcpy(path, path_prefix, sizeof(path_prefix) - 1);
+ strcpy(path + sizeof(path_prefix) - 1, module);
- while (fgets(name, sizeof(name), f)) {
- char *c = strchr(name, ' ');
- if (!c)
- continue;
- *c = 0;
- if (strcmp(module, name) == 0) {
- result = 1;
- break;
- }
- }
- fclose(f);
-
- return result;
+ return (access(path, F_OK) == 0);
}
int