Linux 3.3 introduced the coresize attribute in /sys/module/*. When
available, use this instead of parsing some portion of /proc/modules.
---
libkmod/libkmod-module.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index fb3a64e..375c2a9 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -1686,7 +1686,6 @@ KMOD_EXPORT int kmod_module_get_initstate(const struct
kmod_module *mod)
*/
KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
{
- // FIXME TODO: this should be available from /sys/module/foo
FILE *fp;
char line[4096];
int lineno = 0;
@@ -1695,6 +1694,16 @@ KMOD_EXPORT long kmod_module_get_size(const struct
kmod_module *mod)
if (mod == NULL)
return -ENOENT;
+ /* available as of linux 3.3.x */
+ snprintf(line, sizeof(line), "/sys/module/%s/coresize", mod->name);
+ fp = fopen(line, "r");
+ if (fp != NULL) {
+ if (fscanf(fp, "%ld", &size) != 1)
+ size = -errno;
+ goto done;
+ }
+
+ /* fall back on parsing /proc/modules */
fp = fopen("/proc/modules", "re");
if (fp == NULL) {
int err = -errno;
@@ -1728,6 +1737,8 @@ KMOD_EXPORT long kmod_module_get_size(const struct
kmod_module *mod)
size = value;
break;
}
+
+done:
fclose(fp);
return size;
}
--
1.7.11.1
--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html