diff --git a/src/libsystemd/sd-device/device-internal.h b/src/libsystemd/sd-device/device-internal.h index da630f18fc..3321c8e2dc 100644 --- a/src/libsystemd/sd-device/device-internal.h +++ b/src/libsystemd/sd-device/device-internal.h @@ -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; diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 1c7bb033d3..2801ebdcbe 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -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); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index e895b7818a..1b07f528f2 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -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);