mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
sd-device: split device_read_db_internal() into two part
The new device_read_db_internal_filename() will be used by a fuzzer.
This commit is contained in:
parent
c20db38875
commit
b07d0f2a85
@ -50,6 +50,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
|
||||
int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
|
||||
int device_update_db(sd_device *device);
|
||||
int device_delete_db(sd_device *device);
|
||||
int device_read_db_internal_filename(sd_device *device, const char *filename); /* For fuzzer */
|
||||
int device_read_db_internal(sd_device *device, bool force);
|
||||
static inline int device_read_db(sd_device *device) {
|
||||
return device_read_db_internal(device, false);
|
||||
|
@ -1273,13 +1273,11 @@ int device_get_id_filename(sd_device *device, const char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_read_db_internal(sd_device *device, bool force) {
|
||||
int device_read_db_internal_filename(sd_device *device, const char *filename) {
|
||||
_cleanup_free_ char *db = NULL;
|
||||
char *path;
|
||||
const char *id, *value;
|
||||
const char *value;
|
||||
size_t db_len, i;
|
||||
char key;
|
||||
size_t db_len;
|
||||
unsigned i;
|
||||
int r;
|
||||
|
||||
enum {
|
||||
@ -1291,22 +1289,14 @@ int device_read_db_internal(sd_device *device, bool force) {
|
||||
} state = PRE_KEY;
|
||||
|
||||
assert(device);
|
||||
assert(filename);
|
||||
|
||||
if (device->db_loaded || (!force && device->sealed))
|
||||
return 0;
|
||||
|
||||
r = device_get_id_filename(device, &id);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
path = strjoina("/run/udev/data/", id);
|
||||
|
||||
r = read_full_file(path, &db, &db_len);
|
||||
r = read_full_file(filename, &db, &db_len);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
else
|
||||
return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", path);
|
||||
|
||||
return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", filename);
|
||||
}
|
||||
|
||||
/* devices with a database entry are initialized */
|
||||
@ -1359,13 +1349,31 @@ int device_read_db_internal(sd_device *device, bool force) {
|
||||
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("Invalid state when parsing db");
|
||||
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL), "sd-device: invalid db syntax.");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_read_db_internal(sd_device *device, bool force) {
|
||||
const char *id, *path;
|
||||
int r;
|
||||
|
||||
assert(device);
|
||||
|
||||
if (device->db_loaded || (!force && device->sealed))
|
||||
return 0;
|
||||
|
||||
r = device_get_id_filename(device, &id);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
path = strjoina("/run/udev/data/", id);
|
||||
|
||||
return device_read_db_internal_filename(device, path);
|
||||
}
|
||||
|
||||
_public_ int sd_device_get_is_initialized(sd_device *device) {
|
||||
int r;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user