]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: introduce database version and save it in udev database V field
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Nov 2020 21:23:14 +0000 (06:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 25 Nov 2020 21:38:38 +0000 (06:38 +0900)
src/libsystemd/sd-device/device-internal.h
src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/sd-device.c

index da630f18fc27af176ec21a9139800a4224e34cdf..3321c8e2dc6542b93f5709a0aee2e89fd5f70c4c 100644 (file)
@@ -8,9 +8,19 @@
 #include "set.h"
 #include "time-util.h"
 
+#define LATEST_UDEV_DATABASE_VERSION 1
+
 struct sd_device {
         unsigned n_ref;
 
+        /* The database version indicates the supported features by the udev database.
+         * This is saved and parsed in V field.
+         *
+         * 0: None of the following features are supported (systemd version <= 246).
+         * 1: The current tags (Q) and the database version (V) features are implemented (>= 247).
+         */
+        unsigned database_version;
+
         int watch_handle;
 
         sd_device *parent;
index 1c7bb033d31ff8074a75046e7a14d231dc672f61..2801ebdcbe32080a929d574d562ac3b9d2777527 100644 (file)
@@ -948,6 +948,10 @@ int device_update_db(sd_device *device) {
 
                 SET_FOREACH(tag, device->current_tags)
                         fprintf(f, "Q:%s\n", tag); /* Current tag */
+
+                /* Always write the latest database version here, instead of the value stored in
+                 * device->database_version, as which may be 0. */
+                fputs("V:" STRINGIFY(LATEST_UDEV_DATABASE_VERSION) "\n", f);
         }
 
         r = fflush_and_check(f);
index e895b7818a3edce4a4565c5846278ea852c9cf9a..1b07f528f291ad25e88ce2e359bf6f434d730439 100644 (file)
@@ -1204,6 +1204,12 @@ static int handle_db_line(sd_device *device, char key, const char *value) {
                 if (r < 0)
                         return r;
 
+                break;
+        case 'V':
+                r = safe_atou(value, &device->database_version);
+                if (r < 0)
+                        return r;
+
                 break;
         default:
                 log_device_debug(device, "sd-device: Unknown key '%c' in device db, ignoring", key);