1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00

varlink: automatically send ExpectedMore error message back when we were called without more=true set, but need it

Various Varlink calls only make sense if they are called with more=true
(i.e. in a mode where multiple replies are expected to be sent). If a
method call assumes it is called with more (manifested in the fact it
calls varlink_notify(), the call to reply to such messages) let's return
a recognizable error code for the violated expectation.

This adds a new error for this, org.varlink.service.ExpectedMore. Note
we are squatting the official org.varlink.service namespace, but for
such a basic thing it makes sense to add it there.
This commit is contained in:
Lennart Poettering 2023-10-11 16:51:30 +02:00
parent 4f10005e17
commit 47c9bbb1ab
3 changed files with 11 additions and 1 deletions

View File

@ -32,6 +32,8 @@ static VARLINK_DEFINE_ERROR(
static VARLINK_DEFINE_ERROR(PermissionDenied);
static VARLINK_DEFINE_ERROR(ExpectedMore);
/* As per https://varlink.org/Service */
VARLINK_DEFINE_INTERFACE(
org_varlink_service,
@ -42,4 +44,5 @@ VARLINK_DEFINE_INTERFACE(
&vl_error_MethodNotFound,
&vl_error_MethodNotImplemented,
&vl_error_InvalidParameter,
&vl_error_PermissionDenied);
&vl_error_PermissionDenied,
&vl_error_ExpectedMore);

View File

@ -2275,6 +2275,12 @@ int varlink_notify(Varlink *v, JsonVariant *parameters) {
if (v->state == VARLINK_DISCONNECTED)
return varlink_log_errno(v, SYNTHETIC_ERRNO(ENOTCONN), "Not connected.");
/* If we want to reply with a notify connection but the caller didn't set "more", then return an
* error indicating that we expected to be called with "more" set */
if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PENDING_METHOD))
return varlink_error(v, VARLINK_ERROR_EXPECTED_MORE, NULL);
if (!IN_SET(v->state, VARLINK_PROCESSING_METHOD_MORE, VARLINK_PENDING_METHOD_MORE))
return varlink_log_errno(v, SYNTHETIC_ERRNO(EBUSY), "Connection busy.");

View File

@ -214,3 +214,4 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServer *, varlink_server_unref);
/* These are errors we came up with and squatted the namespace with */
#define VARLINK_ERROR_PERMISSION_DENIED "org.varlink.service.PermissionDenied"
#define VARLINK_ERROR_EXPECTED_MORE "org.varlink.service.ExpectedMore"