]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: automatically send ExpectedMore error message back when we were called witho...
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Oct 2023 14:51:30 +0000 (16:51 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Oct 2023 16:19:36 +0000 (18:19 +0200)
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.

src/shared/varlink-org.varlink.service.c
src/shared/varlink.c
src/shared/varlink.h

index 52ba99dd2bdfce96ec32df26e288d50e3037b5cc..36dc68fd262a7e18a1c77cdad8e1bcf6c06928a1 100644 (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);
index 121de882bbfa326ee30cefb97b1a356e05c5b0b3..8eeac4a49fdbddfd3ea6f9803b7bac2590c06df2 100644 (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.");
 
index 5fe529c8532786213c0ffa62e7f705dce9b1401c..e5541d3ce5f794173650935d6a496ef526e43633 100644 (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"