]> err.no Git - systemd/commitdiff
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 f114609e5bca0379eae5eea0cc1540531ab41ac3..0c25778aa68d5ba1c96e3b43e6e765bcb00a6aa0 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 9483c2b8f8fd0bcfd725a10c1b519ce65e5ac407..a8fd18cf8a5e5c6815dba3906f809ea232f0678a 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 038f6da84d6e0ca07c74c4c075db4fec210eb435..556f55087d48c46aa277c8048b1032d07d8782cb 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 c4fa142b04a21c078db43607acf7c178d68472c9..638ea159fbdf71e15f9a65b9cd6efb84a894a39b 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 5ed8e38c98dd3073641ce0c82101e5e69280efd6..7dedf078f3ef91ebea9963830c0845e95e0eedae 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 1e67a0615a9f79a5fd0a4657bc04e0233fce9bb2..66b96a218654edffefb7e15bbdcfd719cfd6363f 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);