chiark / gitweb /
substitute format chars in RUN after rule matching
authorAndrey Borzenkov <arvidjaar@mail.ru>
Tue, 24 Jan 2006 19:10:48 +0000 (20:10 +0100)
committerKay Sievers <kay.sievers@suse.de>
Tue, 24 Jan 2006 19:10:48 +0000 (20:10 +0100)
Apply substitutions before running a program, not while the rule
is parsed. It allows to use environment variables set during rule
processing as command arguments.

udev.c
udev_rules.c
udev_rules.h
udevd.c
udevstart.c

diff --git a/udev.c b/udev.c
index 4762ab1..f808abf 100644 (file)
--- a/udev.c
+++ b/udev.c
@@ -161,8 +161,13 @@ int main(int argc, char *argv[], char *envp[])
                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
-                               run_program(name_loop->name, udev->dev->subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+                       else {
+                               char program[PATH_SIZE];
+
+                               strlcpy(program, name_loop->name, sizeof(program));
+                               apply_format(udev, program, sizeof(program));
+                               run_program(program, udev->dev->subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+                       }
                }
        }
 
index e9d8d75..fbcbbe0 100644 (file)
@@ -362,7 +362,7 @@ static int wait_for_sysfs(struct udevice *udev, const char *file, int timeout)
        return -1;
 }
 
-static void apply_format(struct udevice *udev, char *string, size_t maxsize)
+void apply_format(struct udevice *udev, char *string, size_t maxsize)
 {
        char temp[PATH_SIZE];
        char temp2[PATH_SIZE];
@@ -1017,7 +1017,6 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udev)
                                        name_list_cleanup(&udev->run_list);
                                }
                                strlcpy(program, key_val(rule, &rule->run), sizeof(program));
-                               apply_format(udev, program, sizeof(program));
                                dbg("add run '%s'", program);
                                name_list_add(&udev->run_list, program, 0);
                        }
index 125babf..b183d9b 100644 (file)
@@ -105,7 +105,7 @@ struct udev_rules {
 extern int udev_rules_init(struct udev_rules *rules, int resolve_names);
 extern void udev_rules_cleanup(struct udev_rules *rules);
 
-extern void udev_apply_format(struct udevice *udev, char *string, size_t maxsize);
+extern void apply_format(struct udevice *udev, char *string, size_t maxsize);
 
 extern void udev_rules_iter_init(struct udev_rules *rules);
 extern struct udev_rule *udev_rules_iter_next(struct udev_rules *rules);
diff --git a/udevd.c b/udevd.c
index ffa81bb..8a352e1 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -123,10 +123,15 @@ static int udev_event_process(struct uevent_msg *msg)
                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:")], msg->devpath, msg->action);
-                       else
-                               if (run_program(name_loop->name, udev->dev->subsystem, NULL, 0, NULL,
+                       else {
+                               char program[PATH_SIZE];
+
+                               strlcpy(program, name_loop->name, sizeof(program));
+                               apply_format(udev, program, sizeof(program));
+                               if (run_program(program, udev->dev->subsystem, NULL, 0, NULL,
                                                (udev_log_priority >= LOG_INFO)))
                                        retval = -1;
+                       }
                }
        }
 
index 8c414f1..11bdf79 100644 (file)
@@ -160,8 +160,13 @@ run:
                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
-                               run_program(name_loop->name, udev->dev->subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+                       else {
+                               char program[PATH_SIZE];
+
+                               strlcpy(program, name_loop->name, sizeof(program));
+                               apply_format(udev, program, sizeof(program));
+                               run_program(program, udev->dev->subsystem, NULL, 0, NULL, (udev_log_priority >= LOG_INFO));
+                       }
                }
        }
 exit: