mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
sd-device: let device_set_subsystem() accept NULL
This makes device_shallow_clone() simpler.
Follow-up for 2255e8adee
.
This commit is contained in:
parent
ad64e3e8d6
commit
df49a7323a
@ -107,7 +107,7 @@ int device_set_devmode(sd_device *device, const char *devmode);
|
|||||||
int device_set_devname(sd_device *device, const char *devname);
|
int device_set_devname(sd_device *device, const char *devname);
|
||||||
int device_set_devtype(sd_device *device, const char *devtype);
|
int device_set_devtype(sd_device *device, const char *devtype);
|
||||||
int device_set_devnum(sd_device *device, const char *major, const char *minor);
|
int device_set_devnum(sd_device *device, const char *major, const char *minor);
|
||||||
int device_set_subsystem(sd_device *device, const char *_subsystem);
|
int device_set_subsystem(sd_device *device, const char *subsystem);
|
||||||
int device_set_drivers_subsystem(sd_device *device);
|
int device_set_drivers_subsystem(sd_device *device);
|
||||||
int device_set_driver(sd_device *device, const char *_driver);
|
int device_set_driver(sd_device *device, const char *_driver);
|
||||||
int device_set_usec_initialized(sd_device *device, usec_t when);
|
int device_set_usec_initialized(sd_device *device, usec_t when);
|
||||||
|
@ -765,18 +765,15 @@ int device_shallow_clone(sd_device *old_device, sd_device **new_device) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (sd_device_get_subsystem(old_device, &val) >= 0) {
|
(void) sd_device_get_subsystem(old_device, &val);
|
||||||
r = device_set_subsystem(ret, val);
|
r = device_set_subsystem(ret, val);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (streq_ptr(val, "drivers")) {
|
||||||
|
r = free_and_strdup(&ret->driver_subsystem, old_device->driver_subsystem);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
if (streq(val, "drivers")) {
|
|
||||||
ret->driver_subsystem = strdup(old_device->driver_subsystem);
|
|
||||||
if (!ret->driver_subsystem)
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
ret->subsystem_set = true;
|
|
||||||
|
|
||||||
/* The device may be already removed. Let's copy minimal set of information to make
|
/* The device may be already removed. Let's copy minimal set of information to make
|
||||||
* device_get_device_id() work without uevent file. */
|
* device_get_device_id() work without uevent file. */
|
||||||
|
@ -779,23 +779,24 @@ _public_ int sd_device_get_parent(sd_device *child, sd_device **ret) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int device_set_subsystem(sd_device *device, const char *_subsystem) {
|
int device_set_subsystem(sd_device *device, const char *subsystem) {
|
||||||
_cleanup_free_ char *subsystem = NULL;
|
_cleanup_free_ char *s = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(device);
|
assert(device);
|
||||||
assert(_subsystem);
|
|
||||||
|
|
||||||
subsystem = strdup(_subsystem);
|
if (subsystem) {
|
||||||
if (!subsystem)
|
s = strdup(subsystem);
|
||||||
return -ENOMEM;
|
if (!s)
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
r = device_add_property_internal(device, "SUBSYSTEM", subsystem);
|
r = device_add_property_internal(device, "SUBSYSTEM", s);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
device->subsystem_set = true;
|
device->subsystem_set = true;
|
||||||
return free_and_replace(device->subsystem, subsystem);
|
return free_and_replace(device->subsystem, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int device_set_drivers_subsystem(sd_device *device) {
|
int device_set_drivers_subsystem(sd_device *device) {
|
||||||
|
Loading…
Reference in New Issue
Block a user