summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/journal/journalctl.c11
-rw-r--r--src/network/networkctl.c4
-rw-r--r--src/resolve/resolvectl.c16
-rw-r--r--src/shared/varlink.c49
-rw-r--r--src/shared/varlink.h3
-rw-r--r--src/varlinkctl/varlinkctl.c18
6 files changed, 72 insertions, 29 deletions
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 817b563bbd..58c7993d0b 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -1917,7 +1917,7 @@ static int verify(sd_journal *j, bool verbose) {
static int simple_varlink_call(const char *option, const char *method) {
_cleanup_(varlink_flush_close_unrefp) Varlink *link = NULL;
- const char *error, *fn;
+ const char *fn;
int r;
if (arg_machine)
@@ -1934,14 +1934,7 @@ static int simple_varlink_call(const char *option, const char *method) {
(void) varlink_set_description(link, "journal");
(void) varlink_set_relative_timeout(link, USEC_INFINITY);
- r = varlink_call(link, method, /* parameters= */ NULL, /* ret_parameters= */ NULL, &error);
- if (r < 0)
- return log_error_errno(r, "Failed to execute varlink call: %m");
- if (error)
- return log_error_errno(SYNTHETIC_ERRNO(ENOANO),
- "Failed to execute varlink call: %s", error);
-
- return 0;
+ return varlink_call_and_log(link, method, /* parameters= */ NULL, /* ret_parameters= */ NULL);
}
static int flush_to_var(void) {
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index 41b35accf8..6f5100c605 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -104,9 +104,9 @@ static int check_netns_match(void) {
if (r < 0)
return log_error_errno(r, "Failed to connect to network service /run/systemd/netif/io.systemd.Network: %m");
- r = varlink_call(vl, "io.systemd.Network.GetNamespaceId", /* parameters= */ NULL, &reply, /* ret_error_id= */ NULL);
+ r = varlink_call_and_log(vl, "io.systemd.Network.GetNamespaceId", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue GetNamespaceId() varlink call: %m");
+ return r;
static const JsonDispatch dispatch_table[] = {
{ "NamespaceId", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, 0, JSON_MANDATORY },
diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c
index 811e0118e9..fcc8eb7bdc 100644
--- a/src/resolve/resolvectl.c
+++ b/src/resolve/resolvectl.c
@@ -1080,9 +1080,9 @@ static int show_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m");
- r = varlink_call(vl, "io.systemd.Resolve.Monitor.DumpStatistics", /* parameters= */ NULL, &reply, /* ret_error_id= */ NULL);
+ r = varlink_call_and_log(vl, "io.systemd.Resolve.Monitor.DumpStatistics", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue DumpStatistics() varlink call: %m");
+ return r;
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
return json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
@@ -1238,9 +1238,9 @@ static int reset_statistics(int argc, char **argv, void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m");
- r = varlink_call(vl, "io.systemd.Resolve.Monitor.ResetStatistics", /* parameters= */ NULL, &reply, /* ret_error_id= */ NULL);
+ r = varlink_call_and_log(vl, "io.systemd.Resolve.Monitor.ResetStatistics", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue ResetStatistics() varlink call: %m");
+ return r;
if (!FLAGS_SET(arg_json_format_flags, JSON_FORMAT_OFF))
return json_variant_dump(reply, arg_json_format_flags, NULL, NULL);
@@ -2972,9 +2972,9 @@ static int verb_show_cache(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m");
- r = varlink_call(vl, "io.systemd.Resolve.Monitor.DumpCache", /* parameters= */ NULL, &reply, /* ret_error_id= */ NULL);
+ r = varlink_call_and_log(vl, "io.systemd.Resolve.Monitor.DumpCache", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue DumpCache() varlink call: %m");
+ return r;
d = json_variant_by_key(reply, "dump");
if (!d)
@@ -3146,9 +3146,9 @@ static int verb_show_server_state(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to connect to query monitoring service /run/systemd/resolve/io.systemd.Resolve.Monitor: %m");
- r = varlink_call(vl, "io.systemd.Resolve.Monitor.DumpServerState", /* parameters= */ NULL, &reply, /* ret_error_id= */ NULL);
+ r = varlink_call_and_log(vl, "io.systemd.Resolve.Monitor.DumpServerState", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue DumpServerState() varlink call: %m");
+ return r;
d = json_variant_by_key(reply, "dump");
if (!d)
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
index 55e3560aea..3bce80e202 100644
--- a/src/shared/varlink.c
+++ b/src/shared/varlink.c
@@ -2259,6 +2259,7 @@ int varlink_callb_ap(
int r;
assert_return(v, -EINVAL);
+ assert_return(method, -EINVAL);
r = json_buildv(&parameters, ap);
if (r < 0)
@@ -2267,6 +2268,54 @@ int varlink_callb_ap(
return varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, ret_flags);
}
+int varlink_call_and_log(
+ Varlink *v,
+ const char *method,
+ JsonVariant *parameters,
+ JsonVariant **ret_parameters) {
+
+ JsonVariant *reply = NULL;
+ const char *error_id = NULL;
+ int r;
+
+ assert_return(v, -EINVAL);
+ assert_return(method, -EINVAL);
+
+ r = varlink_call(v, method, parameters, &reply, &error_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to issue %s() varlink call: %m", method);
+ if (error_id)
+ return log_error_errno(varlink_error_to_errno(error_id, reply),
+ "Failed to issue %s() varlink call: %s", method, error_id);
+
+ if (ret_parameters)
+ *ret_parameters = TAKE_PTR(reply);
+
+ return 0;
+}
+
+int varlink_callb_and_log(
+ Varlink *v,
+ const char *method,
+ JsonVariant **ret_parameters,
+ ...) {
+
+ _cleanup_(json_variant_unrefp) JsonVariant *parameters = NULL;
+ va_list ap;
+ int r;
+
+ assert_return(v, -EINVAL);
+ assert_return(method, -EINVAL);
+
+ va_start(ap, ret_parameters);
+ r = json_buildv(&parameters, ap);
+ va_end(ap);
+ if (r < 0)
+ return log_error_errno(r, "Failed to build JSON message: %m");
+
+ return varlink_call_and_log(v, method, parameters, ret_parameters);
+}
+
static void varlink_collect_context_free(VarlinkCollectContext *cc) {
assert(cc);
diff --git a/src/shared/varlink.h b/src/shared/varlink.h
index a54b1f0381..622ab797c5 100644
--- a/src/shared/varlink.h
+++ b/src/shared/varlink.h
@@ -92,6 +92,8 @@ int varlink_call_full(Varlink *v, const char *method, JsonVariant *parameters, J
static inline int varlink_call(Varlink *v, const char *method, JsonVariant *parameters, JsonVariant **ret_parameters, const char **ret_error_id) {
return varlink_call_full(v, method, parameters, ret_parameters, ret_error_id, NULL);
}
+int varlink_call_and_log(Varlink *v, const char *method, JsonVariant *parameters, JsonVariant **ret_parameters);
+
int varlink_callb_ap(Varlink *v, const char *method, JsonVariant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags, va_list ap);
static inline int varlink_callb_full(Varlink *v, const char *method, JsonVariant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags, ...) {
va_list ap;
@@ -111,6 +113,7 @@ static inline int varlink_callb(Varlink *v, const char *method, JsonVariant **re
va_end(ap);
return r;
}
+int varlink_callb_and_log(Varlink *v, const char *method, JsonVariant **ret_parameters, ...);
/* Send method call and begin collecting all 'more' replies into an array, finishing when a final reply is sent */
int varlink_collect(Varlink *v, const char *method, JsonVariant *parameters, JsonVariant **ret_parameters, const char **ret_error_id, VarlinkReplyFlags *ret_flags);
diff --git a/src/varlinkctl/varlinkctl.c b/src/varlinkctl/varlinkctl.c
index 9c8a8d9710..8f3a88aba5 100644
--- a/src/varlinkctl/varlinkctl.c
+++ b/src/varlinkctl/varlinkctl.c
@@ -210,12 +210,9 @@ static int verb_info(int argc, char *argv[], void *userdata) {
return r;
JsonVariant *reply = NULL;
- const char *error = NULL;
- r = varlink_call(vl, "org.varlink.service.GetInfo", /* parameters= */ NULL, &reply, &error);
+ r = varlink_call_and_log(vl, "org.varlink.service.GetInfo", /* parameters= */ NULL, &reply);
if (r < 0)
- return log_error_errno(r, "Failed to issue GetInfo() call: %m");
- if (error)
- return log_error_errno(SYNTHETIC_ERRNO(EBADE), "Method call GetInfo() failed: %s", error);
+ return r;
pager_open(arg_pager_flags);
@@ -296,12 +293,13 @@ static int verb_introspect(int argc, char *argv[], void *userdata) {
return r;
JsonVariant *reply = NULL;
- const char *error = NULL;
- r = varlink_callb(vl, "org.varlink.service.GetInterfaceDescription", &reply, &error, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("interface", interface)));
+ r = varlink_callb_and_log(
+ vl,
+ "org.varlink.service.GetInterfaceDescription",
+ &reply,
+ JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("interface", interface)));
if (r < 0)
- return log_error_errno(r, "Failed to issue GetInterfaceDescription() call: %m");
- if (error)
- return log_error_errno(SYNTHETIC_ERRNO(EBADE), "Method call GetInterfaceDescription() failed: %s", error);
+ return r;
pager_open(arg_pager_flags);