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 80758717a6, 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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2019-01-03 12:31:06 +01:00
parent 3dd84d4615
commit 116b91e8cc
2 changed files with 16 additions and 23 deletions

View File

@ -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.

View File

@ -15,6 +15,7 @@
#include "alloc-util.h"
#include "conf-files.h"
#include "def.h"
#include "device-private.h"
#include "device-util.h"
#include "dirent-util.h"
@ -41,6 +42,7 @@
#include "util.h"
#define PREALLOC_TOKEN 2048
#define RULES_DIRS (const char* const*) CONF_PATHS_STRV("udev/rules.d")
struct uid_gid {
unsigned name_off;
@ -50,13 +52,6 @@ struct uid_gid {
};
};
static const char* const rules_dirs[] = {
"/etc/udev/rules.d",
"/run/udev/rules.d",
UDEVLIBEXECDIR "/rules.d",
NULL
};
struct UdevRules {
usec_t dirs_ts_usec;
ResolveNameTiming resolve_name_timing;
@ -1609,7 +1604,7 @@ int udev_rules_new(UdevRules **ret_rules, ResolveNameTiming resolve_name_timing)
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)
return log_error_errno(r, "Failed to enumerate rules files: %m");
@ -1661,7 +1656,7 @@ bool udev_rules_check_timestamp(UdevRules *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 bool match_key(UdevRules *rules, struct token *token, const char *val) {