mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-11 15:40:17 +01:00
cli: return sane error message for D-Bus policy permission errors
The error returned to users when a load_connection(s)/set_logging call
fails due to D-Bus policy denial is a bit obscure:
$ nmcli general logging level debug
Error: failed to set logging: Rejected send message, 4 matched rules;
type="method_call", sender=":1.233" (uid=1001 pid=27225 comm="nmcli
general logging level debug ")
interface="org.freedesktop.NetworkManager" member="SetLogging" error
name="(unset)" requested_reply="0" destination=":1.207" (uid=0
pid=25793 comm="/usr/sbin/NetworkManager --no-daemon ")
Convert it to a more comprehensible:
$ nmcli general logging level debug
Error: failed to set logging: access denied
https://bugzilla.redhat.com/show_bug.cgi?id=1362542
(cherry picked from commit 805925f9ef)
This commit is contained in:
parent
a77ed0de97
commit
e9f96024ae
4 changed files with 21 additions and 3 deletions
|
|
@ -1512,3 +1512,19 @@ nmc_complete_bool (const char *prefix)
|
|||
nmc_complete_strings (prefix, "true", "yes", "on",
|
||||
"false", "no", "off", NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* nmc_error_get_simple_message:
|
||||
* @error: a GError
|
||||
*
|
||||
* Returns a simplified message for some errors hard to understand.
|
||||
*/
|
||||
const char *
|
||||
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");
|
||||
else
|
||||
return error->message;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,8 @@ void nmc_complete_strings (const char *prefix, ...) G_GNUC_NULL_TERMINATED;
|
|||
|
||||
void nmc_complete_bool (const char *prefix);
|
||||
|
||||
const char *nmc_error_get_simple_message (GError *error);
|
||||
|
||||
extern NmcOutputField nmc_fields_ip4_config[];
|
||||
extern NmcOutputField nmc_fields_dhcp4_config[];
|
||||
extern NmcOutputField nmc_fields_ip6_config[];
|
||||
|
|
|
|||
|
|
@ -8336,7 +8336,7 @@ do_connection_reload (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (!nm_client_reload_connections (nmc->client, NULL, &error)) {
|
||||
g_string_printf (nmc->return_text, _("Error: failed to reload connections: %s."),
|
||||
error->message);
|
||||
nmc_error_get_simple_message (error));
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
|
@ -8368,7 +8368,7 @@ do_connection_load (NmCli *nmc, int argc, char **argv)
|
|||
g_free (filenames);
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: failed to load connection: %s."),
|
||||
error->message);
|
||||
nmc_error_get_simple_message (error));
|
||||
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
||||
g_error_free (error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -622,7 +622,7 @@ do_general_logging (NmCli *nmc, int argc, char **argv)
|
|||
nm_client_set_logging (nmc->client, level, domains, &error);
|
||||
if (error) {
|
||||
g_string_printf (nmc->return_text, _("Error: failed to set logging: %s"),
|
||||
error->message);
|
||||
nmc_error_get_simple_message (error));
|
||||
return NMC_RESULT_ERROR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue