From: Nikolay Amiantov <ab@fmap.me>
To: linux-modules@vger.kernel.org
Cc: Shea Levy <shea@shealevy.com>, Nikolay Amiantov <ab@fmap.me>
Subject: [PATCH 3/4] static-nodes: use kmod to get modules directory
Date: Tue, 16 Aug 2016 03:50:31 +0300 [thread overview]
Message-ID: <20160816005032.28881-4-ab@fmap.me> (raw)
In-Reply-To: <20160816005032.28881-1-ab@fmap.me>
static-nodes has just used /lib/modules/`uname -r` before with no way to
specify another directory. Instead, make it get the path via kmod, which has a
more sophisticated algorithm for searching the modules directory.
As a side effect, cleanup error messages printing a little.
---
tools/static-nodes.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/tools/static-nodes.c b/tools/static-nodes.c
index 8d2356d..2ed306d 100644
--- a/tools/static-nodes.c
+++ b/tools/static-nodes.c
@@ -29,10 +29,11 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/utsname.h>
#include <shared/util.h>
+#include <libkmod/libkmod.h>
+
#include "kmod.h"
struct static_nodes_format {
@@ -154,8 +155,8 @@ static void help(void)
static int do_static_nodes(int argc, char *argv[])
{
- struct utsname kernel;
char modules[PATH_MAX], buf[4096];
+ struct kmod_ctx *ctx;
const char *output = "/dev/stdout";
FILE *in = NULL, *out = NULL;
const struct static_nodes_format *format = &static_nodes_format_human;
@@ -206,22 +207,25 @@ static int do_static_nodes(int argc, char *argv[])
}
}
- if (uname(&kernel) < 0) {
- fputs("Error: uname failed!\n", stderr);
+ ctx = kmod_new(NULL, NULL);
+ if (ctx == NULL) {
+ fprintf(stderr, "Error: failed to create kmod context\n");
ret = EXIT_FAILURE;
goto finish;
}
-
- snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
+ if (snprintf(modules, sizeof(modules), "%s/modules.devname", kmod_get_dirname(ctx)) < 0) {
+ fprintf(stderr, "Error: path to modules.devname is too long\n");
+ ret = EXIT_FAILURE;
+ goto finish;
+ }
+ kmod_unref(ctx);
in = fopen(modules, "re");
if (in == NULL) {
if (errno == ENOENT) {
- fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
- kernel.release);
+ fprintf(stderr, "Warning: %s not found - ignoring\n", modules);
ret = EXIT_SUCCESS;
} else {
- fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
- kernel.release);
+ fprintf(stderr, "Error: could not open %s - %m\n", modules);
ret = EXIT_FAILURE;
}
goto finish;
--
2.9.2
next prev parent reply other threads:[~2016-08-16 0:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-16 0:50 Improvements in search of kernel modules directory Nikolay Amiantov
2016-08-16 0:50 ` [PATCH 1/4] libkmod: add MODULE_DIR to override " Nikolay Amiantov
2016-08-16 0:50 ` [PATCH 2/4] libkmod: allow hardcoding array of dirname prefixes Nikolay Amiantov
2016-08-16 0:50 ` Nikolay Amiantov [this message]
2016-08-16 0:50 ` [PATCH 4/4] libkmod: add --with-modulesdirs configure option Nikolay Amiantov
2016-11-11 2:13 ` Improvements in search of kernel modules directory Lucas De Marchi
2016-12-05 3:24 ` Lucas De Marchi
2016-12-05 12:35 ` Shea Levy
2016-12-07 7:06 ` Yauheni Kaliuta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160816005032.28881-4-ab@fmap.me \
--to=ab@fmap.me \
--cc=linux-modules@vger.kernel.org \
--cc=shea@shealevy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).