chiark / gitweb /
udev: static_node - do not exit rule after first static_node item
[elogind.git] / src / udev / udev-rules.c
index bbf547222c2f212c40db6f15276be6abd0016893..855a4e4060f4d8ff24889253be341e2e95ac71b2 100644 (file)
@@ -46,9 +46,14 @@ 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;
-        char **dirs;
         usec_t dirs_ts_usec;
         int resolve_names;
 
@@ -895,6 +900,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         case TK_A_GOTO:
         case TK_M_TAG:
         case TK_A_TAG:
+        case TK_A_STATIC_NODE:
                 token->key.value_off = rules_add_string(rule_tmp->rules, value);
                 break;
         case TK_M_IMPORT_BUILTIN:
@@ -938,9 +944,6 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         case TK_A_MODE_ID:
                 token->key.mode = *(mode_t *)data;
                 break;
-        case TK_A_STATIC_NODE:
-                token->key.value_off = rules_add_string(rule_tmp->rules, value);
-                break;
         case TK_M_EVENT_TIMEOUT:
                 token->key.event_timeout = *(int *)data;
                 break;
@@ -961,7 +964,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
                 int has_glob;
 
                 has_split = (strchr(value, '|') != NULL);
-                has_glob = (strchr(value, '*') != NULL || strchr(value, '?') != NULL || strchr(value, '[') != NULL);
+                has_glob = string_is_glob(value);
                 if (has_split && has_glob) {
                         glob = GL_SPLIT_GLOB;
                 } else if (has_split) {
@@ -988,7 +991,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
         }
 
         if (attr != NULL) {
-                /* check if property/attribut name has substitution chars */
+                /* check if property/attribute name has substitution chars */
                 if (attr[0] == '[')
                         token->key.attrsubst = SB_SUBSYS;
                 else if (strchr(attr, '%') != NULL || strchr(attr, '$') != NULL)
@@ -1629,23 +1632,9 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
         if (!rules->strbuf)
                 return udev_rules_unref(rules);
 
-        rules->dirs = strv_new("/etc/udev/rules.d",
-                               "/run/udev/rules.d",
-                               UDEVLIBEXECDIR "/rules.d",
-                               NULL);
-        if (!rules->dirs) {
-                log_error("failed to build config directory array");
-                return udev_rules_unref(rules);
-        }
-        if (!path_strv_canonicalize(rules->dirs)) {
-                log_error("failed to canonicalize config directories");
-                return udev_rules_unref(rules);
-        }
-        strv_uniq(rules->dirs);
-
         udev_rules_check_timestamp(rules);
 
-        r = conf_files_list_strv(&files, ".rules", NULL, (const char **)rules->dirs);
+        r = conf_files_list_strv(&files, ".rules", NULL, rules_dirs);
         if (r < 0) {
                 log_error("failed to enumerate rules files: %s", strerror(-r));
                 return udev_rules_unref(rules);
@@ -1697,7 +1686,6 @@ struct udev_rules *udev_rules_unref(struct udev_rules *rules)
         strbuf_cleanup(rules->strbuf);
         free(rules->uids);
         free(rules->gids);
-        strv_free(rules->dirs);
         free(rules);
         return NULL;
 }
@@ -1707,7 +1695,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)
@@ -2571,15 +2559,11 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
                         /* we assure, that the permissions tokens are sorted before the static token */
                         if (mode == 0 && uid == 0 && gid == 0 && tags == NULL)
                                 goto next;
+
                         strscpyl(device_node, sizeof(device_node), "/dev/", rules_str(rules, cur->key.value_off), NULL);
-                        if (stat(device_node, &stats) != 0)
-                                goto next;
-                        if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
-                                goto next;
 
+                        /* export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
                         if (tags) {
-                                /* Export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
-
                                 STRV_FOREACH(t, tags) {
                                         _cleanup_free_ char *unescaped_filename = NULL;
 
@@ -2604,7 +2588,12 @@ int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
 
                         /* don't touch the permissions if only the tags were set */
                         if (mode == 0 && uid == 0 && gid == 0)
-                                goto next;
+                                break;
+
+                        if (stat(device_node, &stats) != 0)
+                                break;
+                        if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
+                                break;
 
                         if (mode == 0) {
                                 if (gid > 0)