From: Ivan Kruglov Date: Wed, 16 Jul 2025 14:03:49 +0000 (-0700) Subject: core: io.systemd.Unit.List can lookup by InvocationID X-Git-Tag: v259-rc1~276^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c2c2e059829148e8e10a71b948a84c8080a06b1;p=thirdparty%2Fsystemd.git core: io.systemd.Unit.List can lookup by InvocationID --- diff --git a/src/core/varlink-unit.c b/src/core/varlink-unit.c index 5a88bb38402..f71c3d7e33e 100644 --- a/src/core/varlink-unit.c +++ b/src/core/varlink-unit.c @@ -359,6 +359,7 @@ static int lookup_unit_by_pidref(sd_varlink *link, Manager *manager, PidRef *pid typedef struct UnitLookupParameters { const char *name, *cgroup; PidRef pidref; + sd_id128_t invocation_id; } UnitLookupParameters; static void unit_lookup_parameters_done(UnitLookupParameters *p) { @@ -376,10 +377,11 @@ static int varlink_error_no_such_unit(sd_varlink *v, const char *name) { static int varlink_error_conflict_lookup_parameters(sd_varlink *v, const UnitLookupParameters *p) { log_debug_errno( ESRCH, - "Searching unit by lookup parameters name='%s' pid="PID_FMT" cgroup='%s' resulted in multiple different units", + "Searching unit by lookup parameters name='%s' pid="PID_FMT" cgroup='%s' invocationID='%s' resulted in multiple different units", p->name, p->pidref.pid, - p->cgroup); + p->cgroup, + sd_id128_is_null(p->invocation_id) ? "" : SD_ID128_TO_UUID_STRING(p->invocation_id)); return varlink_error_no_such_unit(v, /* name= */ NULL); } @@ -428,6 +430,16 @@ static int lookup_unit_by_parameters(sd_varlink *link, Manager *manager, UnitLoo unit = cgroup_unit; } + if (!sd_id128_is_null(p->invocation_id)) { + Unit *id128_unit = hashmap_get(manager->units_by_invocation_id, &p->invocation_id); + if (!id128_unit) + return varlink_error_no_such_unit(link, "invocationID"); + if (id128_unit != unit && unit != NULL) + return varlink_error_conflict_lookup_parameters(link, p); + + unit = id128_unit; + } + *ret_unit = unit; return 0; } @@ -437,6 +449,7 @@ int vl_method_list_units(sd_varlink *link, sd_json_variant *parameters, sd_varli { "name", SD_JSON_VARIANT_STRING, json_dispatch_const_unit_name, offsetof(UnitLookupParameters, name), 0 /* allows UNIT_NAME_PLAIN | UNIT_NAME_INSTANCE */ }, { "pid", _SD_JSON_VARIANT_TYPE_INVALID, json_dispatch_pidref, offsetof(UnitLookupParameters, pidref), SD_JSON_RELAX /* allows PID_AUTOMATIC */ }, { "cgroup", SD_JSON_VARIANT_STRING, json_dispatch_const_path, offsetof(UnitLookupParameters, cgroup), SD_JSON_STRICT /* require normalized path */ }, + { "invocationID", SD_JSON_VARIANT_STRING, sd_json_dispatch_id128, offsetof(UnitLookupParameters, invocation_id), 0 }, {} }; diff --git a/src/shared/varlink-io.systemd.Unit.c b/src/shared/varlink-io.systemd.Unit.c index b4c7e22b382..eacc9607926 100644 --- a/src/shared/varlink-io.systemd.Unit.c +++ b/src/shared/varlink-io.systemd.Unit.c @@ -1019,6 +1019,8 @@ static SD_VARLINK_DEFINE_METHOD_FULL( SD_VARLINK_DEFINE_INPUT_BY_TYPE(pid, ProcessId, SD_VARLINK_NULLABLE), SD_VARLINK_FIELD_COMMENT("If non-null the cgroup of a unit"), SD_VARLINK_DEFINE_INPUT(cgroup, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), + SD_VARLINK_FIELD_COMMENT("If non-null the invocation ID of a unit"), + SD_VARLINK_DEFINE_INPUT(invocationID, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), SD_VARLINK_FIELD_COMMENT("Configuration of the unit"), SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(context, UnitContext, 0), SD_VARLINK_FIELD_COMMENT("Runtime information of the unit"),