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.
This commit is contained in:
committed by
Yu Watanabe
parent
aa5e67ae6f
commit
76a3af0630
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user