From c9473aaa5b69c47edab365b46abee6e9ab5b18dc Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Fri, 25 Mar 2022 01:13:39 +0900
Subject: [PATCH] udev: drop unnecessary clone of received sd-device object
 
As the sd-device object received through sd-device-monitor is sealed,
so the corresponding udev database or uevent file will not be read.
 
Reference:https://github.com/systemd/systemd/commit/c9473aaa5b69c47edab365b46abee6e9ab5b18dc
Conflict:adaption
 
---
 src/udev/udevd.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
 
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 108142e9c619..05397df7a429 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -124,7 +124,6 @@ typedef struct Event {
         EventState state;
 
         sd_device *dev;
-        sd_device *dev_kernel; /* clone of originally received device */
 
         uint64_t seqnum;
         uint64_t blocker_seqnum;
@@ -163,7 +162,6 @@ static Event *event_free(Event *event) {
 
         LIST_REMOVE(event, event->manager->events, event);
         sd_device_unref(event->dev);
-        sd_device_unref(event->dev_kernel);
 
         sd_event_source_unref(event->timeout_warning_event);
         sd_event_source_unref(event->timeout_event);
@@ -973,9 +971,8 @@ static int event_queue_start(Manager *manager) {
 }
 
 static int event_queue_insert(Manager *manager, sd_device *dev) {
-        _cleanup_(sd_device_unrefp) sd_device *clone = NULL;
-        Event *event;
         uint64_t seqnum;
+        Event *event;
         int r;
 
         assert(manager);
@@ -989,15 +986,6 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
         if (r < 0)
                 return r;
 
-        /* Save original device to restore the state on failures. */
-        r = device_shallow_clone(dev, &clone);
-        if (r < 0)
-                return r;
-
-        r = device_copy_properties(clone, dev);
-        if (r < 0)
-                return r;
-
         event = new(Event, 1);
         if (!event)
                 return -ENOMEM;
@@ -1005,7 +993,6 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
         *event = (Event) {
                 .manager = manager,
                 .dev = sd_device_ref(dev),
-                .dev_kernel = TAKE_PTR(clone),
                 .seqnum = seqnum,
                 .state = EVENT_QUEUED,
         };
@@ -1440,10 +1427,10 @@ static int on_sigchld(sd_event_source *s, const struct signalfd_siginfo *si, voi
                         device_tag_index(worker->event->dev, NULL, false);
 
                         if (manager->monitor) {
-                                /* Forward kernel event unchanged */
-                                r = device_monitor_send_device(manager->monitor, NULL, worker->event->dev_kernel);
+                                /* Forward kernel event to libudev listeners */
+                                r = device_monitor_send_device(manager->monitor, NULL, worker->event->dev);
                                 if (r < 0)
-                                        log_device_warning_errno(worker->event->dev_kernel, r,
+                                        log_device_warning_errno(worker->event->dev, r,
                                                                  "Failed to broadcast failed event to libudev listeners, ignoring: %m");
                         }
                 }
 