From: Christian Brauner Date: Tue, 21 Apr 2026 22:20:24 +0000 (+0200) Subject: vmspawn-varlink: extract notify_event_subscribers from on_qmp_event X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b3a9f20a6992c6f048154a6d8ca3f1db0481eb8;p=thirdparty%2Fsystemd.git vmspawn-varlink: extract notify_event_subscribers from on_qmp_event Pure refactor: factor the subscriber-notification body out of on_qmp_event into a static helper. on_qmp_event keeps the JOB_STATUS_CHANGE short-circuit and otherwise delegates to the new helper. No behaviour change. Signed-off-by: Christian Brauner (Amutable) --- diff --git a/src/vmspawn/vmspawn-varlink.c b/src/vmspawn/vmspawn-varlink.c index 94198923e01..d9beb5bfe3f 100644 --- a/src/vmspawn/vmspawn-varlink.c +++ b/src/vmspawn/vmspawn-varlink.c @@ -263,31 +263,21 @@ static int dispatch_pending_job(VmspawnQmpBridge *bridge, sd_json_variant *data) return 1; } -static int on_qmp_event( - QmpClient *client, - const char *event, - sd_json_variant *data, - void *userdata) { - - VmspawnVarlinkContext *ctx = ASSERT_PTR(userdata); +static int notify_event_subscribers(VmspawnVarlinkContext *ctx, const char *event_name, sd_json_variant *data) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *notification = NULL; sd_varlink *link; char **filter; int r; - assert(client); - assert(event); - - /* Dispatch job status changes to pending continuations (e.g. blockdev-create) */ - if (streq(event, "JOB_STATUS_CHANGE")) - return dispatch_pending_job(ctx->bridge, data); + assert(ctx); + assert(event_name); if (hashmap_isempty(ctx->subscribed)) return 0; r = sd_json_buildo( ¬ification, - SD_JSON_BUILD_PAIR_STRING("event", event), + SD_JSON_BUILD_PAIR_STRING("event", event_name), SD_JSON_BUILD_PAIR_CONDITION(!!data, "data", SD_JSON_BUILD_VARIANT(data))); if (r < 0) { log_warning_errno(r, "Failed to build event notification, ignoring: %m"); @@ -295,7 +285,7 @@ static int on_qmp_event( } HASHMAP_FOREACH_KEY(filter, link, ctx->subscribed) { - if (filter && !strv_contains(filter, event)) + if (filter && !strv_contains(filter, event_name)) continue; r = sd_varlink_notify(link, notification); @@ -306,6 +296,24 @@ static int on_qmp_event( return 0; } +static int on_qmp_event( + QmpClient *client, + const char *event, + sd_json_variant *data, + void *userdata) { + + VmspawnVarlinkContext *ctx = ASSERT_PTR(userdata); + + assert(client); + assert(event); + + /* Dispatch job status changes to pending continuations (e.g. blockdev-create) */ + if (streq(event, "JOB_STATUS_CHANGE")) + return dispatch_pending_job(ctx->bridge, data); + + return notify_event_subscribers(ctx, event, data); +} + /* Free all subscriber entries — varlink_subscriber_hash_ops handles * close + unref for each key and strv_free for each value. */ static void drain_event_subscribers(Hashmap **subscribed) {