diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-04-05 15:57:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-04-12 15:14:21 +0200 |
commit | 8531631763b37cd158e6d417e051c8a110223e0f (patch) | |
tree | 68abcb974e7e1caca444cb18c4f5473a3cd82d5f /src | |
parent | a3861b4726cce668acf36d9dfcd23a2b03fc7255 (diff) | |
download | systemd-8531631763b37cd158e6d417e051c8a110223e0f.tar.gz |
varlink: get rid of "reply" field
So far, if we do a synchronous varlink call from the client side via
varlink_call(), we'll
move the returned json object from "v->current" into "v->reply", and
keep it referenced there until the next call. We then return a pointer
to it. This ensures that the json object remains valid between two
varlink_call() invocations.
But the thing is, we don't need a separate field for that, we can just
leave the data in "v->current". This means VARLINK_IDLE_CLIENT state
will be permitted with and without v->current initialized. Initially,
after connection setup it will be set to NULL, but after the first
varlink_call() it will be set to the most recent response, pinning it
into memory.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/varlink.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 8244f599a9..fe1cfeb0a1 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -128,7 +128,6 @@ struct Varlink { VarlinkReply reply_callback; JsonVariant *current; - JsonVariant *reply; struct ucred ucred; bool ucred_acquired:1; @@ -372,7 +371,6 @@ static void varlink_clear(Varlink *v) { v->output_buffer = mfree(v->output_buffer); v->current = json_variant_unref(v->current); - v->reply = json_variant_unref(v->reply); v->event = sd_event_unref(v->event); } @@ -1478,6 +1476,8 @@ int varlink_call( assert(v->n_pending == 0); /* n_pending can't be > 0 if we are in VARLINK_IDLE_CLIENT state */ + v->current = json_variant_unref(v->current); + r = varlink_sanitize_parameters(¶meters); if (r < 0) return varlink_log_errno(v, r, "Failed to sanitize parameters: %m"); @@ -1514,17 +1514,14 @@ int varlink_call( case VARLINK_CALLED: assert(v->current); - json_variant_unref(v->reply); - v->reply = TAKE_PTR(v->current); - varlink_set_state(v, VARLINK_IDLE_CLIENT); assert(v->n_pending == 1); v->n_pending--; if (ret_parameters) - *ret_parameters = json_variant_by_key(v->reply, "parameters"); + *ret_parameters = json_variant_by_key(v->current, "parameters"); if (ret_error_id) - *ret_error_id = json_variant_string(json_variant_by_key(v->reply, "error")); + *ret_error_id = json_variant_string(json_variant_by_key(v->current, "error")); if (ret_flags) *ret_flags = 0; |