mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 14:10:36 +01:00
cli: don't create a NMClient for the 'connection reload' command
It is a waste of resources instantiating a NMClient, filling the object cache and then throwing everything away without using it. This can take seconds on slow systems with many objects. Since the ReloadConnections doesn't need anything from the cache, just execute the D-Bus method call directly.
This commit is contained in:
parent
07e838567e
commit
fd8d5a0c7a
3 changed files with 65 additions and 4 deletions
|
|
@ -1421,10 +1421,56 @@ nmc_error_get_simple_message (GError *error)
|
|||
/* Return a clear message instead of the obscure D-Bus policy error */
|
||||
if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED))
|
||||
return _("access denied");
|
||||
if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
|
||||
return _("NetworkManager is not running");
|
||||
else
|
||||
return error->message;
|
||||
}
|
||||
|
||||
GVariant *
|
||||
nmc_dbus_call_sync (NmCli *nmc,
|
||||
const char *object_path,
|
||||
const char *interface_name,
|
||||
const char *method_name,
|
||||
GVariant *parameters,
|
||||
const GVariantType *reply_type,
|
||||
GError **error)
|
||||
{
|
||||
gs_unref_object GDBusConnection *connection = NULL;
|
||||
gs_free_error GError *local = NULL;
|
||||
GVariant *result;
|
||||
|
||||
if (nmc->timeout == -1)
|
||||
nmc->timeout = 90;
|
||||
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &local);
|
||||
if (!connection) {
|
||||
g_set_error (error,
|
||||
NMCLI_ERROR,
|
||||
NMC_RESULT_ERROR_UNKNOWN,
|
||||
_("Error: error connecting to system bus: %s"),
|
||||
local->message);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = g_dbus_connection_call_sync (connection,
|
||||
"org.freedesktop.NetworkManager",
|
||||
object_path,
|
||||
interface_name,
|
||||
method_name,
|
||||
parameters,
|
||||
reply_type,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
nmc->timeout * 1000,
|
||||
NULL,
|
||||
error);
|
||||
|
||||
if (error && *error)
|
||||
g_dbus_error_strip_remote_error (*error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NM_UTILS_LOOKUP_STR_DEFINE (nm_connectivity_to_string, NMConnectivityState,
|
||||
|
|
|
|||
|
|
@ -89,4 +89,12 @@ extern const NmcMetaGenericInfo *const metagen_dhcp_config[];
|
|||
|
||||
const char *nm_connectivity_to_string (NMConnectivityState connectivity);
|
||||
|
||||
GVariant *nmc_dbus_call_sync (NmCli *nmc,
|
||||
const char *object_path,
|
||||
const char *interface_name,
|
||||
const char *method_name,
|
||||
GVariant *parameters,
|
||||
const GVariantType *reply_type,
|
||||
GError **error);
|
||||
|
||||
#endif /* NMC_COMMON_H */
|
||||
|
|
|
|||
|
|
@ -8845,17 +8845,24 @@ do_connection_monitor (NmCli *nmc, int argc, char **argv)
|
|||
static NMCResultCode
|
||||
do_connection_reload (NmCli *nmc, int argc, char **argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gs_unref_variant GVariant *result = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
next_arg (nmc, &argc, &argv, NULL);
|
||||
if (nmc->complete)
|
||||
return nmc->return_value;
|
||||
|
||||
if (!nm_client_reload_connections (nmc->client, NULL, &error)) {
|
||||
result = nmc_dbus_call_sync (nmc,
|
||||
"/org/freedesktop/NetworkManager/Settings",
|
||||
"org.freedesktop.NetworkManager.Settings",
|
||||
"ReloadConnections",
|
||||
g_variant_new ("()"),
|
||||
G_VARIANT_TYPE("(b)"),
|
||||
&error);
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: failed to reload connections: %s."),
|
||||
nmc_error_get_simple_message (error));
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
return nmc->return_value;
|
||||
|
|
@ -9245,7 +9252,7 @@ static const NMCCommand connection_cmds[] = {
|
|||
{ "add", do_connection_add, usage_connection_add, TRUE, TRUE },
|
||||
{ "edit", do_connection_edit, usage_connection_edit, TRUE, TRUE },
|
||||
{ "delete", do_connection_delete, usage_connection_delete, TRUE, TRUE },
|
||||
{ "reload", do_connection_reload, usage_connection_reload, TRUE, TRUE },
|
||||
{ "reload", do_connection_reload, usage_connection_reload, FALSE, FALSE },
|
||||
{ "load", do_connection_load, usage_connection_load, TRUE, TRUE },
|
||||
{ "modify", do_connection_modify, usage_connection_modify, TRUE, TRUE },
|
||||
{ "clone", do_connection_clone, usage_connection_clone, TRUE, TRUE },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue