1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-08 08:58:27 +03:00

sd-device: use path_extract_filename() at one more place

This also does several cleanups.
This commit is contained in:
Yu Watanabe 2022-04-17 14:25:27 +09:00
parent 60e50fb20d
commit ce1d08ba94

View File

@ -1437,37 +1437,30 @@ int device_get_device_id(sd_device *device, const char **ret) {
return r;
if (sd_device_get_devnum(device, &devnum) >= 0) {
assert(subsystem);
/* use dev_t — b259:131072, c254:0 */
r = asprintf(&id, "%c%u:%u",
if (asprintf(&id, "%c%u:%u",
streq(subsystem, "block") ? 'b' : 'c',
major(devnum), minor(devnum));
if (r < 0)
major(devnum), minor(devnum)) < 0)
return -ENOMEM;
} else if (sd_device_get_ifindex(device, &ifindex) >= 0) {
/* use netdev ifindex — n3 */
r = asprintf(&id, "n%u", (unsigned) ifindex);
if (r < 0)
if (asprintf(&id, "n%u", (unsigned) ifindex) < 0)
return -ENOMEM;
} else {
_cleanup_free_ char *sysname = NULL;
/* use $subsys:$sysname — pci:0000:00:1f.2
* sysname() has '!' translated, get it from devpath
*/
const char *sysname;
* sd_device_get_sysname() has '!' translated, get it from devpath */
r = path_extract_filename(device->devpath, &sysname);
if (r < 0)
return r;
sysname = basename(device->devpath);
if (!sysname)
return -EINVAL;
if (!subsystem)
return -EINVAL;
if (streq(subsystem, "drivers"))
/* the 'drivers' pseudo-subsystem is special, and needs the real subsystem
* encoded as well */
if (streq(subsystem, "drivers")) {
/* the 'drivers' pseudo-subsystem is special, and needs the real
* subsystem encoded as well */
assert(device->driver_subsystem);
id = strjoin("+drivers:", device->driver_subsystem, ":", sysname);
else
} else
id = strjoin("+", subsystem, ":", sysname);
if (!id)
return -ENOMEM;