chiark / gitweb /
udev: support ENV{}=="" global property matches
authorKay Sievers <kay@vrfy.org>
Thu, 13 Nov 2014 19:35:06 +0000 (20:35 +0100)
committerKay Sievers <kay@vrfy.org>
Thu, 13 Nov 2014 19:35:06 +0000 (20:35 +0100)
src/test/test-udev.c
src/udev/udev-event.c
src/udev/udev-rules.c
src/udev/udev.h
src/udev/udevadm-test.c
src/udev/udevd.c

index 7c011f8..f2283ec 100644 (file)
@@ -149,8 +149,14 @@ int main(int argc, char *argv[]) {
                 }
         }
 
-        udev_event_execute_rules(event, 3 * USEC_PER_SEC, USEC_PER_SEC, rules, &sigmask_orig);
-        udev_event_execute_run(event, 3 * USEC_PER_SEC, USEC_PER_SEC, NULL);
+        udev_event_execute_rules(event,
+                                 3 * USEC_PER_SEC, USEC_PER_SEC,
+                                 NULL,
+                                 rules,
+                                 &sigmask_orig);
+        udev_event_execute_run(event,
+                               3 * USEC_PER_SEC, USEC_PER_SEC,
+                               NULL);
 out:
         if (event != NULL && event->fd_signal >= 0)
                 close(event->fd_signal);
index 5585b78..34f5348 100644 (file)
@@ -787,9 +787,10 @@ static int rename_netif(struct udev_event *event) {
 }
 
 void udev_event_execute_rules(struct udev_event *event,
-                              usec_t timeout_usec,
-                              usec_t timeout_warn_usec,
-                              struct udev_rules *rules, const sigset_t *sigmask) {
+                              usec_t timeout_usec, usec_t timeout_warn_usec,
+                              struct udev_list *properties_list,
+                              struct udev_rules *rules,
+                              const sigset_t *sigmask) {
         struct udev_device *dev = event->dev;
 
         if (udev_device_get_subsystem(dev) == NULL)
@@ -803,7 +804,10 @@ void udev_event_execute_rules(struct udev_event *event,
                 if (major(udev_device_get_devnum(dev)) != 0)
                         udev_watch_end(event->udev, dev);
 
-                udev_rules_apply_to_event(rules, event, timeout_usec, timeout_warn_usec, sigmask);
+                udev_rules_apply_to_event(rules, event,
+                                          timeout_usec, timeout_warn_usec,
+                                          properties_list,
+                                          sigmask);
 
                 if (major(udev_device_get_devnum(dev)) != 0)
                         udev_node_remove(dev);
@@ -837,7 +841,10 @@ void udev_event_execute_rules(struct udev_event *event,
                         }
                 }
 
-                udev_rules_apply_to_event(rules, event, timeout_usec, timeout_warn_usec, sigmask);
+                udev_rules_apply_to_event(rules, event,
+                                          timeout_usec, timeout_warn_usec,
+                                          properties_list,
+                                          sigmask);
 
                 /* rename a new network interface, if needed */
                 if (udev_device_get_ifindex(dev) > 0 && streq(udev_device_get_action(dev), "add") &&
index c02295f..093d68c 100644 (file)
@@ -1876,6 +1876,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                               struct udev_event *event,
                               usec_t timeout_usec,
                               usec_t timeout_warn_usec,
+                              struct udev_list *properties_list,
                               const sigset_t *sigmask) {
         struct token *cur;
         struct token *rule;
@@ -1941,7 +1942,18 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                         const char *value;
 
                         value = udev_device_get_property_value(event->dev, key_name);
-                        if (value == NULL)
+
+                        /* check global properties */
+                        if (!value && properties_list) {
+                                struct udev_list_entry *list_entry;
+
+                                list_entry = udev_list_get_entry(properties_list);
+                                list_entry = udev_list_entry_get_by_name(list_entry, key_name);
+                                if (list_entry != NULL)
+                                        value = udev_list_entry_get_value(list_entry);
+                        }
+
+                        if (!value)
                                 value = "";
                         if (match_key(rules, cur, value))
                                 goto nomatch;
index 7668a27..dece6ec 100644 (file)
@@ -73,7 +73,9 @@ struct udev_rules;
 struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names);
 struct udev_rules *udev_rules_unref(struct udev_rules *rules);
 bool udev_rules_check_timestamp(struct udev_rules *rules);
-int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec,
+int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event,
+                              usec_t timeout_usec, usec_t timeout_warn_usec,
+                              struct udev_list *properties_list,
                               const sigset_t *sigmask);
 int udev_rules_apply_static_dev_perms(struct udev_rules *rules);
 
@@ -88,8 +90,11 @@ int udev_event_spawn(struct udev_event *event,
                      usec_t timeout_warn_usec,
                      const char *cmd, char **envp, const sigset_t *sigmask,
                      char *result, size_t ressize);
-void udev_event_execute_rules(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec,
-                              struct udev_rules *rules, const sigset_t *sigset);
+void udev_event_execute_rules(struct udev_event *event,
+                              usec_t timeout_usec, usec_t timeout_warn_usec,
+                              struct udev_list *properties_list,
+                              struct udev_rules *rules,
+                              const sigset_t *sigset);
 void udev_event_execute_run(struct udev_event *event, usec_t timeout_usec, usec_t timeout_warn_usec, const sigset_t *sigset);
 int udev_build_argv(struct udev *udev, char *cmd, int *argc, char *argv[]);
 
index 4738b61..d9d61b4 100644 (file)
@@ -136,7 +136,11 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
                 goto out;
         }
 
-        udev_event_execute_rules(event, 60 * USEC_PER_SEC, 20 * USEC_PER_SEC, rules, &sigmask_orig);
+        udev_event_execute_rules(event,
+                                 60 * USEC_PER_SEC, 20 * USEC_PER_SEC,
+                                 NULL,
+                                 rules,
+                                 &sigmask_orig);
 
         udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev))
                 printf("%s=%s\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
index 6335b6c..3c3de76 100644 (file)
@@ -75,8 +75,8 @@ static sigset_t sigmask_orig;
 static UDEV_LIST(event_list);
 static UDEV_LIST(worker_list);
 static char *udev_cgroup;
-static bool udev_exit;
 static struct udev_list properties_list;
+static bool udev_exit;
 
 enum event_state {
         EVENT_UNDEF,
@@ -305,9 +305,15 @@ static void worker_new(struct event *event) {
                         udev_event->rtnl = rtnl;
 
                         /* apply rules, create node, symlinks */
-                        udev_event_execute_rules(udev_event, arg_event_timeout_usec, arg_event_timeout_warn_usec, rules, &sigmask_orig);
-
-                        udev_event_execute_run(udev_event, arg_event_timeout_usec, arg_event_timeout_warn_usec, &sigmask_orig);
+                        udev_event_execute_rules(udev_event,
+                                                 arg_event_timeout_usec, arg_event_timeout_warn_usec,
+                                                 &properties_list,
+                                                 rules,
+                                                 &sigmask_orig);
+
+                        udev_event_execute_run(udev_event,
+                                               arg_event_timeout_usec, arg_event_timeout_warn_usec,
+                                               &sigmask_orig);
 
                         /* in case rtnl was initialized */
                         rtnl = sd_rtnl_ref(udev_event->rtnl);