Merge pull request #30614 from yuwata/udev-event-take-worker
udev: make UdevEvent take UdevWorker object
This commit is contained in:
@@ -141,7 +141,7 @@ static int run(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to open device '%s'", devpath);
|
||||
|
||||
assert_se(event = udev_event_new(dev, 0, NULL, log_get_max_level()));
|
||||
assert_se(event = udev_event_new(dev, NULL));
|
||||
|
||||
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, SIGHUP, SIGCHLD, -1) >= 0);
|
||||
|
||||
@@ -169,8 +169,8 @@ static int run(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
udev_event_execute_rules(event, -1, 3 * USEC_PER_SEC, SIGKILL, NULL, rules);
|
||||
udev_event_execute_run(event, 3 * USEC_PER_SEC, SIGKILL);
|
||||
udev_event_execute_rules(event, rules);
|
||||
udev_event_execute_run(event);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ static void test_event_spawn_core(bool with_pidfd, const char *cmd, char *result
|
||||
assert_se(setenv("SYSTEMD_PIDFD", yes_no(with_pidfd), 1) >= 0);
|
||||
|
||||
assert_se(sd_device_new_from_syspath(&dev, "/sys/class/net/lo") >= 0);
|
||||
assert_se(event = udev_event_new(dev, 0, NULL, LOG_DEBUG));
|
||||
assert_se(udev_event_spawn(event, 5 * USEC_PER_SEC, SIGKILL, false, cmd, result_buf, buf_size, NULL) == 0);
|
||||
assert_se(event = udev_event_new(dev, NULL));
|
||||
assert_se(udev_event_spawn(event, false, cmd, result_buf, buf_size, NULL) == 0);
|
||||
|
||||
assert_se(unsetenv("SYSTEMD_PIDFD") >= 0);
|
||||
}
|
||||
|
||||
+9
-32
@@ -14,10 +14,10 @@
|
||||
#include "udev-node.h"
|
||||
#include "udev-trace.h"
|
||||
#include "udev-util.h"
|
||||
#include "udev-watch.h"
|
||||
#include "user-util.h"
|
||||
|
||||
UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rtnl, int log_level) {
|
||||
UdevEvent *udev_event_new(sd_device *dev, UdevWorker *worker) {
|
||||
int log_level = worker ? worker->log_level : log_get_max_level();
|
||||
UdevEvent *event;
|
||||
|
||||
assert(dev);
|
||||
@@ -27,10 +27,10 @@ UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rt
|
||||
return NULL;
|
||||
|
||||
*event = (UdevEvent) {
|
||||
.worker = worker,
|
||||
.rtnl = worker ? sd_netlink_ref(worker->rtnl) : NULL,
|
||||
.dev = sd_device_ref(dev),
|
||||
.birth_usec = now(CLOCK_MONOTONIC),
|
||||
.exec_delay_usec = exec_delay_usec,
|
||||
.rtnl = sd_netlink_ref(rtnl),
|
||||
.uid = UID_INVALID,
|
||||
.gid = GID_INVALID,
|
||||
.mode = MODE_INVALID,
|
||||
@@ -276,14 +276,7 @@ static int update_devnode(UdevEvent *event) {
|
||||
return udev_node_update(dev, event->dev_db_clone);
|
||||
}
|
||||
|
||||
static int event_execute_rules_on_remove(
|
||||
UdevEvent *event,
|
||||
int inotify_fd,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list,
|
||||
UdevRules *rules) {
|
||||
|
||||
static int event_execute_rules_on_remove(UdevEvent *event, UdevRules *rules) {
|
||||
sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
int r;
|
||||
|
||||
@@ -299,11 +292,7 @@ static int event_execute_rules_on_remove(
|
||||
if (r < 0)
|
||||
log_device_debug_errno(dev, r, "Failed to delete database under /run/udev/data/, ignoring: %m");
|
||||
|
||||
r = udev_watch_end(inotify_fd, dev);
|
||||
if (r < 0)
|
||||
log_device_warning_errno(dev, r, "Failed to remove inotify watch, ignoring: %m");
|
||||
|
||||
r = udev_rules_apply_to_event(rules, event, timeout_usec, timeout_signal, properties_list);
|
||||
r = udev_rules_apply_to_event(rules, event);
|
||||
|
||||
if (sd_device_get_devnum(dev, NULL) >= 0)
|
||||
(void) udev_node_remove(dev);
|
||||
@@ -328,14 +317,7 @@ static int copy_all_tags(sd_device *d, sd_device *s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_event_execute_rules(
|
||||
UdevEvent *event,
|
||||
int inotify_fd, /* This may be negative */
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list,
|
||||
UdevRules *rules) {
|
||||
|
||||
int udev_event_execute_rules(UdevEvent *event, UdevRules *rules) {
|
||||
sd_device_action_t action;
|
||||
sd_device *dev;
|
||||
int r;
|
||||
@@ -348,12 +330,7 @@ int udev_event_execute_rules(
|
||||
return log_device_error_errno(dev, r, "Failed to get ACTION: %m");
|
||||
|
||||
if (action == SD_DEVICE_REMOVE)
|
||||
return event_execute_rules_on_remove(event, inotify_fd, timeout_usec, timeout_signal, properties_list, rules);
|
||||
|
||||
/* Disable watch during event processing. */
|
||||
r = udev_watch_end(inotify_fd, dev);
|
||||
if (r < 0)
|
||||
log_device_warning_errno(dev, r, "Failed to remove inotify watch, ignoring: %m");
|
||||
return event_execute_rules_on_remove(event, rules);
|
||||
|
||||
r = device_clone_with_db(dev, &event->dev_db_clone);
|
||||
if (r < 0)
|
||||
@@ -373,7 +350,7 @@ int udev_event_execute_rules(
|
||||
|
||||
DEVICE_TRACE_POINT(rules_start, dev);
|
||||
|
||||
r = udev_rules_apply_to_event(rules, event, timeout_usec, timeout_signal, properties_list);
|
||||
r = udev_rules_apply_to_event(rules, event);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, r, "Failed to apply udev rules: %m");
|
||||
|
||||
|
||||
+6
-10
@@ -15,9 +15,13 @@
|
||||
#include "macro.h"
|
||||
#include "time-util.h"
|
||||
#include "udev-rules.h"
|
||||
#include "udev-worker.h"
|
||||
#include "user-util.h"
|
||||
|
||||
typedef struct UdevEvent {
|
||||
UdevWorker *worker;
|
||||
sd_netlink *rtnl;
|
||||
|
||||
sd_device *dev;
|
||||
sd_device *dev_parent;
|
||||
sd_device *dev_db_clone;
|
||||
@@ -29,9 +33,7 @@ typedef struct UdevEvent {
|
||||
gid_t gid;
|
||||
OrderedHashmap *seclabel_list;
|
||||
OrderedHashmap *run_list;
|
||||
usec_t exec_delay_usec;
|
||||
usec_t birth_usec;
|
||||
sd_netlink *rtnl;
|
||||
unsigned builtin_run;
|
||||
unsigned builtin_ret;
|
||||
UdevRuleEscapeType esc:8;
|
||||
@@ -47,14 +49,8 @@ typedef struct UdevEvent {
|
||||
int default_log_level;
|
||||
} UdevEvent;
|
||||
|
||||
UdevEvent *udev_event_new(sd_device *dev, usec_t exec_delay_usec, sd_netlink *rtnl, int log_level);
|
||||
UdevEvent *udev_event_new(sd_device *dev, UdevWorker *worker);
|
||||
UdevEvent *udev_event_free(UdevEvent *event);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(UdevEvent*, udev_event_free);
|
||||
|
||||
int udev_event_execute_rules(
|
||||
UdevEvent *event,
|
||||
int inotify_fd,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list,
|
||||
UdevRules *rules);
|
||||
int udev_event_execute_rules(UdevEvent *event, UdevRules *rules);
|
||||
|
||||
@@ -156,7 +156,6 @@ static ssize_t udev_event_subst_format(
|
||||
const char *attr,
|
||||
char *dest,
|
||||
size_t l,
|
||||
Hashmap *global_props,
|
||||
bool *ret_truncated) {
|
||||
|
||||
sd_device *parent, *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
|
||||
@@ -349,7 +348,7 @@ static ssize_t udev_event_subst_format(
|
||||
case FORMAT_SUBST_ENV:
|
||||
if (isempty(attr))
|
||||
return -EINVAL;
|
||||
r = device_get_property_value_with_fallback(dev, attr, global_props, &val);
|
||||
r = device_get_property_value_with_fallback(dev, attr, event->worker ? event->worker->properties : NULL, &val);
|
||||
if (r == -ENOENT)
|
||||
goto null_terminate;
|
||||
if (r < 0)
|
||||
@@ -379,7 +378,6 @@ size_t udev_event_apply_format(
|
||||
char *dest,
|
||||
size_t size,
|
||||
bool replace_whitespace,
|
||||
Hashmap *global_props,
|
||||
bool *ret_truncated) {
|
||||
|
||||
bool truncated = false;
|
||||
@@ -412,7 +410,7 @@ size_t udev_event_apply_format(
|
||||
continue;
|
||||
}
|
||||
|
||||
subst_len = udev_event_subst_format(event, type, attr, dest, size, global_props, &t);
|
||||
subst_len = udev_event_subst_format(event, type, attr, dest, size, &t);
|
||||
if (subst_len < 0) {
|
||||
log_device_warning_errno(event->dev, subst_len,
|
||||
"Failed to substitute variable '$%s' or apply format '%%%c', ignoring: %m",
|
||||
|
||||
@@ -14,7 +14,6 @@ size_t udev_event_apply_format(
|
||||
char *dest,
|
||||
size_t size,
|
||||
bool replace_whitespace,
|
||||
Hashmap *global_props,
|
||||
bool *ret_truncated);
|
||||
int udev_check_format(const char *value, size_t *offset, const char **hint);
|
||||
|
||||
|
||||
+31
-47
@@ -1761,7 +1761,7 @@ static bool token_match_attr(UdevRuleToken *token, sd_device *dev, UdevEvent *ev
|
||||
|
||||
switch (token->attr_subst_type) {
|
||||
case SUBST_TYPE_FORMAT:
|
||||
(void) udev_event_apply_format(event, name, nbuf, sizeof(nbuf), false, NULL, &truncated);
|
||||
(void) udev_event_apply_format(event, name, nbuf, sizeof(nbuf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "sysfs attribute name", name,
|
||||
token->type == TK_M_ATTR ? "ATTR" : "ATTRS", /* is_match = */ true);
|
||||
@@ -1928,10 +1928,7 @@ static size_t udev_replace_ifname(char *str) {
|
||||
static int udev_rule_apply_token_to_event(
|
||||
UdevRuleToken *token,
|
||||
sd_device *dev,
|
||||
UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list) {
|
||||
UdevEvent *event) {
|
||||
|
||||
int r;
|
||||
|
||||
@@ -1983,7 +1980,7 @@ static int udev_rule_apply_token_to_event(
|
||||
case TK_M_ENV: {
|
||||
const char *val = NULL;
|
||||
|
||||
(void) device_get_property_value_with_fallback(dev, token->data, properties_list, &val);
|
||||
(void) device_get_property_value_with_fallback(dev, token->data, event->worker ? event->worker->properties : NULL, &val);
|
||||
|
||||
return token_match_string(token, val);
|
||||
}
|
||||
@@ -2038,7 +2035,7 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_PATH_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "sysctl entry name", token->data, "SYSCTL", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2056,7 +2053,7 @@ static int udev_rule_apply_token_to_event(
|
||||
struct stat statbuf;
|
||||
bool match, truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "file name", token->value, "TEST", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2099,7 +2096,7 @@ static int udev_rule_apply_token_to_event(
|
||||
size_t count;
|
||||
|
||||
event->program_result = mfree(event->program_result);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "command", token->value, "PROGRAM", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2107,7 +2104,7 @@ static int udev_rule_apply_token_to_event(
|
||||
|
||||
log_event_debug(dev, token, "Running PROGRAM '%s'", buf);
|
||||
|
||||
r = udev_event_spawn(event, timeout_usec, timeout_signal, true, buf, result, sizeof(result), NULL);
|
||||
r = udev_event_spawn(event, /* accept_failure = */ true, buf, result, sizeof(result), NULL);
|
||||
if (r != 0) {
|
||||
if (r < 0)
|
||||
log_event_warning_errno(dev, token, r, "Failed to execute \"%s\": %m", buf);
|
||||
@@ -2131,7 +2128,7 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_PATH_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "file name to be imported", token->value, "IMPORT", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2182,7 +2179,7 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_LINE_SIZE], result[UDEV_LINE_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "command", token->value, "IMPORT", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2190,7 +2187,7 @@ static int udev_rule_apply_token_to_event(
|
||||
|
||||
log_event_debug(dev, token, "Importing properties from results of '%s'", buf);
|
||||
|
||||
r = udev_event_spawn(event, timeout_usec, timeout_signal, true, buf, result, sizeof result, &truncated);
|
||||
r = udev_event_spawn(event, /* accept_failure = */ true, buf, result, sizeof result, &truncated);
|
||||
if (r != 0) {
|
||||
if (r < 0)
|
||||
log_event_warning_errno(dev, token, r, "Failed to execute '%s', ignoring: %m", buf);
|
||||
@@ -2261,7 +2258,7 @@ static int udev_rule_apply_token_to_event(
|
||||
event->builtin_run |= mask;
|
||||
}
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "builtin command", token->value, "IMPORT", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2317,7 +2314,7 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_PATH_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "property name", token->value, "IMPORT", /* is_match = */ true);
|
||||
return false;
|
||||
@@ -2378,7 +2375,7 @@ static int udev_rule_apply_token_to_event(
|
||||
if (token->op == OP_ASSIGN_FINAL)
|
||||
event->owner_final = true;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, owner, sizeof(owner), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, owner, sizeof(owner), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "user name", token->value, "OWNER", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2401,7 +2398,7 @@ static int udev_rule_apply_token_to_event(
|
||||
if (token->op == OP_ASSIGN_FINAL)
|
||||
event->group_final = true;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, group, sizeof(group), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, group, sizeof(group), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "group name", token->value, "GROUP", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2423,7 +2420,7 @@ static int udev_rule_apply_token_to_event(
|
||||
if (token->op == OP_ASSIGN_FINAL)
|
||||
event->mode_final = true;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, mode_str, sizeof(mode_str), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, mode_str, sizeof(mode_str), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "mode", token->value, "MODE", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2475,7 +2472,7 @@ static int udev_rule_apply_token_to_event(
|
||||
if (!name)
|
||||
return log_oom();
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, label_str, sizeof(label_str), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, label_str, sizeof(label_str), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "security label", token->value, "SECLABEL", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2519,7 +2516,7 @@ static int udev_rule_apply_token_to_event(
|
||||
}
|
||||
|
||||
if (token->op == OP_ADD &&
|
||||
device_get_property_value_with_fallback(dev, name, properties_list, &val) >= 0) {
|
||||
device_get_property_value_with_fallback(dev, name, event->worker ? event->worker->properties : NULL, &val) >= 0) {
|
||||
l = strpcpyl_full(&p, l, &truncated, val, " ", NULL);
|
||||
if (truncated) {
|
||||
log_event_warning(dev, token,
|
||||
@@ -2529,7 +2526,7 @@ static int udev_rule_apply_token_to_event(
|
||||
}
|
||||
}
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, p, l, false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, p, l, false, &truncated);
|
||||
if (truncated) {
|
||||
_cleanup_free_ char *key_with_name = strjoin("ENV{", name, "}");
|
||||
log_event_truncated(dev, token, "property value", token->value,
|
||||
@@ -2554,7 +2551,7 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_PATH_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "tag name", token->value, "TAG", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2591,7 +2588,7 @@ static int udev_rule_apply_token_to_event(
|
||||
break;
|
||||
}
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "network interface name", token->value, "NAME", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2629,7 +2626,7 @@ static int udev_rule_apply_token_to_event(
|
||||
device_cleanup_devlinks(dev);
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf),
|
||||
/* replace_whitespace = */ event->esc != ESCAPE_NONE, properties_list, &truncated);
|
||||
/* replace_whitespace = */ event->esc != ESCAPE_NONE, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "symbolic link path", token->value, "SYMLINK", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2701,7 +2698,7 @@ static int udev_rule_apply_token_to_event(
|
||||
log_event_error_errno(dev, token, r, "Could not find file matches '%s', ignoring: %m", buf);
|
||||
break;
|
||||
}
|
||||
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "attribute value", token->value, "ATTR", /* is_match = */ false);
|
||||
break;
|
||||
@@ -2721,13 +2718,13 @@ static int udev_rule_apply_token_to_event(
|
||||
char buf[UDEV_PATH_SIZE], value[UDEV_NAME_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->data, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "sysctl entry name", token->data, "SYSCTL", /* is_match = */ false);
|
||||
break;
|
||||
}
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, value, sizeof(value), false, &truncated);
|
||||
if (truncated) {
|
||||
_cleanup_free_ char *key_with_name = strjoin("SYSCTL{", buf, "}");
|
||||
log_event_truncated(dev, token, "sysctl value", token->value,
|
||||
@@ -2756,7 +2753,7 @@ static int udev_rule_apply_token_to_event(
|
||||
if (IN_SET(token->op, OP_ASSIGN, OP_ASSIGN_FINAL))
|
||||
ordered_hashmap_clear_free_key(event->run_list);
|
||||
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, properties_list, &truncated);
|
||||
(void) udev_event_apply_format(event, token->value, buf, sizeof(buf), false, &truncated);
|
||||
if (truncated) {
|
||||
log_event_truncated(dev, token, "command", token->value,
|
||||
token->type == TK_A_RUN_BUILTIN ? "RUN{builtin}" : "RUN{program}",
|
||||
@@ -2793,11 +2790,7 @@ static bool token_is_for_parents(UdevRuleToken *token) {
|
||||
return token->type >= TK_M_PARENTS_KERNEL && token->type <= TK_M_PARENTS_TAG;
|
||||
}
|
||||
|
||||
static int udev_rule_apply_parent_token_to_event(
|
||||
UdevRuleToken *head_token,
|
||||
UdevEvent *event,
|
||||
int timeout_signal) {
|
||||
|
||||
static int udev_rule_apply_parent_token_to_event(UdevRuleToken *head_token, UdevEvent *event) {
|
||||
int r;
|
||||
|
||||
assert(head_token);
|
||||
@@ -2810,7 +2803,7 @@ static int udev_rule_apply_parent_token_to_event(
|
||||
if (!token_is_for_parents(token))
|
||||
return true; /* All parent tokens match. */
|
||||
|
||||
r = udev_rule_apply_token_to_event(token, event->dev_parent, event, 0, timeout_signal, NULL);
|
||||
r = udev_rule_apply_token_to_event(token, event->dev_parent, event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
@@ -2830,9 +2823,6 @@ static int udev_rule_apply_parent_token_to_event(
|
||||
static int udev_rule_apply_line_to_event(
|
||||
UdevRuleLine *line,
|
||||
UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list,
|
||||
UdevRuleLine **next_line) {
|
||||
|
||||
UdevRuleLineType mask = LINE_HAS_GOTO | LINE_UPDATE_SOMETHING;
|
||||
@@ -2868,7 +2858,7 @@ static int udev_rule_apply_line_to_event(
|
||||
if (parents_done)
|
||||
continue;
|
||||
|
||||
r = udev_rule_apply_parent_token_to_event(token, event, timeout_signal);
|
||||
r = udev_rule_apply_parent_token_to_event(token, event);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
@@ -2876,7 +2866,7 @@ static int udev_rule_apply_line_to_event(
|
||||
continue;
|
||||
}
|
||||
|
||||
r = udev_rule_apply_token_to_event(token, event->dev, event, timeout_usec, timeout_signal, properties_list);
|
||||
r = udev_rule_apply_token_to_event(token, event->dev, event);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
@@ -2887,13 +2877,7 @@ static int udev_rule_apply_line_to_event(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udev_rules_apply_to_event(
|
||||
UdevRules *rules,
|
||||
UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list) {
|
||||
|
||||
int udev_rules_apply_to_event(UdevRules *rules, UdevEvent *event) {
|
||||
int r;
|
||||
|
||||
assert(rules);
|
||||
@@ -2901,7 +2885,7 @@ int udev_rules_apply_to_event(
|
||||
|
||||
LIST_FOREACH(rule_files, file, rules->rule_files)
|
||||
LIST_FOREACH_WITH_NEXT(rule_lines, line, next_line, file->rule_lines) {
|
||||
r = udev_rule_apply_line_to_event(line, event, timeout_usec, timeout_signal, properties_list, &next_line);
|
||||
r = udev_rule_apply_line_to_event(line, event, &next_line);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -39,10 +39,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(UdevRules*, udev_rules_free);
|
||||
#define udev_rules_free_and_replace(a, b) free_and_replace_full(a, b, udev_rules_free)
|
||||
|
||||
bool udev_rules_should_reload(UdevRules *rules);
|
||||
int udev_rules_apply_to_event(UdevRules *rules, UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
Hashmap *properties_list);
|
||||
int udev_rules_apply_to_event(UdevRules *rules, UdevEvent *event);
|
||||
int udev_rules_apply_static_dev_perms(UdevRules *rules);
|
||||
|
||||
ResolveNameTiming resolve_name_timing_from_string(const char *s) _pure_;
|
||||
|
||||
+10
-7
@@ -221,8 +221,6 @@ static int spawn_wait(Spawn *spawn) {
|
||||
|
||||
int udev_event_spawn(
|
||||
UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
bool accept_failure,
|
||||
const char *cmd,
|
||||
char *result,
|
||||
@@ -240,6 +238,9 @@ int udev_event_spawn(
|
||||
assert(event->dev);
|
||||
assert(result || result_size == 0);
|
||||
|
||||
int timeout_signal = event->worker ? event->worker->timeout_signal : SIGKILL;
|
||||
usec_t timeout_usec = event->worker ? event->worker->timeout_usec : DEFAULT_WORKER_TIMEOUT_USEC;
|
||||
|
||||
/* pipes from child to parent */
|
||||
if (result || log_get_max_level() >= LOG_INFO)
|
||||
if (pipe2(outpipe, O_NONBLOCK|O_CLOEXEC) != 0)
|
||||
@@ -322,11 +323,13 @@ int udev_event_spawn(
|
||||
return r; /* 0 for success, and positive if the program failed */
|
||||
}
|
||||
|
||||
void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_signal) {
|
||||
void udev_event_execute_run(UdevEvent *event) {
|
||||
const char *command;
|
||||
void *val;
|
||||
int r;
|
||||
|
||||
assert(event);
|
||||
|
||||
ORDERED_HASHMAP_FOREACH_KEY(val, command, event->run_list) {
|
||||
UdevBuiltinCommand builtin_cmd = PTR_TO_UDEV_BUILTIN_CMD(val);
|
||||
|
||||
@@ -336,15 +339,15 @@ void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_s
|
||||
if (r < 0)
|
||||
log_device_debug_errno(event->dev, r, "Failed to run built-in command \"%s\", ignoring: %m", command);
|
||||
} else {
|
||||
if (event->exec_delay_usec > 0) {
|
||||
if (event->worker && event->worker->exec_delay_usec > 0) {
|
||||
log_device_debug(event->dev, "Delaying execution of \"%s\" for %s.",
|
||||
command, FORMAT_TIMESPAN(event->exec_delay_usec, USEC_PER_SEC));
|
||||
(void) usleep_safe(event->exec_delay_usec);
|
||||
command, FORMAT_TIMESPAN(event->worker->exec_delay_usec, USEC_PER_SEC));
|
||||
(void) usleep_safe(event->worker->exec_delay_usec);
|
||||
}
|
||||
|
||||
log_device_debug(event->dev, "Running command \"%s\"", command);
|
||||
|
||||
r = udev_event_spawn(event, timeout_usec, timeout_signal, false, command, NULL, 0, NULL);
|
||||
r = udev_event_spawn(event, /* accept_failure = */ false, command, NULL, 0, NULL);
|
||||
if (r < 0)
|
||||
log_device_warning_errno(event->dev, r, "Failed to execute '%s', ignoring: %m", command);
|
||||
else if (r > 0) /* returned value is positive when program fails */
|
||||
|
||||
@@ -14,14 +14,12 @@ typedef struct UdevEvent UdevEvent;
|
||||
|
||||
int udev_event_spawn(
|
||||
UdevEvent *event,
|
||||
usec_t timeout_usec,
|
||||
int timeout_signal,
|
||||
bool accept_failure,
|
||||
const char *cmd,
|
||||
char *result,
|
||||
size_t ressize,
|
||||
bool *ret_truncated);
|
||||
void udev_event_execute_run(UdevEvent *event, usec_t timeout_usec, int timeout_signal);
|
||||
void udev_event_execute_run(UdevEvent *event);
|
||||
|
||||
static inline usec_t udev_warn_timeout(usec_t timeout_usec) {
|
||||
if (timeout_usec == USEC_INFINITY)
|
||||
|
||||
@@ -232,12 +232,9 @@ int udev_watch_end(int inotify_fd, sd_device *dev) {
|
||||
_cleanup_close_ int dirfd = -EBADF;
|
||||
int wd, r;
|
||||
|
||||
assert(inotify_fd >= 0);
|
||||
assert(dev);
|
||||
|
||||
/* This may be called by 'udevadm test'. In that case, inotify_fd is not initialized. */
|
||||
if (inotify_fd < 0)
|
||||
return 0;
|
||||
|
||||
if (sd_device_get_devname(dev, NULL) < 0)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ static int worker_process_device(UdevWorker *worker, sd_device *dev) {
|
||||
|
||||
log_device_uevent(dev, "Processing device");
|
||||
|
||||
udev_event = udev_event_new(dev, worker->exec_delay_usec, worker->rtnl, worker->log_level);
|
||||
udev_event = udev_event_new(dev, worker);
|
||||
if (!udev_event)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -194,18 +194,17 @@ static int worker_process_device(UdevWorker *worker, sd_device *dev) {
|
||||
if (worker->blockdev_read_only)
|
||||
(void) worker_mark_block_device_read_only(dev);
|
||||
|
||||
/* Disable watch during event processing. */
|
||||
r = udev_watch_end(worker->inotify_fd, dev);
|
||||
if (r < 0)
|
||||
log_device_warning_errno(dev, r, "Failed to remove inotify watch, ignoring: %m");
|
||||
|
||||
/* apply rules, create node, symlinks */
|
||||
r = udev_event_execute_rules(
|
||||
udev_event,
|
||||
worker->inotify_fd,
|
||||
worker->timeout_usec,
|
||||
worker->timeout_signal,
|
||||
worker->properties,
|
||||
worker->rules);
|
||||
r = udev_event_execute_rules(udev_event, worker->rules);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
udev_event_execute_run(udev_event, worker->timeout_usec, worker->timeout_signal);
|
||||
udev_event_execute_run(udev_event);
|
||||
|
||||
if (!worker->rtnl)
|
||||
/* in case rtnl was initialized */
|
||||
|
||||
@@ -97,7 +97,7 @@ int builtin_main(int argc, char *argv[], void *userdata) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
event = udev_event_new(dev, 0, NULL, LOG_DEBUG);
|
||||
event = udev_event_new(dev, NULL);
|
||||
if (!event) {
|
||||
r = log_oom();
|
||||
goto finish;
|
||||
|
||||
@@ -124,12 +124,12 @@ int test_main(int argc, char *argv[], void *userdata) {
|
||||
/* don't read info from the db */
|
||||
device_seal(dev);
|
||||
|
||||
event = udev_event_new(dev, 0, NULL, LOG_DEBUG);
|
||||
event = udev_event_new(dev, NULL);
|
||||
|
||||
assert_se(sigfillset(&mask) >= 0);
|
||||
assert_se(sigprocmask(SIG_SETMASK, &mask, &sigmask_orig) >= 0);
|
||||
|
||||
udev_event_execute_rules(event, -1, 60 * USEC_PER_SEC, SIGKILL, NULL, rules);
|
||||
udev_event_execute_rules(event, rules);
|
||||
|
||||
FOREACH_DEVICE_PROPERTY(dev, key, value)
|
||||
printf("%s=%s\n", key, value);
|
||||
@@ -138,7 +138,7 @@ int test_main(int argc, char *argv[], void *userdata) {
|
||||
char program[UDEV_PATH_SIZE];
|
||||
bool truncated;
|
||||
|
||||
(void) udev_event_apply_format(event, cmd, program, sizeof(program), false, NULL, &truncated);
|
||||
(void) udev_event_apply_format(event, cmd, program, sizeof(program), false, &truncated);
|
||||
if (truncated)
|
||||
log_warning("The command '%s' is truncated while substituting into '%s'.", program, cmd);
|
||||
printf("run: '%s'\n", program);
|
||||
|
||||
Reference in New Issue
Block a user