* [PATCH] Add kernel-version dependent configuration directory
@ 2020-02-26 8:04 Anton V. Boyarshinov
2020-02-26 10:07 ` Alexey Gladkov
0 siblings, 1 reply; 3+ messages in thread
From: Anton V. Boyarshinov @ 2020-02-26 8:04 UTC (permalink / raw)
To: linux-modules; +Cc: legion
In some cases it looks reasonable to have kernel-version dependent
modules configuration: blacklists, options and so on. This commit
introduces additional configuration directories:
* /lib/modprobe.d/`uname -r`
* /etc/modprobe.d/`uname -r`
Signed-off-by: Anton V. Boyarshinov <boyarsh@altlinux.org>
---
libkmod/libkmod-config.c | 5 +----
libkmod/libkmod.c | 44 ++++++++++++++++++++++++++++++++++++----
man/modprobe.d.xml | 2 ++
3 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
index aaac0a1..5cc348a 100644
--- a/libkmod/libkmod-config.c
+++ b/libkmod/libkmod-config.c
@@ -711,11 +711,8 @@ static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d,
fstatat(dirfd(d), fn, &st, 0);
- if (S_ISDIR(st.st_mode)) {
- ERR(ctx, "Directories inside directories are not supported: "
- "%s/%s\n", path, fn);
+ if (S_ISDIR(st.st_mode))
return true;
- }
return false;
}
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 69fe431..1ebdeb4 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -225,6 +225,21 @@ static char *get_kernel_release(const char *dirname)
return p;
}
+static char *get_ver_config_path(const char * dir)
+{
+ struct utsname u;
+ char *ver_conf;
+ static const char appendix[] = "modprobe.d";
+
+ if (uname(&u) < 0)
+ return NULL;
+
+ if (asprintf(&ver_conf, "%s/%s/%s", dir, appendix, u.release) < 0)
+ return NULL;
+
+ return ver_conf;
+}
+
/**
* kmod_new:
* @dirname: what to consider as linux module's directory, if NULL
@@ -251,7 +266,7 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
{
const char *env;
struct kmod_ctx *ctx;
- int err;
+ int err, configs_count;
ctx = calloc(1, sizeof(struct kmod_ctx));
if (!ctx)
@@ -269,9 +284,30 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
if (env != NULL)
kmod_set_log_priority(ctx, log_priority(env));
- if (config_paths == NULL)
- config_paths = default_config_paths;
- err = kmod_config_new(ctx, &ctx->config, config_paths);
+ if (config_paths == NULL) {
+ char **tmp_config_paths = malloc(sizeof(default_config_paths) +
+ sizeof(char *) * 2);
+ if(tmp_config_paths == NULL) {
+ ERR(ctx, "could not create versioned config.\n");
+ goto fail;
+ }
+
+ memcpy(tmp_config_paths, default_config_paths, sizeof(default_config_paths));
+
+ configs_count = sizeof(default_config_paths) / sizeof(char *);
+ tmp_config_paths[configs_count-1] = get_ver_config_path("/lib");
+ tmp_config_paths[configs_count] = get_ver_config_path("/etc");
+ tmp_config_paths[configs_count+1] = NULL;
+
+ err = kmod_config_new(ctx, &ctx->config, (const char * const*) tmp_config_paths);
+
+ free(tmp_config_paths[configs_count-1]);
+ free(tmp_config_paths[configs_count]);
+ free(tmp_config_paths);
+ }
+ else
+ err = kmod_config_new(ctx, &ctx->config, config_paths);
+
if (err < 0) {
ERR(ctx, "could not create config\n");
goto fail;
diff --git a/man/modprobe.d.xml b/man/modprobe.d.xml
index 211af84..d1e254a 100644
--- a/man/modprobe.d.xml
+++ b/man/modprobe.d.xml
@@ -41,7 +41,9 @@
<refsynopsisdiv>
<para><filename>/lib/modprobe.d/*.conf</filename></para>
+ <para><filename>/lib/modprobe.d/`uname -r`/*.conf</filename></para>
<para><filename>/etc/modprobe.d/*.conf</filename></para>
+ <para><filename>/etc/modprobe.d/`uname -r`/*.conf</filename></para>
<para><filename>/run/modprobe.d/*.conf</filename></para>
</refsynopsisdiv>
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Add kernel-version dependent configuration directory
2020-02-26 8:04 [PATCH] Add kernel-version dependent configuration directory Anton V. Boyarshinov
@ 2020-02-26 10:07 ` Alexey Gladkov
2020-02-26 10:14 ` Anton V. Boyarshinov
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Gladkov @ 2020-02-26 10:07 UTC (permalink / raw)
To: Anton V. Boyarshinov; +Cc: linux-modules
On Wed, Feb 26, 2020 at 11:04:49AM +0300, Anton V. Boyarshinov wrote:
> In some cases it looks reasonable to have kernel-version dependent
> modules configuration: blacklists, options and so on. This commit
> introduces additional configuration directories:
> * /lib/modprobe.d/`uname -r`
> * /etc/modprobe.d/`uname -r`
>
> Signed-off-by: Anton V. Boyarshinov <boyarsh@altlinux.org>
> ---
> libkmod/libkmod-config.c | 5 +----
> libkmod/libkmod.c | 44 ++++++++++++++++++++++++++++++++++++----
> man/modprobe.d.xml | 2 ++
> 3 files changed, 43 insertions(+), 8 deletions(-)
>
> diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
> index aaac0a1..5cc348a 100644
> --- a/libkmod/libkmod-config.c
> +++ b/libkmod/libkmod-config.c
> @@ -711,11 +711,8 @@ static bool conf_files_filter_out(struct kmod_ctx *ctx, DIR *d,
>
> fstatat(dirfd(d), fn, &st, 0);
>
> - if (S_ISDIR(st.st_mode)) {
> - ERR(ctx, "Directories inside directories are not supported: "
> - "%s/%s\n", path, fn);
> + if (S_ISDIR(st.st_mode))
> return true;
> - }
>
> return false;
> }
> diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
> index 69fe431..1ebdeb4 100644
> --- a/libkmod/libkmod.c
> +++ b/libkmod/libkmod.c
> @@ -225,6 +225,21 @@ static char *get_kernel_release(const char *dirname)
> return p;
> }
>
> +static char *get_ver_config_path(const char * dir)
> +{
> + struct utsname u;
> + char *ver_conf;
> + static const char appendix[] = "modprobe.d";
> +
> + if (uname(&u) < 0)
> + return NULL;
> +
> + if (asprintf(&ver_conf, "%s/%s/%s", dir, appendix, u.release) < 0)
> + return NULL;
> +
> + return ver_conf;
> +}
> +
> /**
> * kmod_new:
> * @dirname: what to consider as linux module's directory, if NULL
> @@ -251,7 +266,7 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
> {
> const char *env;
> struct kmod_ctx *ctx;
> - int err;
> + int err, configs_count;
>
> ctx = calloc(1, sizeof(struct kmod_ctx));
> if (!ctx)
> @@ -269,9 +284,30 @@ KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
> if (env != NULL)
> kmod_set_log_priority(ctx, log_priority(env));
>
> - if (config_paths == NULL)
> - config_paths = default_config_paths;
> - err = kmod_config_new(ctx, &ctx->config, config_paths);
> + if (config_paths == NULL) {
> + char **tmp_config_paths = malloc(sizeof(default_config_paths) +
> + sizeof(char *) * 2);
> + if(tmp_config_paths == NULL) {
> + ERR(ctx, "could not create versioned config.\n");
> + goto fail;
> + }
> +
> + memcpy(tmp_config_paths, default_config_paths, sizeof(default_config_paths));
> +
> + configs_count = sizeof(default_config_paths) / sizeof(char *);
Is it ARRAY_SIZE ?
> + tmp_config_paths[configs_count-1] = get_ver_config_path("/lib");
> + tmp_config_paths[configs_count] = get_ver_config_path("/etc");
Please use SYSCONFDIR. All other parts of the code use it.
> + tmp_config_paths[configs_count+1] = NULL;
> +
> + err = kmod_config_new(ctx, &ctx->config, (const char * const*) tmp_config_paths);
> +
> + free(tmp_config_paths[configs_count-1]);
> + free(tmp_config_paths[configs_count]);
> + free(tmp_config_paths);
> + }
> + else
> + err = kmod_config_new(ctx, &ctx->config, config_paths);
> +
> if (err < 0) {
> ERR(ctx, "could not create config\n");
> goto fail;
> diff --git a/man/modprobe.d.xml b/man/modprobe.d.xml
> index 211af84..d1e254a 100644
> --- a/man/modprobe.d.xml
> +++ b/man/modprobe.d.xml
> @@ -41,7 +41,9 @@
>
> <refsynopsisdiv>
> <para><filename>/lib/modprobe.d/*.conf</filename></para>
> + <para><filename>/lib/modprobe.d/`uname -r`/*.conf</filename></para>
> <para><filename>/etc/modprobe.d/*.conf</filename></para>
> + <para><filename>/etc/modprobe.d/`uname -r`/*.conf</filename></para>
> <para><filename>/run/modprobe.d/*.conf</filename></para>
> </refsynopsisdiv>
>
> --
> 2.21.0
>
>
--
Rgrds, legion
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Add kernel-version dependent configuration directory
2020-02-26 10:07 ` Alexey Gladkov
@ 2020-02-26 10:14 ` Anton V. Boyarshinov
0 siblings, 0 replies; 3+ messages in thread
From: Anton V. Boyarshinov @ 2020-02-26 10:14 UTC (permalink / raw)
To: Alexey Gladkov; +Cc: linux-modules
В Wed, 26 Feb 2020 11:07:56 +0100
Alexey Gladkov <gladkov.alexey@gmail.com> пишет:
> > +
> > + configs_count = sizeof(default_config_paths) / sizeof(char *);
>
> Is it ARRAY_SIZE ?
Yes, will be fixed.
> > + tmp_config_paths[configs_count-1] = get_ver_config_path("/lib");
> > + tmp_config_paths[configs_count] = get_ver_config_path("/etc");
>
> Please use SYSCONFDIR. All other parts of the code use it.
Thank you, will be fixed.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-26 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 8:04 [PATCH] Add kernel-version dependent configuration directory Anton V. Boyarshinov
2020-02-26 10:07 ` Alexey Gladkov
2020-02-26 10:14 ` Anton V. Boyarshinov
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).