Skip to content

Commit

Permalink
bus-polkit: avoid duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
dtardon committed Feb 22, 2023
1 parent 6ba12c9 commit 225fb0e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/shared/bus-polkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ typedef struct AsyncPolkitQuery {
char *action;
char **details;

sd_bus_message *request, *reply;
sd_bus_message *reply;
sd_bus_slot *slot;

sd_event_source *defer_event_source;
Expand Down Expand Up @@ -231,8 +231,6 @@ static AsyncPolkitQuery *async_polkit_query_free(AsyncPolkitQuery *q) {
assert(!q->parent);

sd_bus_slot_unref(q->slot);

sd_bus_message_unref(q->request);
sd_bus_message_unref(q->reply);

free(q->action);
Expand Down Expand Up @@ -263,7 +261,6 @@ static int async_polkit_queries_create_query(
return -ENOMEM;

*q = (AsyncPolkitQuery) {
.request = sd_bus_message_ref(request),
.parent = parent,
};

Expand Down Expand Up @@ -301,6 +298,8 @@ static int async_polkit_callback(sd_bus_message *reply, void *userdata, sd_bus_e

assert(reply);

assert(q->parent);

assert(q->slot);
q->slot = sd_bus_slot_unref(q->slot);

Expand All @@ -327,25 +326,24 @@ static int async_polkit_callback(sd_bus_message *reply, void *userdata, sd_bus_e
if (r < 0)
goto fail;

r = sd_bus_message_rewind(q->request, true);
r = sd_bus_message_rewind(q->parent->request, true);
if (r < 0)
goto fail;

assert(q->parent);
assert(q->parent->items); /* There must be at least one query on the list */
LIST_FOREACH(item, i, q->parent->items)
if (i != q)
sd_bus_message_rewind(i->reply, true);

r = sd_bus_enqueue_for_read(sd_bus_message_get_bus(q->request), q->request);
r = sd_bus_enqueue_for_read(sd_bus_message_get_bus(q->parent->request), q->parent->request);
if (r < 0)
goto fail;

return 1;

fail:
log_debug_errno(r, "Processing asynchronous PolicyKit reply failed, ignoring: %m");
(void) sd_bus_reply_method_errno(q->request, r, NULL);
(void) sd_bus_reply_method_errno(q->parent->request, r, NULL);
async_polkit_queries_unref(q->parent);
return r;
}
Expand Down

0 comments on commit 225fb0e

Please sign in to comment.