$(E) " GENHDR " $@
$(Q) echo "/* Generated by make. */" > $@
$(Q) echo \#define UDEV_VERSION \"$(VERSION)\" >> $@
- $(Q) echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
$(Q) echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
- $(Q) echo \#define UDEV_RULES_DIR \"$(configdir)/rules.d\" >> $@
# man pages
%.8 %.7: %.xml
.PHONY: clean
install-config:
+ $(INSTALL) -d $(DESTDIR)$(libudevdir)/rules.d
$(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
@ if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
- $(INSTALL_DATA) etc/udev/udev.conf $(DESTDIR)$(configdir); \
+ $(INSTALL_DATA) udev.conf $(DESTDIR)$(configdir); \
fi
- @ for i in etc/udev/rules.d/*.rules; do \
- if [ ! -r $(DESTDIR)$(configdir)/rules.d/$$(basename $$i) ]; then \
- $(INSTALL_DATA) $$i $(DESTDIR)$(configdir)/rules.d; \
- fi \
- done
+ cp rules/rules.d/* $(DESTDIR)$(libudevdir)/rules.d
@ extras="$(EXTRAS)"; for target in $$extras; do \
$(MAKE) -C $$target $@ || exit 1; \
done;
install-bin: all
$(INSTALL) -d $(DESTDIR)$(libudevdir)
$(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(libudevdir)/$(PROG)
- $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
- $(INSTALL_DATA) 60-cdrom_id.rules $(DESTDIR)$(configdir)/rules.d/60-cdrom_id.rules
+ $(INSTALL) -d $(DESTDIR)$(libudevdir)/rules.d
+ $(INSTALL_DATA) 60-cdrom_id.rules $(DESTDIR)$(libudevdir)/rules.d/60-cdrom_id.rules
.PHONY: install-bin
uninstall-bin:
- rm $(DESTDIR)$(libudevdir)/$(PROG)
- - rm $(DESTDIR)$(configdir)/rules.d/60-cdrom_id.rules
+ - rm $(DESTDIR)$(libudevdir)/rules.d/60-cdrom_id.rules
.PHONY: uninstall-bin
install-man:
install-bin: all
$(INSTALL) -d $(DESTDIR)$(libudevdir)
$(INSTALL_PROGRAM) $(PROG) $(DESTDIR)$(libudevdir)/$(PROG)
- $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d/
- $(INSTALL_DATA) 61-persistent-storage-edd.rules $(DESTDIR)$(configdir)/rules.d/61-persistent-storage-edd.rules
+ $(INSTALL) -d $(DESTDIR)$(libudevdir)/rules.d/
+ $(INSTALL_DATA) 61-persistent-storage-edd.rules $(DESTDIR)$(libudevdir)/rules.d/61-persistent-storage-edd.rules
.PHONY: install-bin
uninstall-bin:
- rm $(DESTDIR)$(libudevdir)/$(PROG)
- - rm $(DESTDIR)$(configdir)/rules.d/61-persistent-storage-edd.rules
+ - rm $(DESTDIR)$(libudevdir)/rules.d/61-persistent-storage-edd.rules
.PHONY: uninstall-bin
install-man:
install-bin: all
$(INSTALL_PROGRAM) -D $(PROG) $(DESTDIR)$(libudevdir)/$(PROG)
- $(INSTALL_DATA) 79-fstab_import.rules $(DESTDIR)$(configdir)/rules.d/79-fstab_import.rules
+ $(INSTALL_DATA) 79-fstab_import.rules $(DESTDIR)$(libudevdir)/rules.d/79-fstab_import.rules
.PHONY: install-bin
uninstall-bin:
- rm $(DESTDIR)$(libudevdir)/$(PROG)
- - rm $(DESTDIR)$(configdir)/rules.d/79-fstab_import.rules
+ - rm $(DESTDIR)$(libudevdir)/rules.d/79-fstab_import.rules
.PHONY: uninstall-bin
install-man:
$(INSTALL_DATA) rule_generator.functions $(DESTDIR)$(libudevdir)/rule_generator.functions
$(INSTALL_SCRIPT) write_cd_rules $(DESTDIR)$(libudevdir)/write_cd_rules
$(INSTALL_SCRIPT) write_net_rules $(DESTDIR)$(libudevdir)/write_net_rules
- $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
+ $(INSTALL) -d $(DESTDIR)$(libudevdir)/rules.d
$(INSTALL_DATA) 75-cd-aliases-generator.rules \
- $(DESTDIR)$(configdir)/rules.d/75-cd-aliases-generator.rules
+ $(DESTDIR)$(libudevdir)/rules.d/75-cd-aliases-generator.rules
$(INSTALL_DATA) 75-persistent-net-generator.rules \
- $(DESTDIR)$(configdir)/rules.d/75-persistent-net-generator.rules
+ $(DESTDIR)$(libudevdir)/rules.d/75-persistent-net-generator.rules
.PHONY: install-bin
uninstall-bin:
my $PWD = $ENV{PWD};
my $sysfs = "sys/";
my $udev_bin = "../test-udev";
-my $udev_root = "udev-root/"; # !!! directory will be removed !!!
+my $udev_root = "udev-root/";
my $udev_conf = "udev-test.conf";
my $udev_rules = "udev-test.rules";
}
# prepare
-make_udev_root ();
+make_udev_root();
# create config file
open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
print CONF "udev_root=\"$udev_root\"\n";
-print CONF "udev_rules=\"$udev_rules\"\n";
+print CONF "udev_rules=\"$PWD\"\n";
print CONF "udev_log=\"info\"\n";
close CONF;
If udev receives a device event, it matches its configured rules against the available device attributes provided in sysfs to identify the device\. Rules that match may provide additional device information or specify a device node name and multiple symlink names and instruct udev to run additional programs as part of the device event handling\.
.SH "CONFIGURATION"
.PP
-All udev configuration files are placed in
-\fI/etc/udev/*\fR\. Every file consists of a set of lines of text\. All empty lines or lines beginning with \'#\' will be ignored\.
+udev configuration files are placed in
+\fI/etc/udev/\fR
+and
+\fI/lib/udev/\fR\. All empty lines, or lines beginning with \'#\' will be ignored\.
.SS "Configuration file"
.PP
udev expects its main configuration file at
\fI/dev\fR\.
.RE
.PP
-\fBudev_rules\fR
-.RS 4
-The name of the udev rules file or directory to look for files with the suffix
-\fI\.rules\fR\. Multiple rule files are read in lexical order\. The default value is
-\fI/etc/udev/rules\.d\fR\.
-.RE
-.PP
\fBudev_log\fR
.RS 4
The logging priority\. Valid values are the numerical syslog priorities or their textual representations:
.RE
.SS "Rules files"
.PP
-The udev rules are read from the files located in the
-\fI/etc/udev/rules\.d\fR
-directory or at the location specified value in the configuration file\. Every line in the rules file contains at least one key value pair\. There are two kind of keys, match and assignment keys\. If all match keys are matching against its value, the rule gets applied and the assign keys get the specified value assigned\.
+The udev rules are read from the files located in the default rules directory
+\fI/lib/udev/rules\.d/\fR, the custom rules directory
+\fI/etc/udev/rules\.d/\fR
+and the temporary rules directory
+\fI/dev/\.udev/rules\.d/\fR\. All rule files are sorted and processed in lexical order, regardless in which of these directories they live\. Every line in the rules file contains at least one key value pair\. There are two kind of keys, match and assignment keys\. If all match keys are matching against its value, the rule gets applied and the assign keys get the specified value assigned\.
.PP
A matching rule may specify the name of the device node, add a symlink pointing to the node, or run a specified program as part of the event handling\. If no matching rule is found, the default device node name is used\.
.PP
-# udev.conf
-
# The initial syslog(3) priority: "err", "info", "debug" or its
# numerical equivalent. For runtime debugging, the daemons internal
# state can be changed with: "udevadm control --log_priority=<value>".
udev_log="err"
-
#define READ_END 0
#define WRITE_END 1
+#define UDEV_ROOT "/dev"
#define DB_DIR ".udev/db"
#define DB_NAME_INDEX_DIR ".udev/names"
+#define RULES_LIB_DIR "/lib/udev/rules.d"
#define RULES_DYN_DIR ".udev/rules.d"
+#define RULES_ETC_DIR "/etc/udev/rules.d"
struct udev_rules;
</refsect1>
<refsect1><title>CONFIGURATION</title>
- <para>All udev configuration files are placed in <filename>/etc/udev/*</filename>.
- Every file consists of a set of lines of text. All empty lines or lines beginning
- with '#' will be ignored.</para>
+ <para>udev configuration files are placed in <filename>/etc/udev/</filename>
+ and <filename>/lib/udev/</filename>. All empty lines, or lines beginning with
+ '#' will be ignored.</para>
<refsect2><title>Configuration file</title>
<para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
</listitem>
</varlistentry>
- <varlistentry>
- <term><option>udev_rules</option></term>
- <listitem>
- <para>The name of the udev rules file or directory to look for files
- with the suffix <filename>.rules</filename>. Multiple rule files are
- read in lexical order. The default value is
- <filename>/etc/udev/rules.d</filename>.</para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><option>udev_log</option></term>
<listitem>
<refsect2><title>Rules files</title>
<para>The udev rules are read from the files located in the
- <filename>/etc/udev/rules.d</filename> directory or at the location specified
- value in the configuration file. Every line in the rules file contains at least
+ default rules directory <filename>/lib/udev/rules.d/</filename>,
+ the custom rules directory <filename>/etc/udev/rules.d/</filename>
+ and the temporary rules directory <filename>/dev/.udev/rules.d/</filename>.
+ All rule files are sorted and processed in lexical order, regardless
+ in which of these directories they live. Every line in the rules file contains at least
one key value pair. There are two kind of keys, match and assignment keys.
If all match keys are matching against its value, the rule gets applied and the
assign keys get the specified value assigned.</para>
{
const char *env;
- strcpy(udev_root, UDEV_ROOT);
strcpy(udev_config_filename, UDEV_CONFIG_FILE);
- strcpy(udev_rules_dir, UDEV_RULES_DIR);
+ strcpy(udev_root, UDEV_ROOT);
+ udev_rules_dir[0] = '\0';
udev_log_priority = LOG_ERR;
udev_run = 1;
dbg("UDEV_CONFIG_FILE='%s'\n", udev_config_filename);
dbg("udev_root='%s'\n", udev_root);
- dbg("udev_rules='%s'\n", udev_rules_dir);
+ dbg("udev_rules_dir='%s'\n", udev_rules_dir);
dbg("udev_log=%d\n", udev_log_priority);
}
struct stat statbuf;
char filename[PATH_MAX];
LIST_HEAD(name_list);
- LIST_HEAD(dyn_list);
+ LIST_HEAD(sort_list);
struct name_entry *name_loop, *name_tmp;
- struct name_entry *dyn_loop, *dyn_tmp;
+ struct name_entry *sort_loop, *sort_tmp;
int retval = 0;
memset(rules, 0x00, sizeof(struct udev_rules));
rules->resolve_names = resolve_names;
- /* read main config from single file or all files in a directory */
- if (stat(udev_rules_dir, &statbuf) != 0)
- return -1;
- if ((statbuf.st_mode & S_IFMT) != S_IFDIR) {
- dbg("parse single rules file '%s'\n", udev_rules_dir);
- name_list_add(&name_list, udev_rules_dir, 1);
+ if (udev_rules_dir[0] != '\0') {
+ /* custom rules location for testing */
+ add_matching_files(&name_list, udev_rules_dir, RULESFILE_SUFFIX);
} else {
- dbg("parse rules directory '%s'\n", udev_rules_dir);
- retval = add_matching_files(&name_list, udev_rules_dir, RULESFILE_SUFFIX);
- }
-
- /* read dynamic rules directory */
- strlcpy(filename, udev_root, sizeof(filename));
- strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename));
- if (stat(filename, &statbuf) != 0) {
- create_path(filename);
- selinux_setfscreatecon(filename, NULL, S_IFDIR|0755);
- mkdir(filename, 0755);
- selinux_resetfscreatecon();
- }
- add_matching_files(&dyn_list, filename, RULESFILE_SUFFIX);
+ /* read default rules */
+ add_matching_files(&name_list, RULES_LIB_DIR, RULESFILE_SUFFIX);
+
+ /* read user/custom rules */
+ add_matching_files(&sort_list, RULES_ETC_DIR, RULESFILE_SUFFIX);
+
+ /* read dynamic/temporary rules */
+ strlcpy(filename, udev_root, sizeof(filename));
+ strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename));
+ if (stat(filename, &statbuf) != 0) {
+ create_path(filename);
+ selinux_setfscreatecon(filename, NULL, S_IFDIR|0755);
+ mkdir(filename, 0755);
+ selinux_resetfscreatecon();
+ }
+ add_matching_files(&sort_list, filename, RULESFILE_SUFFIX);
- /* sort dynamic rules files by basename into list of files */
- list_for_each_entry_safe(dyn_loop, dyn_tmp, &dyn_list, node) {
- const char *dyn_base = strrchr(dyn_loop->name, '/');
+ /* sort all rules files by basename into list of files */
+ list_for_each_entry_safe(sort_loop, sort_tmp, &sort_list, node) {
+ const char *sort_base = strrchr(sort_loop->name, '/');
- if (dyn_base == NULL)
- continue;
+ if (sort_base == NULL)
+ continue;
- list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) {
- const char *name_base = strrchr(name_loop->name, '/');
+ list_for_each_entry_safe(name_loop, name_tmp, &name_list, node) {
+ const char *name_base = strrchr(name_loop->name, '/');
- if (name_base == NULL)
- continue;
+ if (name_base == NULL)
+ continue;
- if (strcmp(name_base, dyn_base) > 0)
- break;
+ if (strcmp(name_base, sort_base) > 0)
+ break;
+ }
+ list_move_tail(&sort_loop->node, &name_loop->node);
}
- list_move_tail(&dyn_loop->node, &name_loop->node);
}
/* parse list of files */
/* watch rules directory */
inotify_fd = inotify_init();
if (inotify_fd >= 0) {
- char filename[PATH_MAX];
-
- inotify_add_watch(inotify_fd, udev_rules_dir, IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
-
- /* watch dynamic rules directory */
- strlcpy(filename, udev_root, sizeof(filename));
- strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename));
- inotify_add_watch(inotify_fd, filename, IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
+ if (udev_rules_dir[0] != '\0') {
+ inotify_add_watch(inotify_fd, udev_rules_dir,
+ IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
+ } else {
+ char filename[PATH_MAX];
+
+ inotify_add_watch(inotify_fd, RULES_LIB_DIR,
+ IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
+ inotify_add_watch(inotify_fd, RULES_ETC_DIR,
+ IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
+
+ /* watch dynamic rules directory */
+ strlcpy(filename, udev_root, sizeof(filename));
+ strlcat(filename, "/"RULES_DYN_DIR, sizeof(filename));
+ inotify_add_watch(inotify_fd, filename,
+ IN_CREATE | IN_DELETE | IN_MOVE | IN_CLOSE_WRITE);
+ }
} else if (errno == ENOSYS)
err("the kernel does not support inotify, udevd can't monitor rules file changes\n");
else