summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test-udev.c18
-rw-r--r--udev_rules.c23
-rw-r--r--udev_rules.h1
-rw-r--r--udev_rules_parse.c12
-rw-r--r--udevd.c20
-rw-r--r--udevstart.c18
6 files changed, 37 insertions, 55 deletions
diff --git a/test-udev.c b/test-udev.c
index f114609e5b..0c25778aa6 100644
--- a/test-udev.c
+++ b/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:
diff --git a/udev_rules.c b/udev_rules.c
index 9483c2b8f8..a8fd18cf8a 100644
--- a/udev_rules.c
+++ b/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)
{
diff --git a/udev_rules.h b/udev_rules.h
index 038f6da84d..556f55087d 100644
--- a/udev_rules.h
+++ b/udev_rules.h
@@ -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);
diff --git a/udev_rules_parse.c b/udev_rules_parse.c
index c4fa142b04..638ea159fb 100644
--- a/udev_rules_parse.c
+++ b/udev_rules_parse.c
@@ -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 5ed8e38c98..7dedf078f3 100644
--- 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;
diff --git a/udevstart.c b/udevstart.c
index 1e67a0615a..66b96a2186 100644
--- a/udevstart.c
+++ b/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);