1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00

substitute format chars in RUN after rule matching

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.
This commit is contained in:
Andrey Borzenkov 2006-01-24 20:10:48 +01:00 committed by Kay Sievers
parent 7d1e179f86
commit f5f0c34f6d
5 changed files with 23 additions and 9 deletions

9
udev.c
View File

@ -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));
}
}
}

View 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);
}

View 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);

View File

@ -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;
}
}
}

View 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: