+ scope = t->scope;
+ state = DNS_TRANSACTION_SUCCESS;
+ continue;
+ }
+
+ /* One of the transactions has failed, let's see
+ * whether we find anything better, but if not, return
+ * its response data */
+ if (state != DNS_TRANSACTION_SUCCESS && t->state == DNS_TRANSACTION_FAILURE) {
+ DnsAnswer *a;
+
+ if (t->received) {
+ rcode = DNS_PACKET_RCODE(t->received);
+ a = t->received->answer;
+ } else {
+ rcode = t->cached_rcode;
+ a = t->cached;
+ }
+
+ dns_answer_unref(answer);
+ answer = dns_answer_ref(a);
+
+ scope = t->scope;
+ state = DNS_TRANSACTION_FAILURE;
+ continue;
+ }
+
+ if (state == DNS_TRANSACTION_NO_SERVERS && t->state != DNS_TRANSACTION_NO_SERVERS)
+ state = t->state;
+ }
+
+ if (pending) {
+
+ /* If so far we weren't successful, and there's
+ * something still pending, then wait for it */
+ if (state != DNS_TRANSACTION_SUCCESS)
+ return;
+
+ /* If we already were successful, then only wait for
+ * other transactions on the same scope to finish. */
+ SET_FOREACH(t, q->transactions, i) {
+ if (t->scope == scope && IN_SET(t->state, DNS_TRANSACTION_PENDING, DNS_TRANSACTION_NULL))
+ return;
+ }
+ }
+
+ if (IN_SET(state, DNS_TRANSACTION_SUCCESS, DNS_TRANSACTION_FAILURE)) {
+ q->answer = dns_answer_ref(answer);
+ q->answer_rcode = rcode;
+ q->answer_ifindex = (scope && scope->link) ? scope->link->ifindex : 0;
+ q->answer_protocol = scope ? scope->protocol : _DNS_PROTOCOL_INVALID;
+ q->answer_family = scope ? scope->family : AF_UNSPEC;
+ }
+
+ dns_query_complete(q, state);