diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-29 09:33:27 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-25 09:49:26 +0200 |
commit | 05f47839e1feca299191aaa1251c041d61ada1fc (patch) | |
tree | 8eba9406ddaf73eb8ad9c493605b5f32307f9ed6 /src/resolve | |
parent | Merge pull request #33461 from poettering/boot-measured-flag-rework (diff) | |
download | systemd-05f47839e1feca299191aaa1251c041d61ada1fc.tar.xz systemd-05f47839e1feca299191aaa1251c041d61ada1fc.zip |
varlink: add varlink_many_*() helpers that send messages to a set of connections at once
If we have a Varlink interface that allows man subscribers to the same
source of events we typically want to notify all of them at once with
the same message.
Let's add some helpers for this purpose: varlink_many_*() can be used to
send messages, similar to the corresponding varlink_*() calls, but they
take a Set of Varlink objects and we issue the operation on every
connection once.
This ports over one existing case where this is beneficial, but the main
user for this is supposed to be importd later.
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-manager.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 2eee418adf..9bbdc648fc 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -1165,7 +1165,6 @@ static int dns_question_to_json(DnsQuestion *q, sd_json_variant **ret) { int manager_monitor_send(Manager *m, DnsQuery *q) { _cleanup_(sd_json_variant_unrefp) sd_json_variant *jquestion = NULL, *jcollected_questions = NULL, *janswer = NULL; _cleanup_(dns_question_unrefp) DnsQuestion *merged = NULL; - Varlink *connection; DnsAnswerItem *rri; int r; @@ -1220,34 +1219,32 @@ int manager_monitor_send(Manager *m, DnsQuery *q) { return log_debug_errno(r, "Failed to append notification entry to array: %m"); } - SET_FOREACH(connection, m->varlink_subscription) { - r = varlink_notifybo( - connection, - SD_JSON_BUILD_PAIR("state", SD_JSON_BUILD_STRING(dns_transaction_state_to_string(q->state))), - SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_DNSSEC_FAILED, - "result", SD_JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))), - SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_RCODE_FAILURE, - "rcode", SD_JSON_BUILD_INTEGER(q->answer_rcode)), - SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_ERRNO, - "errno", SD_JSON_BUILD_INTEGER(q->answer_errno)), - SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state, - DNS_TRANSACTION_DNSSEC_FAILED, - DNS_TRANSACTION_RCODE_FAILURE) && - q->answer_ede_rcode >= 0, - "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)), - SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state, - DNS_TRANSACTION_DNSSEC_FAILED, - DNS_TRANSACTION_RCODE_FAILURE) && - q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg), - "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg)), - SD_JSON_BUILD_PAIR("question", SD_JSON_BUILD_VARIANT(jquestion)), - SD_JSON_BUILD_PAIR_CONDITION(!!jcollected_questions, - "collectedQuestions", SD_JSON_BUILD_VARIANT(jcollected_questions)), - SD_JSON_BUILD_PAIR_CONDITION(!!janswer, + r = varlink_many_notifybo( + m->varlink_subscription, + SD_JSON_BUILD_PAIR("state", SD_JSON_BUILD_STRING(dns_transaction_state_to_string(q->state))), + SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_DNSSEC_FAILED, + "result", SD_JSON_BUILD_STRING(dnssec_result_to_string(q->answer_dnssec_result))), + SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_RCODE_FAILURE, + "rcode", SD_JSON_BUILD_INTEGER(q->answer_rcode)), + SD_JSON_BUILD_PAIR_CONDITION(q->state == DNS_TRANSACTION_ERRNO, + "errno", SD_JSON_BUILD_INTEGER(q->answer_errno)), + SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state, + DNS_TRANSACTION_DNSSEC_FAILED, + DNS_TRANSACTION_RCODE_FAILURE) && + q->answer_ede_rcode >= 0, + "extendedDNSErrorCode", SD_JSON_BUILD_INTEGER(q->answer_ede_rcode)), + SD_JSON_BUILD_PAIR_CONDITION(IN_SET(q->state, + DNS_TRANSACTION_DNSSEC_FAILED, + DNS_TRANSACTION_RCODE_FAILURE) && + q->answer_ede_rcode >= 0 && !isempty(q->answer_ede_msg), + "extendedDNSErrorMessage", SD_JSON_BUILD_STRING(q->answer_ede_msg)), + SD_JSON_BUILD_PAIR("question", SD_JSON_BUILD_VARIANT(jquestion)), + SD_JSON_BUILD_PAIR_CONDITION(!!jcollected_questions, + "collectedQuestions", SD_JSON_BUILD_VARIANT(jcollected_questions)), + SD_JSON_BUILD_PAIR_CONDITION(!!janswer, "answer", SD_JSON_BUILD_VARIANT(janswer))); - if (r < 0) - log_debug_errno(r, "Failed to send monitor event, ignoring: %m"); - } + if (r < 0) + log_debug_errno(r, "Failed to send monitor event, ignoring: %m"); return 0; } |