chiark / gitweb /
add udev_rules_run() to handle RUN list
authorKay Sievers <kay.sievers@vrfy.org>
Sat, 14 Jul 2007 18:44:19 +0000 (20:44 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Sat, 14 Jul 2007 18:44:19 +0000 (20:44 +0200)
test-udev.c
udev_rules.c
udev_rules.h
udev_rules_parse.c
udevd.c
udevstart.c

index f114609..0c25778 100644 (file)
@@ -154,22 +154,8 @@ int main(int argc, char *argv[], char *envp[])
 
        retval = udev_device_event(&rules, udev);
 
-       if (retval == 0 && !udev->ignore_device && udev_run) {
-               struct name_entry *name_loop;
-
-               dbg("executing run list");
-               list_for_each_entry(name_loop, &udev->run_list, node) {
-                       if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
-                               pass_env_to_socket(&name_loop->name[strlen("socket:")], devpath, action);
-                       else {
-                               char program[PATH_SIZE];
-
-                               strlcpy(program, name_loop->name, sizeof(program));
-                               udev_rules_apply_format(udev, program, sizeof(program));
-                               run_program(program, udev->dev->subsystem, NULL, 0, NULL);
-                       }
-               }
-       }
+       if (retval == 0 && !udev->ignore_device && udev_run)
+               udev_rules_run(udev);
 
        udev_device_cleanup(udev);
 fail:
index 9483c2b..a8fd18c 100644 (file)
@@ -238,6 +238,29 @@ static int import_parent_into_env(struct udevice *udev, const char *filter)
        return rc;
 }
 
+int udev_rules_run(struct udevice *udev)
+{
+       struct name_entry *name_loop;
+       int retval = 0;
+
+       dbg("executing run list");
+       list_for_each_entry(name_loop, &udev->run_list, node) {
+               if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0) {
+                       pass_env_to_socket(&name_loop->name[strlen("socket:")], udev->dev->devpath, udev->action);
+               } else {
+                       char program[PATH_SIZE];
+
+                       strlcpy(program, name_loop->name, sizeof(program));
+                       udev_rules_apply_format(udev, program, sizeof(program));
+                       if (run_program(program, udev->dev->subsystem, NULL, 0, NULL) != 0)
+                               if (!name_loop->ignore_error)
+                                       retval = -1;
+               }
+       }
+
+       return retval;
+}
+
 #define WAIT_LOOP_PER_SECOND           50
 static int wait_for_sysfs(struct udevice *udev, const char *file, int timeout)
 {
index 038f6da..556f550 100644 (file)
@@ -123,6 +123,7 @@ extern struct udev_rule *udev_rules_iter_label(struct udev_rules *rules, const c
 
 extern int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev);
 extern int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev);
+extern int udev_rules_run(struct udevice *udev);
 
 extern void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize);
 
index c4fa142..638ea15 100644 (file)
@@ -425,13 +425,13 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
 
                if (strncasecmp(key, "IMPORT", sizeof("IMPORT")-1) == 0) {
                        attr = get_key_attribute(key + sizeof("IMPORT")-1);
-                       if (attr && strstr(attr, "program")) {
+                       if (attr != NULL && strstr(attr, "program")) {
                                dbg("IMPORT will be executed");
                                rule->import_type  = IMPORT_PROGRAM;
-                       } else if (attr && strstr(attr, "file")) {
+                       } else if (attr != NULL && strstr(attr, "file")) {
                                dbg("IMPORT will be included as file");
                                rule->import_type  = IMPORT_FILE;
-                       } else if (attr && strstr(attr, "parent")) {
+                       } else if (attr != NULL && strstr(attr, "parent")) {
                                dbg("IMPORT will include the parent values");
                                rule->import_type = IMPORT_PARENT;
                        } else {
@@ -479,8 +479,10 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
 
                if (strncasecmp(key, "RUN", sizeof("RUN")-1) == 0) {
                        attr = get_key_attribute(key + sizeof("RUN")-1);
-                       if (attr && strstr(attr, "ignore_error"))
-                               rule->run_ignore_error = 1;
+                       if (attr != NULL) {
+                               if (strstr(attr, "ignore_error"))
+                                       rule->run_ignore_error = 1;
+                       }
                        add_rule_key(rule, &rule->run, operation, value);
                        valid = 1;
                        continue;
diff --git a/udevd.c b/udevd.c
index 5ed8e38..7dedf07 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -135,24 +135,8 @@ static int udev_event_process(struct udevd_uevent_msg *msg)
        retval = udev_device_event(&rules, udev);
 
        /* run programs collected by RUN-key*/
-       if (retval == 0 && !udev->ignore_device && udev_run) {
-               struct name_entry *name_loop;
-
-               dbg("executing run list");
-               list_for_each_entry(name_loop, &udev->run_list, node) {
-                       if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
-                               pass_env_to_socket(&name_loop->name[strlen("socket:")], udev->dev->devpath, udev->action);
-                       else {
-                               char program[PATH_SIZE];
-
-                               strlcpy(program, name_loop->name, sizeof(program));
-                               udev_rules_apply_format(udev, program, sizeof(program));
-                               if (run_program(program, udev->dev->subsystem, NULL, 0, NULL) != 0)
-                                       if (!name_loop->ignore_error)
-                                               retval = -1;
-                       }
-               }
-       }
+       if (retval == 0 && !udev->ignore_device && udev_run)
+               retval = udev_rules_run(udev);
 
        udev_device_cleanup(udev);
        return retval;
index 1e67a06..66b96a2 100644 (file)
@@ -148,22 +148,8 @@ static int add_device(const char *devpath)
        else
                info("device node creation supressed");
 
-       if (retval == 0 && udev_run) {
-               struct name_entry *name_loop;
-
-               dbg("executing run list");
-               list_for_each_entry(name_loop, &udev->run_list, node) {
-                       if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0)
-                               pass_env_to_socket(&name_loop->name[strlen("socket:")], udev->dev->devpath, "add");
-                       else {
-                               char program[PATH_SIZE];
-
-                               strlcpy(program, name_loop->name, sizeof(program));
-                               udev_rules_apply_format(udev, program, sizeof(program));
-                               run_program(program, udev->dev->subsystem, NULL, 0, NULL);
-                       }
-               }
-       }
+       if (retval == 0 && udev_run)
+               udev_rules_run(udev);
 
 exit:
        udev_device_cleanup(udev);