diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-09 15:00:30 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-09 15:02:55 +0900 |
commit | ff88b949531e70639c507f74da875a7de2adf543 (patch) | |
tree | 4bf1b9c8ff1db99c9d5080c52c0b4c69130c8d8f /src/udev/udev-event.c | |
parent | 1de6a49721957a85a4934ddbdf88d535774597b1 (diff) | |
download | systemd-ff88b949531e70639c507f74da875a7de2adf543.tar.gz |
udev: move device_rename() from device-private.c
The function is used only by udevd.
Diffstat (limited to 'src/udev/udev-event.c')
-rw-r--r-- | src/udev/udev-event.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c index ebffdc3430..e0904145ea 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; |