You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
systemd/SOURCES/0392-udev-move-device_renam...

149 lines
4.9 KiB

From 7f183125fbec97bd6e4c0b3ac792b0e0c23132e0 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 9 Jan 2023 15:00:30 +0900
Subject: [PATCH] udev: move device_rename() from device-private.c
The function is used only by udevd.
(cherry picked from commit ff88b949531e70639c507f74da875a7de2adf543)
Related: RHEL-5988
---
src/libsystemd/sd-device/device-private.c | 45 ----------------------
src/libsystemd/sd-device/device-private.h | 1 -
src/udev/udev-event.c | 46 +++++++++++++++++++++++
3 files changed, 46 insertions(+), 46 deletions(-)
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 9cec037237..36b0da4f12 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -619,51 +619,6 @@ int device_get_devlink_priority(sd_device *device, int *ret) {
return 0;
}
-int device_rename(sd_device *device, const char *name) {
- _cleanup_free_ char *new_syspath = NULL;
- const char *s;
- int r;
-
- assert(device);
- assert(name);
-
- if (!filename_is_valid(name))
- return -EINVAL;
-
- r = sd_device_get_syspath(device, &s);
- if (r < 0)
- return r;
-
- r = path_extract_directory(s, &new_syspath);
- if (r < 0)
- return r;
-
- if (!path_extend(&new_syspath, name))
- return -ENOMEM;
-
- if (!path_is_safe(new_syspath))
- return -EINVAL;
-
- /* At the time this is called, the renamed device may not exist yet. Hence, we cannot validate
- * the new syspath. */
- r = device_set_syspath(device, new_syspath, /* verify = */ false);
- if (r < 0)
- return r;
-
- r = sd_device_get_property_value(device, "INTERFACE", &s);
- if (r == -ENOENT)
- return 0;
- if (r < 0)
- return r;
-
- /* like DEVPATH_OLD, INTERFACE_OLD is not saved to the db, but only stays around for the current event */
- r = device_add_property_internal(device, "INTERFACE_OLD", s);
- if (r < 0)
- return r;
-
- return device_add_property_internal(device, "INTERFACE", name);
-}
-
static int device_shallow_clone(sd_device *device, sd_device **ret) {
_cleanup_(sd_device_unrefp) sd_device *dest = NULL;
const char *val = NULL;
diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h
index a59f130aff..e57b74ba24 100644
--- a/src/libsystemd/sd-device/device-private.h
+++ b/src/libsystemd/sd-device/device-private.h
@@ -53,7 +53,6 @@ int device_properties_prepare(sd_device *device);
int device_get_properties_nulstr(sd_device *device, const char **ret_nulstr, size_t *ret_len);
int device_get_properties_strv(sd_device *device, char ***ret);
-int device_rename(sd_device *device, const char *name);
int device_clone_with_db(sd_device *device, sd_device **ret);
int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 3ac12d9b52..1dc05f863d 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -12,6 +12,7 @@
#include "sd-event.h"
#include "alloc-util.h"
+#include "device-internal.h"
#include "device-private.h"
#include "device-util.h"
#include "fd-util.h"
@@ -859,6 +860,51 @@ int udev_event_spawn(
return r; /* 0 for success, and positive if the program failed */
}
+static int device_rename(sd_device *device, const char *name) {
+ _cleanup_free_ char *new_syspath = NULL;
+ const char *s;
+ int r;
+
+ assert(device);
+ assert(name);
+
+ if (!filename_is_valid(name))
+ return -EINVAL;
+
+ r = sd_device_get_syspath(device, &s);
+ if (r < 0)
+ return r;
+
+ r = path_extract_directory(s, &new_syspath);
+ if (r < 0)
+ return r;
+
+ if (!path_extend(&new_syspath, name))
+ return -ENOMEM;
+
+ if (!path_is_safe(new_syspath))
+ return -EINVAL;
+
+ /* At the time this is called, the renamed device may not exist yet. Hence, we cannot validate
+ * the new syspath. */
+ r = device_set_syspath(device, new_syspath, /* verify = */ false);
+ if (r < 0)
+ return r;
+
+ r = sd_device_get_property_value(device, "INTERFACE", &s);
+ if (r == -ENOENT)
+ return 0;
+ if (r < 0)
+ return r;
+
+ /* like DEVPATH_OLD, INTERFACE_OLD is not saved to the db, but only stays around for the current event */
+ r = device_add_property_internal(device, "INTERFACE_OLD", s);
+ if (r < 0)
+ return r;
+
+ return device_add_property_internal(device, "INTERFACE", name);
+}
+
static int rename_netif(UdevEvent *event) {
const char *oldname;
sd_device *dev;