sd-device: attempt to read db again if it wasn't found

This mostly reverts "sd-device: don't retry loading uevent/db files more than
once", 7141e4f62c. We will retry if we couldn't
access the file, but not if parsing failed.

Not re-reading the database at all just doesn't seem like a good idea. We have
two implementations of device_read_db, and one does that, and the other retries
to read the db. Re-reading seems more useful, since we can create the object
and then access properties as some later time when we know that the device has
been initialized and we can get useful results. Otherwise, we force the user to
destroy this object and create a new one.

This changes device_read_uevent_file() and device_read_db_aux(). See next
commit for description of where those functions are used.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-12-13 15:41:09 +01:00
parent 421e3b45f0
commit cd53c8f97d

View file

@ -498,8 +498,6 @@ int device_read_uevent_file(sd_device *device) {
if (device->uevent_loaded || device->sealed)
return 0;
device->uevent_loaded = true;
r = sd_device_get_syspath(device, &syspath);
if (r < 0)
return r;
@ -507,15 +505,19 @@ int device_read_uevent_file(sd_device *device) {
path = strjoina(syspath, "/uevent");
r = read_full_file(path, &uevent, &uevent_len);
if (r == -EACCES)
if (r == -EACCES) {
/* empty uevent files may be write-only */
device->uevent_loaded = true;
return 0;
else if (r == -ENOENT)
}
if (r == -ENOENT)
/* some devices may not have uevent files, see set_syspath() */
return 0;
else if (r < 0)
if (r < 0)
return log_device_debug_errno(device, r, "sd-device: Failed to read uevent file '%s': %m", path);
device->uevent_loaded = true;
for (i = 0; i < uevent_len; i++)
switch (state) {
case PRE_KEY:
@ -1301,8 +1303,6 @@ int device_read_db_aux(sd_device *device, bool force) {
if (device->db_loaded || (!force && device->sealed))
return 0;
device->db_loaded = true;
r = device_get_id_filename(device, &id);
if (r < 0)
return r;
@ -1320,6 +1320,8 @@ int device_read_db_aux(sd_device *device, bool force) {
/* devices with a database entry are initialized */
device->is_initialized = true;
device->db_loaded = true;
for (i = 0; i < db_len; i++) {
switch (state) {
case PRE_KEY: