From: Kay Sievers Date: Fri, 18 Jul 2008 13:56:03 +0000 (+0200) Subject: move default rules from /etc/udev/rules.d/ to /lib/udev/rules.d/ X-Git-Tag: 174~1657 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=282988c4f8a85c28468e6442e86efe51dc71cc93;p=systemd move default rules from /etc/udev/rules.d/ to /lib/udev/rules.d/ None of these rules is supposed to be changed by users, so move them out of /etc. Custom rules, and automatically generated rules stay in /etc. All rules are still processed in lexical order, regardless which directory they live in. --- diff --git a/Makefile b/Makefile index 075389b6..ed2b381d 100644 --- a/Makefile +++ b/Makefile @@ -190,9 +190,7 @@ udev_version.h: $(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 @@ -220,15 +218,12 @@ clean: .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; diff --git a/extras/cdrom_id/Makefile b/extras/cdrom_id/Makefile index caab2bea..ec03d1fc 100644 --- a/extras/cdrom_id/Makefile +++ b/extras/cdrom_id/Makefile @@ -51,13 +51,13 @@ clean: 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: diff --git a/extras/edd_id/Makefile b/extras/edd_id/Makefile index f17a5b8c..0126b859 100644 --- a/extras/edd_id/Makefile +++ b/extras/edd_id/Makefile @@ -51,13 +51,13 @@ clean: 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: diff --git a/extras/fstab_import/Makefile b/extras/fstab_import/Makefile index 23448f32..3f65aa3f 100644 --- a/extras/fstab_import/Makefile +++ b/extras/fstab_import/Makefile @@ -50,12 +50,12 @@ clean: 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: diff --git a/extras/rule_generator/Makefile b/extras/rule_generator/Makefile index d6f1265e..e236ca77 100644 --- a/extras/rule_generator/Makefile +++ b/extras/rule_generator/Makefile @@ -41,11 +41,11 @@ install-bin: all $(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: diff --git a/etc/udev/debian/50-udev.rules b/rules/debian/50-udev.rules similarity index 100% rename from etc/udev/debian/50-udev.rules rename to rules/debian/50-udev.rules diff --git a/etc/udev/debian/60-persistent-input.rules b/rules/debian/60-persistent-input.rules similarity index 100% rename from etc/udev/debian/60-persistent-input.rules rename to rules/debian/60-persistent-input.rules diff --git a/etc/udev/debian/60-persistent-storage-tape.rules b/rules/debian/60-persistent-storage-tape.rules similarity index 100% rename from etc/udev/debian/60-persistent-storage-tape.rules rename to rules/debian/60-persistent-storage-tape.rules diff --git a/etc/udev/debian/60-persistent-storage.rules b/rules/debian/60-persistent-storage.rules similarity index 100% rename from etc/udev/debian/60-persistent-storage.rules rename to rules/debian/60-persistent-storage.rules diff --git a/etc/udev/debian/60-persistent-v4l.rules b/rules/debian/60-persistent-v4l.rules similarity index 100% rename from etc/udev/debian/60-persistent-v4l.rules rename to rules/debian/60-persistent-v4l.rules diff --git a/etc/udev/debian/75-cd-aliases-generator.rules b/rules/debian/75-cd-aliases-generator.rules similarity index 100% rename from etc/udev/debian/75-cd-aliases-generator.rules rename to rules/debian/75-cd-aliases-generator.rules diff --git a/etc/udev/debian/75-persistent-net-generator.rules b/rules/debian/75-persistent-net-generator.rules similarity index 100% rename from etc/udev/debian/75-persistent-net-generator.rules rename to rules/debian/75-persistent-net-generator.rules diff --git a/etc/udev/debian/80-drivers.rules b/rules/debian/80-drivers.rules similarity index 100% rename from etc/udev/debian/80-drivers.rules rename to rules/debian/80-drivers.rules diff --git a/etc/udev/debian/91-permissions.rules b/rules/debian/91-permissions.rules similarity index 100% rename from etc/udev/debian/91-permissions.rules rename to rules/debian/91-permissions.rules diff --git a/etc/udev/debian/95-late.rules b/rules/debian/95-late.rules similarity index 100% rename from etc/udev/debian/95-late.rules rename to rules/debian/95-late.rules diff --git a/etc/udev/frugalware/50-udev-default.rules b/rules/frugalware/50-udev-default.rules similarity index 100% rename from etc/udev/frugalware/50-udev-default.rules rename to rules/frugalware/50-udev-default.rules diff --git a/etc/udev/frugalware/64-device-mapper.rules b/rules/frugalware/64-device-mapper.rules similarity index 100% rename from etc/udev/frugalware/64-device-mapper.rules rename to rules/frugalware/64-device-mapper.rules diff --git a/etc/udev/gentoo/30-kernel-compat.rules b/rules/gentoo/30-kernel-compat.rules similarity index 100% rename from etc/udev/gentoo/30-kernel-compat.rules rename to rules/gentoo/30-kernel-compat.rules diff --git a/etc/udev/gentoo/40-gentoo.rules b/rules/gentoo/40-gentoo.rules similarity index 100% rename from etc/udev/gentoo/40-gentoo.rules rename to rules/gentoo/40-gentoo.rules diff --git a/etc/udev/gentoo/40-video.rules b/rules/gentoo/40-video.rules similarity index 100% rename from etc/udev/gentoo/40-video.rules rename to rules/gentoo/40-video.rules diff --git a/etc/udev/gentoo/65-permissions.rules b/rules/gentoo/65-permissions.rules similarity index 100% rename from etc/udev/gentoo/65-permissions.rules rename to rules/gentoo/65-permissions.rules diff --git a/etc/udev/gentoo/90-network.rules b/rules/gentoo/90-network.rules similarity index 100% rename from etc/udev/gentoo/90-network.rules rename to rules/gentoo/90-network.rules diff --git a/etc/udev/packages/40-alsa.rules b/rules/packages/40-alsa.rules similarity index 100% rename from etc/udev/packages/40-alsa.rules rename to rules/packages/40-alsa.rules diff --git a/etc/udev/packages/40-ia64.rules b/rules/packages/40-ia64.rules similarity index 100% rename from etc/udev/packages/40-ia64.rules rename to rules/packages/40-ia64.rules diff --git a/etc/udev/packages/40-pilot-links.rules b/rules/packages/40-pilot-links.rules similarity index 100% rename from etc/udev/packages/40-pilot-links.rules rename to rules/packages/40-pilot-links.rules diff --git a/etc/udev/packages/40-ppc.rules b/rules/packages/40-ppc.rules similarity index 100% rename from etc/udev/packages/40-ppc.rules rename to rules/packages/40-ppc.rules diff --git a/etc/udev/packages/40-s390.rules b/rules/packages/40-s390.rules similarity index 100% rename from etc/udev/packages/40-s390.rules rename to rules/packages/40-s390.rules diff --git a/etc/udev/packages/40-zaptel.rules b/rules/packages/40-zaptel.rules similarity index 100% rename from etc/udev/packages/40-zaptel.rules rename to rules/packages/40-zaptel.rules diff --git a/etc/udev/packages/64-device-mapper.rules b/rules/packages/64-device-mapper.rules similarity index 100% rename from etc/udev/packages/64-device-mapper.rules rename to rules/packages/64-device-mapper.rules diff --git a/etc/udev/packages/64-md-raid.rules b/rules/packages/64-md-raid.rules similarity index 100% rename from etc/udev/packages/64-md-raid.rules rename to rules/packages/64-md-raid.rules diff --git a/etc/udev/redhat/40-redhat.rules b/rules/redhat/40-redhat.rules similarity index 100% rename from etc/udev/redhat/40-redhat.rules rename to rules/redhat/40-redhat.rules diff --git a/etc/udev/redhat/95-pam-console.rules b/rules/redhat/95-pam-console.rules similarity index 100% rename from etc/udev/redhat/95-pam-console.rules rename to rules/redhat/95-pam-console.rules diff --git a/etc/udev/rules.d/50-udev-default.rules b/rules/rules.d/50-udev-default.rules similarity index 100% rename from etc/udev/rules.d/50-udev-default.rules rename to rules/rules.d/50-udev-default.rules diff --git a/etc/udev/rules.d/60-persistent-input.rules b/rules/rules.d/60-persistent-input.rules similarity index 100% rename from etc/udev/rules.d/60-persistent-input.rules rename to rules/rules.d/60-persistent-input.rules diff --git a/etc/udev/rules.d/60-persistent-storage-tape.rules b/rules/rules.d/60-persistent-storage-tape.rules similarity index 100% rename from etc/udev/rules.d/60-persistent-storage-tape.rules rename to rules/rules.d/60-persistent-storage-tape.rules diff --git a/etc/udev/rules.d/60-persistent-storage.rules b/rules/rules.d/60-persistent-storage.rules similarity index 100% rename from etc/udev/rules.d/60-persistent-storage.rules rename to rules/rules.d/60-persistent-storage.rules diff --git a/etc/udev/rules.d/60-persistent-v4l.rules b/rules/rules.d/60-persistent-v4l.rules similarity index 100% rename from etc/udev/rules.d/60-persistent-v4l.rules rename to rules/rules.d/60-persistent-v4l.rules diff --git a/etc/udev/rules.d/80-drivers.rules b/rules/rules.d/80-drivers.rules similarity index 100% rename from etc/udev/rules.d/80-drivers.rules rename to rules/rules.d/80-drivers.rules diff --git a/etc/udev/rules.d/95-udev-late.rules b/rules/rules.d/95-udev-late.rules similarity index 100% rename from etc/udev/rules.d/95-udev-late.rules rename to rules/rules.d/95-udev-late.rules diff --git a/etc/udev/slackware/udev.rules b/rules/slackware/udev.rules similarity index 100% rename from etc/udev/slackware/udev.rules rename to rules/slackware/udev.rules diff --git a/etc/udev/suse/40-suse.rules b/rules/suse/40-suse.rules similarity index 100% rename from etc/udev/suse/40-suse.rules rename to rules/suse/40-suse.rules diff --git a/etc/udev/suse/64-device-mapper.rules b/rules/suse/64-device-mapper.rules similarity index 100% rename from etc/udev/suse/64-device-mapper.rules rename to rules/suse/64-device-mapper.rules diff --git a/test/udev-test.pl b/test/udev-test.pl index 72b4aef6..f7f68a14 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -23,7 +23,7 @@ use strict; 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"; @@ -1847,12 +1847,12 @@ if (!($<==0)) { } # 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; diff --git a/udev.7 b/udev.7 index 4bf625df..c4ca2860 100644 --- a/udev.7 +++ b/udev.7 @@ -25,8 +25,10 @@ and receives uevents directly from the kernel if a device is added or removed fr 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 @@ -38,13 +40,6 @@ Specifies where to place the device nodes in the filesystem\. The default value \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: @@ -55,9 +50,11 @@ and .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 diff --git a/etc/udev/udev.conf b/udev.conf similarity index 93% rename from etc/udev/udev.conf rename to udev.conf index e6ef0814..998b4a7d 100644 --- a/etc/udev/udev.conf +++ b/udev.conf @@ -1,7 +1,4 @@ -# 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=". udev_log="err" - diff --git a/udev.h b/udev.h index e1b7ac0d..5ecef4ab 100644 --- a/udev.h +++ b/udev.h @@ -47,9 +47,12 @@ #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; diff --git a/udev.xml b/udev.xml index e1986799..c740c0d8 100644 --- a/udev.xml +++ b/udev.xml @@ -40,9 +40,9 @@ CONFIGURATION - All udev configuration files are placed in /etc/udev/*. - 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 /etc/udev/ + and /lib/udev/. All empty lines, or lines beginning with + '#' will be ignored. Configuration file udev expects its main configuration file at /etc/udev/udev.conf. @@ -57,16 +57,6 @@ - - - - The name of the udev rules file or directory to look for files - with the suffix .rules. Multiple rule files are - read in lexical order. The default value is - /etc/udev/rules.d. - - - @@ -80,8 +70,11 @@ Rules files The udev rules are read from the files located in the - /etc/udev/rules.d directory or at the location specified - value in the configuration file. Every line in the rules file contains at least + default rules directory /lib/udev/rules.d/, + the custom rules directory /etc/udev/rules.d/ + and the temporary rules directory /dev/.udev/rules.d/. + 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. diff --git a/udev_config.c b/udev_config.c index 42190945..55f0361d 100644 --- a/udev_config.c +++ b/udev_config.c @@ -164,9 +164,9 @@ void udev_config_init(void) { 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; @@ -195,6 +195,6 @@ void udev_config_init(void) 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); } diff --git a/udev_rules_parse.c b/udev_rules_parse.c index bdaf55bd..999af3b8 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -727,53 +727,53 @@ int udev_rules_init(struct udev_rules *rules, int resolve_names) 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 */ diff --git a/udevd.c b/udevd.c index d6977e96..0827a5ce 100644 --- a/udevd.c +++ b/udevd.c @@ -1142,14 +1142,23 @@ int main(int argc, char *argv[], char *envp[]) /* 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