summaryrefslogtreecommitdiffstats
path: root/src/libsystemd
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-10-30 15:30:16 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-31 01:50:50 +0100
commit76a3af06308480600f354f8ea6dcd62587555a0c (patch)
tree040e7ab27e52ec1f22f94113ec8a41320f92db81 /src/libsystemd
parentsd-varlink: don't show error code we already decoded as part of the log message (diff)
downloadsystemd-76a3af06308480600f354f8ea6dcd62587555a0c.tar.xz
systemd-76a3af06308480600f354f8ea6dcd62587555a0c.zip
sd-varlink: add helper VARLINK_STATE_WANTS_REPLY()
Let's add a helper that detects whether we still need to reply to a state. This should make the logic easier to follow.
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-varlink/sd-varlink.c9
-rw-r--r--src/libsystemd/sd-varlink/varlink-internal.h7
2 files changed, 12 insertions, 4 deletions
diff --git a/src/libsystemd/sd-varlink/sd-varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c
index 31ce6710c6..a1b3648266 100644
--- a/src/libsystemd/sd-varlink/sd-varlink.c
+++ b/src/libsystemd/sd-varlink/sd-varlink.c
@@ -1369,7 +1369,7 @@ static int varlink_dispatch_method(sd_varlink *v) {
varlink_log_errno(v, r, "Parameters for method %s() didn't pass validation on field '%s': %m",
method, strna(bad_field));
- if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) {
+ if (VARLINK_STATE_WANTS_REPLY(v->state)) {
r = sd_varlink_error_invalid_parameter_name(v, bad_field);
if (r < 0)
goto fail;
@@ -1384,15 +1384,16 @@ static int varlink_dispatch_method(sd_varlink *v) {
if (r < 0) {
varlink_log_errno(v, r, "Callback for %s returned error: %m", method);
- /* We got an error back from the callback. Propagate it to the client if the method call remains unanswered. */
- if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) {
+ /* We got an error back from the callback. Propagate it to the client if the
+ * method call remains unanswered. */
+ if (VARLINK_STATE_WANTS_REPLY(v->state)) {
r = sd_varlink_error_errno(v, r);
if (r < 0)
goto fail;
}
}
}
- } else if (IN_SET(v->state, VARLINK_PROCESSING_METHOD, VARLINK_PROCESSING_METHOD_MORE)) {
+ } else if (VARLINK_STATE_WANTS_REPLY(v->state)) {
r = sd_varlink_errorbo(v, SD_VARLINK_ERROR_METHOD_NOT_FOUND, SD_JSON_BUILD_PAIR("method", SD_JSON_BUILD_STRING(method)));
if (r < 0)
goto fail;
diff --git a/src/libsystemd/sd-varlink/varlink-internal.h b/src/libsystemd/sd-varlink/varlink-internal.h
index 5469d9e345..b184ac7754 100644
--- a/src/libsystemd/sd-varlink/varlink-internal.h
+++ b/src/libsystemd/sd-varlink/varlink-internal.h
@@ -63,6 +63,13 @@ typedef enum VarlinkState {
VARLINK_PENDING_METHOD, \
VARLINK_PENDING_METHOD_MORE)
+/* Tests whether we are expected to generate a method call reply, i.e. are processing a method call, except
+ * one with the ONEWAY flag set. */
+#define VARLINK_STATE_WANTS_REPLY(state) \
+ IN_SET(state, \
+ VARLINK_PROCESSING_METHOD, \
+ VARLINK_PROCESSING_METHOD_MORE)
+
typedef struct VarlinkJsonQueueItem VarlinkJsonQueueItem;
/* A queued message we shall write into the socket, along with the file descriptors to send at the same