diff options
author | Thomas Haller <thaller@redhat.com> | 2020-03-14 08:43:01 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-03-23 09:33:52 +0100 |
commit | d99d1dc26525d86a6f0000505fbfd256908cf7a7 (patch) | |
tree | 2c88446bdf3f106ef13e38edc0b71203bcaab9ec | |
parent | 06da903bb6fd4e35d595c6230a8ecc2a8b7da107 (diff) | |
download | NetworkManager-d99d1dc26525d86a6f0000505fbfd256908cf7a7.tar.gz |
cli: replace deprecated and synchronous nm_client_set_logging()
This is more a showcase for using nm_client_dbus_call(), than a
real use.
In this case, nmcli was mostly fine to just invoke the synchronous API
and not care about the problems that it had.
Still, replace it, and show the suggested alternative.
-rw-r--r-- | clients/cli/general.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/clients/cli/general.c b/clients/cli/general.c index 53b5e6d40e..c083386a65 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -731,11 +731,26 @@ nmc_complete_strings_nocase (const char *prefix, ...) va_end (args); } -static NMCResultCode -do_general_logging (NmCli *nmc, int argc, char **argv) +static void +_set_logging_cb (GObject *object, GAsyncResult *result, gpointer user_data) { + NmCli *nmc = user_data; + gs_unref_variant GVariant *res = NULL; gs_free_error GError *error = NULL; + res = nm_client_dbus_call_finish (NM_CLIENT (object), result, &error); + if (!res) { + g_dbus_error_strip_remote_error (error); + g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"), + nmc_error_get_simple_message (error)); + nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; + } + quit (); +} + +static NMCResultCode +do_general_logging (NmCli *nmc, int argc, char **argv) +{ next_arg (nmc, &argc, &argv, NULL); if (argc == 0) { if (nmc->complete) @@ -789,12 +804,19 @@ do_general_logging (NmCli *nmc, int argc, char **argv) if (nmc->complete) return nmc->return_value; - nm_client_set_logging (nmc->client, level, domains, &error); - if (error) { - g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"), - nmc_error_get_simple_message (error)); - return NMC_RESULT_ERROR_UNKNOWN; - } + nmc->should_wait++; + nm_client_dbus_call (nmc->client, + NM_DBUS_PATH, + NM_DBUS_INTERFACE, + "SetLogging", + g_variant_new ("(ss)", + level ?: "", + domains ?: ""), + G_VARIANT_TYPE ("()"), + -1, + NULL, + _set_logging_cb, + nmc); } return nmc->return_value; |