systemd/SOURCES/0434-udevadm-trigger-allow-to-fallback-without-synthetic-.patch

105 lines
4.4 KiB
Diff
Raw Normal View History

2024-04-30 11:42:21 +00:00
From 597c41edd3e94f2c16209359fbd8de7ed44225d7 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Fri, 28 Oct 2022 10:14:09 +0900
Subject: [PATCH] udevadm-trigger: allow to fallback without synthetic UUID
only first time
If a device is successfully triggered with synthetic UUID, then that means
the kernel support it. Hence, it is not necessary to fallback without UUID
for later devices.
(cherry picked from commit b15039425feba8f316fb306b75d96e2f0f0b82fa)
Related: RHEL-5988
---
src/udev/udevadm-trigger.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c
index 1d421064d7..cda31edd75 100644
--- a/src/udev/udevadm-trigger.c
+++ b/src/udev/udevadm-trigger.c
@@ -26,17 +26,20 @@ static bool arg_verbose = false;
static bool arg_dry_run = false;
static bool arg_quiet = false;
static bool arg_uuid = false;
+static bool arg_settle = false;
static int exec_list(
sd_device_enumerator *e,
sd_device_action_t action,
Hashmap *settle_hashmap) {
- bool skip_uuid_logic = false;
+ int uuid_supported = -1;
const char *action_str;
sd_device *d;
int r, ret = 0;
+ assert(e);
+
action_str = device_action_to_string(action);
FOREACH_DEVICE_AND_SUBSYSTEM(e, d) {
@@ -57,14 +60,14 @@ static int exec_list(
/* Use the UUID mode if the user explicitly asked for it, or if --settle has been specified,
* so that we can recognize our own uevent. */
- r = sd_device_trigger_with_uuid(d, action, (arg_uuid || settle_hashmap) && !skip_uuid_logic ? &id : NULL);
- if (r == -EINVAL && !arg_uuid && settle_hashmap && !skip_uuid_logic) {
+ r = sd_device_trigger_with_uuid(d, action, (arg_uuid || arg_settle) && uuid_supported != 0 ? &id : NULL);
+ if (r == -EINVAL && !arg_uuid && arg_settle && uuid_supported < 0) {
/* If we specified a UUID because of the settling logic, and we got EINVAL this might
* be caused by an old kernel which doesn't know the UUID logic (pre-4.13). Let's try
* if it works without the UUID logic then. */
r = sd_device_trigger(d, action);
if (r != -EINVAL)
- skip_uuid_logic = true; /* dropping the uuid stuff changed the return code,
+ uuid_supported = false; /* dropping the uuid stuff changed the return code,
* hence don't bother next time */
}
if (r < 0) {
@@ -108,11 +111,14 @@ static int exec_list(
continue;
}
+ if (uuid_supported < 0)
+ uuid_supported = true;
+
/* If the user asked for it, write event UUID to stdout */
if (arg_uuid)
printf(SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(id));
- if (settle_hashmap) {
+ if (arg_settle) {
_cleanup_free_ sd_id128_t *mid = NULL;
_cleanup_free_ char *sp = NULL;
@@ -285,7 +291,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
_cleanup_hashmap_free_ Hashmap *settle_hashmap = NULL;
usec_t ping_timeout_usec = 5 * USEC_PER_SEC;
- bool settle = false, ping = false;
+ bool ping = false;
int c, r;
if (running_in_chroot() > 0) {
@@ -389,7 +395,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
break;
}
case 'w':
- settle = true;
+ arg_settle = true;
break;
case ARG_NAME: {
@@ -477,7 +483,7 @@ int trigger_main(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to add parent match '%s': %m", argv[optind]);
}
- if (settle) {
+ if (arg_settle) {
settle_hashmap = hashmap_new(&path_hash_ops_free_free);
if (!settle_hashmap)
return log_oom();