diff mbox series

[2/4] libkmod, depmod: Load modprobe.d, depmod.d from $prefix/lib.

Message ID 20230711153126.28876-3-msuchanek@suse.de (mailing list archive)
State New, archived
Headers show
Series kmod /usr support | expand

Commit Message

Michal Suchánek July 11, 2023, 3:31 p.m. UTC
There is an ongoing effort to limit use of files outside of /usr (or
$prefix on general). Currently all modprobe.d paths are hardcoded to
outside of $prefix. Teach kmod to load modprobe.d from $prefix/lib.

On some distributions /usr/lib and /lib are the same directory because
of a compatibility symlink, and it is possible to craft configuration
files with sideeffects that would behave differently when loaded twice.
However, the override semantic ensures that one 'overrides' the other,
and only one configuration file of the same name is loaded from any of
the seach directories.

Cc: Takashi Iwai <tiwai@suse.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 Makefile.am        | 1 +
 libkmod/libkmod.c  | 3 ++-
 man/Makefile.am    | 9 +++++++--
 man/depmod.d.xml   | 1 +
 man/modprobe.d.xml | 1 +
 tools/depmod.c     | 1 +
 6 files changed, 13 insertions(+), 3 deletions(-)

Comments

Jiri Slaby July 12, 2023, 6:47 a.m. UTC | #1
On 11. 07. 23, 17:31, Michal Suchanek wrote:
> There is an ongoing effort to limit use of files outside of /usr (or
> $prefix on general). Currently all modprobe.d paths are hardcoded to
> outside of $prefix. Teach kmod to load modprobe.d from $prefix/lib.
> 
> On some distributions /usr/lib and /lib are the same directory because
> of a compatibility symlink, and it is possible to craft configuration
> files with sideeffects that would behave differently when loaded twice.
> However, the override semantic ensures that one 'overrides' the other,
> and only one configuration file of the same name is loaded from any of
> the seach directories.

search

...
> --- a/man/Makefile.am
> +++ b/man/Makefile.am
> @@ -17,9 +17,14 @@ EXTRA_DIST = $(MAN5:%.5=%.xml) $(MAN8:%.8=%.xml)
>   CLEANFILES = $(dist_man_MANS)
>   
>   %.5 %.8: %.xml
> -	$(AM_V_XSLT)$(XSLT) \
> +	$(AM_V_XSLT)if [ -n '$(prefix)' ] ; then \
> +		sed -e 's|@PREFIX@|$(prefix)|g' $< ; \

Hmm, if prefix is empty, this will remove @PREFIX@. So why you need this 
'if' at all?

> +	else \
> +		sed -e '/@PREFIX@/d' $< ; \
> +	fi | \
Michal Suchánek July 12, 2023, 7:35 a.m. UTC | #2
Hello,

On Wed, Jul 12, 2023 at 08:47:20AM +0200, Jiri Slaby wrote:
> On 11. 07. 23, 17:31, Michal Suchanek wrote:
> > There is an ongoing effort to limit use of files outside of /usr (or
> > $prefix on general). Currently all modprobe.d paths are hardcoded to
> > outside of $prefix. Teach kmod to load modprobe.d from $prefix/lib.
> > 
> > On some distributions /usr/lib and /lib are the same directory because
> > of a compatibility symlink, and it is possible to craft configuration
> > files with sideeffects that would behave differently when loaded twice.
> > However, the override semantic ensures that one 'overrides' the other,
> > and only one configuration file of the same name is loaded from any of
> > the seach directories.
> 
> search
> 
> ...
> > --- a/man/Makefile.am
> > +++ b/man/Makefile.am
> > @@ -17,9 +17,14 @@ EXTRA_DIST = $(MAN5:%.5=%.xml) $(MAN8:%.8=%.xml)
> >   CLEANFILES = $(dist_man_MANS)
> >   %.5 %.8: %.xml
> > -	$(AM_V_XSLT)$(XSLT) \
> > +	$(AM_V_XSLT)if [ -n '$(prefix)' ] ; then \
> > +		sed -e 's|@PREFIX@|$(prefix)|g' $< ; \
> 
> Hmm, if prefix is empty, this will remove @PREFIX@. So why you need this
> 'if' at all?

It removes the whole duplicate line.

Thanks

Michal

> 
> > +	else \
> > +		sed -e '/@PREFIX@/d' $< ; \
> > +	fi | \
> 
> 
> -- 
> js
> suse labs
>
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index 8ba85c91a0f3..7aa5bfa5638d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,7 @@  AM_CPPFLAGS = \
 	-include $(top_builddir)/config.h \
 	-I$(top_srcdir) \
 	-DSYSCONFDIR=\""$(sysconfdir)"\" \
+	-DPREFIX=\""$(prefix)"\" \
 	${zlib_CFLAGS}
 
 AM_CFLAGS = $(OUR_CFLAGS)
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 2670f9a4611a..13c82b069e84 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -65,6 +65,7 @@  static const char *const default_config_paths[] = {
 	SYSCONFDIR "/modprobe.d",
 	"/run/modprobe.d",
 	"/usr/local/lib/modprobe.d",
+	PREFIX "/lib/modprobe.d",
 	"/lib/modprobe.d",
 	NULL
 };
@@ -237,7 +238,7 @@  static char *get_kernel_release(const char *dirname)
  *                to load from user-defined configuration parameters such as
  *                alias, blacklists, commands (install, remove). If NULL
  *                defaults to /etc/modprobe.d, /run/modprobe.d,
- *                /usr/local/lib/modprobe.d and /lib/modprobe.d. Give an empty
+ *                /usr/local/lib/modprobe.d and PREFIX/lib/modprobe.d. Give an empty
  *                vector if configuration should not be read. This array must
  *                be null terminated.
  *
diff --git a/man/Makefile.am b/man/Makefile.am
index 11514d52a190..ad07c30bbd24 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -17,9 +17,14 @@  EXTRA_DIST = $(MAN5:%.5=%.xml) $(MAN8:%.8=%.xml)
 CLEANFILES = $(dist_man_MANS)
 
 %.5 %.8: %.xml
-	$(AM_V_XSLT)$(XSLT) \
+	$(AM_V_XSLT)if [ -n '$(prefix)' ] ; then \
+		sed -e 's|@PREFIX@|$(prefix)|g' $< ; \
+	else \
+		sed -e '/@PREFIX@/d' $< ; \
+	fi | \
+	$(XSLT) \
 		-o $@ \
 		--nonet \
 		--stringparam man.output.quietly 1 \
 		--param funcsynopsis.style "'ansi'" \
-		http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
+		http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl -
diff --git a/man/depmod.d.xml b/man/depmod.d.xml
index 8d3d821cddc8..431ebca6654b 100644
--- a/man/depmod.d.xml
+++ b/man/depmod.d.xml
@@ -40,6 +40,7 @@ 
 
   <refsynopsisdiv>
     <para><filename>/lib/depmod.d/*.conf</filename></para>
+    <para><filename>@PREFIX@/lib/depmod.d/*.conf</filename></para>
     <para><filename>/usr/local/lib/depmod.d/*.conf</filename></para>
     <para><filename>/run/depmod.d/*.conf</filename></para>
     <para><filename>/etc/depmod.d/*.conf</filename></para>
diff --git a/man/modprobe.d.xml b/man/modprobe.d.xml
index 0ab3e9110a7e..e8a91d7668af 100644
--- a/man/modprobe.d.xml
+++ b/man/modprobe.d.xml
@@ -41,6 +41,7 @@ 
 
   <refsynopsisdiv>
     <para><filename>/lib/modprobe.d/*.conf</filename></para>
+    <para><filename>@PREFIX@/lib/modprobe.d/*.conf</filename></para>
     <para><filename>/usr/local/lib/modprobe.d/*.conf</filename></para>
     <para><filename>/run/modprobe.d/*.conf</filename></para>
     <para><filename>/etc/modprobe.d/*.conf</filename></para>
diff --git a/tools/depmod.c b/tools/depmod.c
index 1d1d41db860f..7e9339923809 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -54,6 +54,7 @@  static const char *const default_cfg_paths[] = {
 	SYSCONFDIR "/depmod.d",
 	"/run/depmod.d",
 	"/usr/local/lib/depmod.d",
+	PREFIX "/lib/depmod.d",
 	"/lib/depmod.d",
 	NULL
 };