summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-11-22 05:05:26 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-12-22 20:45:13 +0100
commit6e574ebd00c96b2f51fdb5db9fa629b9deb2c309 (patch)
tree22ce0ad14046834e051695b596aa9144c123ffa7 /src/libsystemd
parentsd-device: modernize device_update_db() and friends (diff)
downloadsystemd-6e574ebd00c96b2f51fdb5db9fa629b9deb2c309.tar.xz
systemd-6e574ebd00c96b2f51fdb5db9fa629b9deb2c309.zip
sd-device: introduce device_has_db() helper function
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-device/device-private.c13
-rw-r--r--src/libsystemd/sd-device/device-private.h1
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 90df3f724d..cd85ec9c62 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -809,6 +809,19 @@ static int device_get_db_path(sd_device *device, char **ret) {
return 0;
}
+int device_has_db(sd_device *device) {
+ _cleanup_free_ char *path = NULL;
+ int r;
+
+ assert(device);
+
+ r = device_get_db_path(device, &path);
+ if (r < 0)
+ return r;
+
+ return access(path, F_OK) >= 0;
+}
+
int device_update_db(sd_device *device) {
_cleanup_(unlink_and_freep) char *path = NULL, *path_tmp = NULL;
_cleanup_fclose_ FILE *f = NULL;
diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h
index a0161e7c12..79a0013dc7 100644
--- a/src/libsystemd/sd-device/device-private.h
+++ b/src/libsystemd/sd-device/device-private.h
@@ -59,6 +59,7 @@ int device_clone_with_db(sd_device *device, sd_device **ret);
int device_tag_index(sd_device *dev, sd_device *dev_old, bool add);
bool device_should_have_db(sd_device *device);
+int device_has_db(sd_device *device);
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 */