From: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Date: Thu, 3 Jan 2019 12:31:06 +0100
Subject: [PATCH] udev: use the usual set of load paths for udev rules

This adds /usr/local/lib/udev/rules.d to the search path on non-split-usr systems.
On split-usr systems, the paths with /usr/-prefixes are added too.
In the past, on split-usr systems, it made sense to only load rules from
/lib/udev/rules.d, because /usr could be mounted late. But we don't support running
without /usr since 80758717a63, so in practice it doesn't matter whether the
rules files are in /lib/udev/rules.d or /usr/lib/udev/rules.d. Distributions
that maintain the illusion of functional split-usr are welcome to simply not put any
files in /usr/lib/udev/rules.d/.

In practice this doesn't change much, but it makes udev more consistent with the
rest of the systemd suite.
---
 man/udev.xml          | 26 ++++++++++++--------------
 src/udev/udev-rules.c | 13 ++++---------
 2 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/man/udev.xml b/man/udev.xml
index 15e6d8e..955aff8 100644
--- a/man/udev.xml
+++ b/man/udev.xml
@@ -45,20 +45,18 @@
   </refsect1>
 
   <refsect1><title>Rules Files</title>
-      <para>The udev rules are read from the files located in the
-      system rules directory <filename>/usr/lib/udev/rules.d</filename>,
-      the volatile runtime directory <filename>/run/udev/rules.d</filename>
-      and the local administration directory <filename>/etc/udev/rules.d</filename>.
-      All rules files are collectively sorted and processed in lexical order,
-      regardless of the directories in which they live. However, files with
-      identical filenames replace each other. Files in <filename>/etc</filename>
-      have the highest priority, files in <filename>/run</filename> take precedence
-      over files with the same name in <filename>/usr/lib</filename>. This can be
-      used to override a system-supplied rules file with a local file if needed;
-      a symlink in <filename>/etc</filename> with the same name as a rules file in
-      <filename>/usr/lib</filename>, pointing to <filename>/dev/null</filename>,
-      disables the rules file entirely. Rule files must have the extension
-      <filename>.rules</filename>; other extensions are ignored.</para>
+      <para>The udev rules are read from the files located in the system rules directories
+      <filename>/usr/lib/udev/rules.d</filename> and <filename>/usr/local/lib/udev/rules.d</filename>, the
+      volatile runtime directory <filename>/run/udev/rules.d</filename> and the local administration
+      directory <filename>/etc/udev/rules.d</filename>.  All rules files are collectively sorted and
+      processed in lexical order, regardless of the directories in which they live. However, files with
+      identical filenames replace each other. Files in <filename>/etc</filename> have the highest priority,
+      files in <filename>/run</filename> take precedence over files with the same name under
+      <filename>/usr</filename>. This can be used to override a system-supplied rules file with a local
+      file if needed; a symlink in <filename>/etc</filename> with the same name as a rules file in
+      <filename>/usr/lib</filename>, pointing to <filename>/dev/null</filename>, disables the rules file
+      entirely. Rule files must have the extension <filename>.rules</filename>; other extensions are
+      ignored.</para>
 
       <para>Every line in the rules file contains at least one key-value pair.
       Except for empty lines or lines beginning with <literal>#</literal>, which are ignored.
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index f029395..cd8f4ef 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -18,6 +18,7 @@
 
 #include "alloc-util.h"
 #include "conf-files.h"
+#include "def.h"
 #include "dirent-util.h"
 #include "escape.h"
 #include "fd-util.h"
@@ -36,6 +37,7 @@
 #include "util.h"
 
 #define PREALLOC_TOKEN          2048
+#define RULES_DIRS (const char* const*) CONF_PATHS_STRV("udev/rules.d")
 
 struct uid_gid {
         unsigned int name_off;
@@ -45,13 +47,6 @@ struct uid_gid {
         };
 };
 
-static const char* const rules_dirs[] = {
-        "/etc/udev/rules.d",
-        "/run/udev/rules.d",
-        UDEVLIBEXECDIR "/rules.d",
-        NULL
-};
-
 struct udev_rules {
         struct udev *udev;
         usec_t dirs_ts_usec;
@@ -1542,7 +1537,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
 
         udev_rules_check_timestamp(rules);
 
-        r = conf_files_list_strv(&files, ".rules", NULL, 0, rules_dirs);
+        r = conf_files_list_strv(&files, ".rules", NULL, 0, RULES_DIRS);
         if (r < 0) {
                 log_error_errno(r, "failed to enumerate rules files: %m");
                 return udev_rules_unref(rules);
@@ -1598,7 +1593,7 @@ bool udev_rules_check_timestamp(struct udev_rules *rules) {
         if (!rules)
                 return false;
 
-        return paths_check_timestamp(rules_dirs, &rules->dirs_ts_usec, true);
+        return paths_check_timestamp(RULES_DIRS, &rules->dirs_ts_usec, true);
 }
 
 static int match_key(struct udev_rules *rules, struct token *token, const char *val) {
