mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-12-14 10:37:11 +07:00
add udev_rules_run() to handle RUN list
This commit is contained in:
parent
fb819f5554
commit
274da2b23d
18
test-udev.c
18
test-udev.c
@ -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:
|
||||
|
23
udev_rules.c
23
udev_rules.c
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
20
udevd.c
20
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;
|
||||
|
18
udevstart.c
18
udevstart.c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user