From b32e4c941a7525881599f6d419ddaafacd85b52c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Feb 2023 16:57:38 +0100 Subject: [PATCH] nmcli: replace all uses of g_print()/g_printerr() with nmc_print()/nmc_printerr() The main purpose is to simplify printf debugging and manual testing. We can now trivially patch the code so that all output from nmcli gets (additionally) written to a file. That is useful when debugging a unit test in "test-client.py". Thereby we can duplicate all messages via nm_utils_print(), which is in sync with the debug messages from libnm and which honors LIBNM_CLIENT_DEBUG_FILE. --- src/nmcli/agent.c | 40 +- src/nmcli/common.c | 20 +- src/nmcli/connections.c | 1054 +++++++++++++++++++------------------- src/nmcli/devices.c | 269 +++++----- src/nmcli/general.c | 230 ++++----- src/nmcli/nmcli.c | 22 +- src/nmcli/polkit-agent.c | 9 +- src/nmcli/settings.c | 24 +- src/nmcli/utils.c | 76 +-- 9 files changed, 885 insertions(+), 859 deletions(-) diff --git a/src/nmcli/agent.c b/src/nmcli/agent.c index 6d0fcfb5c9..b16a3c51c9 100644 --- a/src/nmcli/agent.c +++ b/src/nmcli/agent.c @@ -22,36 +22,36 @@ static void usage(void) { - g_printerr(_("Usage: nmcli agent { COMMAND | help }\n\n" - "COMMAND := { secret | polkit | all }\n\n")); + nmc_printerr(_("Usage: nmcli agent { COMMAND | help }\n\n" + "COMMAND := { secret | polkit | all }\n\n")); } static void usage_agent_secret(void) { - g_printerr(_("Usage: nmcli agent secret { help }\n" - "\n" - "Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n" - "a password it asks registered agents for it. This command keeps nmcli running\n" - "and if a password is required asks the user for it.\n\n")); + nmc_printerr(_("Usage: nmcli agent secret { help }\n" + "\n" + "Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n" + "a password it asks registered agents for it. This command keeps nmcli running\n" + "and if a password is required asks the user for it.\n\n")); } static void usage_agent_polkit(void) { - g_printerr(_("Usage: nmcli agent polkit { help }\n" - "\n" - "Registers nmcli as a polkit action for the user session.\n" - "When a polkit daemon requires an authorization, nmcli asks the user and gives\n" - "the response back to polkit.\n\n")); + nmc_printerr(_("Usage: nmcli agent polkit { help }\n" + "\n" + "Registers nmcli as a polkit action for the user session.\n" + "When a polkit daemon requires an authorization, nmcli asks the user and gives\n" + "the response back to polkit.\n\n")); } static void usage_agent_all(void) { - g_printerr(_("Usage: nmcli agent all { help }\n" - "\n" - "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n")); + nmc_printerr(_("Usage: nmcli agent all { help }\n" + "\n" + "Runs nmcli as both NetworkManager secret and a polkit agent.\n\n")); } static char *pre_input_deftext; @@ -82,7 +82,7 @@ get_secrets_from_user(const NmcConfig *nmc_config, /* Ask user for the password */ if (msg) - g_print("%s\n", msg); + nmc_print("%s\n", msg); if (secret->value) { /* Prefill the password if we have it. */ rl_startup_hook = set_deftext; @@ -138,7 +138,7 @@ do_agent_secret(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const * NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, G_CALLBACK(secrets_requested), nmc); - g_print(_("nmcli successfully registered as a NetworkManager's secret agent.\n")); + nmc_print(_("nmcli successfully registered as a NetworkManager's secret agent.\n")); } else { g_string_printf(nmc->return_text, _("Error: secret agent initialization failed")); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; @@ -148,7 +148,7 @@ do_agent_secret(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const * static void polkit_registered(gpointer instance, gpointer user_data) { - g_print(_("nmcli successfully registered as a polkit agent.\n")); + nmc_print(_("nmcli successfully registered as a polkit agent.\n")); } static void @@ -202,14 +202,14 @@ do_agent_all(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *arg do_agent_secret(cmd, nmc, argc, argv); r = nmc->return_value; if (r != NMC_RESULT_SUCCESS) { - g_printerr("%s\n", nmc->return_text->str); + nmc_printerr("%s\n", nmc->return_text->str); g_string_truncate(nmc->return_text, 0); nmc->return_value = NMC_RESULT_SUCCESS; } do_agent_polkit(cmd, nmc, argc, argv); if (nmc->return_value != NMC_RESULT_SUCCESS) { - g_printerr("%s\n", nmc->return_text->str); + nmc_printerr("%s\n", nmc->return_text->str); g_string_truncate(nmc->return_text, 0); } diff --git a/src/nmcli/common.c b/src/nmcli/common.c index 8c89f82dcc..f31d09872d 100644 --- a/src/nmcli/common.c +++ b/src/nmcli/common.c @@ -660,16 +660,16 @@ vpn_openconnect_get_secrets(NMConnection *connection, GPtrArray *secrets) /* Interactively authenticate to OpenConnect server and get secrets */ ret = nm_vpn_openconnect_authenticate_helper(gw, &cookie, &gateway, &gwcert, &status, &error); if (!ret) { - g_printerr(_("Error: openconnect failed: %s\n"), error->message); + nmc_printerr(_("Error: openconnect failed: %s\n"), error->message); g_clear_error(&error); return FALSE; } if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) - g_printerr(_("Error: openconnect failed with status %d\n"), WEXITSTATUS(status)); + nmc_printerr(_("Error: openconnect failed with status %d\n"), WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) - g_printerr(_("Error: openconnect failed with signal %d\n"), WTERMSIG(status)); + nmc_printerr(_("Error: openconnect failed with signal %d\n"), WTERMSIG(status)); /* Append port to the host value */ if (gateway && port) { @@ -743,7 +743,7 @@ get_secrets_from_user(const NmcConfig *nmc_config, } } if (msg) - g_print("%s\n", msg); + nmc_print("%s\n", msg); echo_on = secret->is_secret ? nmc_config->show_secrets : TRUE; @@ -760,10 +760,10 @@ get_secrets_from_user(const NmcConfig *nmc_config, pwd = g_strdup(""); } else { if (msg) - g_print("%s\n", msg); - g_printerr(_("Warning: password for '%s' not given in 'passwd-file' " - "and nmcli cannot ask without '--ask' option.\n"), - secret->entry_id); + nmc_print("%s\n", msg); + nmc_printerr(_("Warning: password for '%s' not given in 'passwd-file' " + "and nmcli cannot ask without '--ask' option.\n"), + secret->entry_id); } } /* No password provided, cancel the secrets. */ @@ -1532,7 +1532,7 @@ nmc_do_cmd(NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, const if (argc == 1 && nmc->complete) { for (c = cmds; c->cmd; ++c) { if (!*cmd || matches(cmd, c->cmd)) - g_print("%s\n", c->cmd); + nmc_print("%s\n", c->cmd); } nmc_complete_help(cmd); g_task_return_boolean(task, TRUE); @@ -1612,7 +1612,7 @@ nmc_complete_strv(const char *prefix, gssize nargs, const char *const *args) if (prefix && !matches(prefix, candidate)) continue; - g_print("%s\n", candidate); + nmc_print("%s\n", candidate); } } diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 97cd991e8b..36de6373e9 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -1084,7 +1084,7 @@ static TabCompletionInfo nmc_tab_completion; static void usage(void) { - g_printerr( + nmc_printerr( _("Usage: nmcli connection { COMMAND | help }\n\n" "COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload " "| load | import | export }\n\n" @@ -1110,7 +1110,7 @@ usage(void) static void usage_connection_show(void) { - g_printerr( + nmc_printerr( _("Usage: nmcli connection show { ARGUMENTS | help }\n" "\n" "ARGUMENTS := [--active] [--order ]\n" @@ -1132,171 +1132,173 @@ usage_connection_show(void) static void usage_connection_up(void) { - g_printerr(_("Usage: nmcli connection up { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] [ifname ] [ap ] [nsp ] " - "[passwd-file ]\n" - "\n" - "Activate a connection on a device. The profile to activate is identified by its\n" - "name, UUID or D-Bus path.\n" - "\n" - "ARGUMENTS := ifname [ap ] [nsp ] [passwd-file ]\n" - "\n" - "Activate a device with a connection. The connection profile is selected\n" - "automatically by NetworkManager.\n" - "\n" - "ifname - specifies the device to active the connection on\n" - "ap - specifies AP to connect to (only valid for Wi-Fi)\n" - "nsp - specifies NSP to connect to (only valid for WiMAX)\n" - "passwd-file - file with password(s) required to activate the connection\n\n")); + nmc_printerr( + _("Usage: nmcli connection up { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] [ifname ] [ap ] [nsp ] " + "[passwd-file ]\n" + "\n" + "Activate a connection on a device. The profile to activate is identified by its\n" + "name, UUID or D-Bus path.\n" + "\n" + "ARGUMENTS := ifname [ap ] [nsp ] [passwd-file ]\n" + "\n" + "Activate a device with a connection. The connection profile is selected\n" + "automatically by NetworkManager.\n" + "\n" + "ifname - specifies the device to active the connection on\n" + "ap - specifies AP to connect to (only valid for Wi-Fi)\n" + "nsp - specifies NSP to connect to (only valid for WiMAX)\n" + "passwd-file - file with password(s) required to activate the connection\n\n")); } static void usage_connection_down(void) { - g_printerr(_("Usage: nmcli connection down { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path | apath] ...\n" - "\n" - "Deactivate a connection from a device (without preventing the device from\n" - "further auto-activation). The profile to deactivate is identified by its name,\n" - "UUID or D-Bus path.\n\n")); + nmc_printerr( + _("Usage: nmcli connection down { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path | apath] ...\n" + "\n" + "Deactivate a connection from a device (without preventing the device from\n" + "further auto-activation). The profile to deactivate is identified by its name,\n" + "UUID or D-Bus path.\n\n")); } static void usage_connection_add(void) { - g_printerr(_("Usage: nmcli connection add { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- " - "([+|-]. )+]\n\n" - " COMMON_OPTIONS:\n" - " type \n" - " [ifname | \"*\"]\n" - " [con-name ]\n" - " [autoconnect yes|no]\n" - " [save yes|no]\n" - " [master ]\n" - " [slave-type ]\n\n" - " TYPE_SPECIFIC_OPTIONS:\n" - " ethernet: [mac ]\n" - " [cloned-mac ]\n" - " [mtu ]\n\n" - " wifi: ssid \n" - " [mac ]\n" - " [cloned-mac ]\n" - " [mtu ]\n" - " [mode infrastructure|ap|adhoc]\n\n" - " wimax: [mac ]\n" - " [nsp ]\n\n" - " pppoe: username \n" - " [password ]\n" - " [service ]\n" - " [mtu ]\n" - " [mac ]\n\n" - " gsm: apn \n" - " [user ]\n" - " [password ]\n\n" - " cdma: [user ]\n" - " [password ]\n\n" - " infiniband: [mac ]\n" - " [mtu ]\n" - " [transport-mode datagram | connected]\n" - " [parent ]\n" - " [p-key ]\n\n" - " bluetooth: [addr ]\n" - " [bt-type panu|nap|dun-gsm|dun-cdma]\n\n" - " vlan: dev \n" - " id \n" - " [flags ]\n" - " [ingress ]\n" - " [egress ]\n" - " [mtu ]\n\n" - " bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | " - "broadcast (3) |\n" - " 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n" - " [primary ]\n" - " [miimon ]\n" - " [downdelay ]\n" - " [updelay ]\n" - " [arp-interval ]\n" - " [arp-ip-target ]\n" - " [lacp-rate slow (0) | fast (1)]\n\n" - " bond-slave: master \n" - " [queue-id <0-65535>]\n\n" - " team: [config |]\n\n" - " team-slave: master \n" - " [config |]\n\n" - " bridge: [stp yes|no]\n" - " [priority ]\n" - " [forward-delay <2-30>]\n" - " [hello-time <1-10>]\n" - " [max-age <6-40>]\n" - " [ageing-time <0-1000000>]\n" - " [multicast-snooping yes|no]\n" - " [mac ]\n\n" - " bridge-slave: master \n" - " [priority <0-63>]\n" - " [path-cost <1-65535>]\n" - " [hairpin yes|no]\n\n" - " vpn: vpn-type " - "vpnc|openvpn|pptp|openconnect|openswan|libreswan|ssh|l2tp|iodine|...\n" - " [user ]\n\n" - " olpc-mesh: ssid \n" - " [channel <1-13>]\n" - " [dhcp-anycast ]\n\n" - " adsl: username \n" - " protocol pppoa|pppoe|ipoatm\n" - " [password ]\n" - " [encapsulation vcmux|llc]\n\n" - " tun: mode tun|tap\n" - " [owner ]\n" - " [group ]\n" - " [pi yes|no]\n" - " [vnet-hdr yes|no]\n" - " [multi-queue yes|no]\n\n" - " ip-tunnel: mode ipip|gre|sit|isatap|vti|ip6ip6|ipip6|ip6gre|vti6\n" - " remote \n" - " [local ]\n" - " [dev ]\n\n" - " macsec: dev \n" - " mode \n" - " [cak ckn ]\n" - " [encrypt yes|no]\n" - " [port 1-65534]\n\n\n" - " macvlan: dev \n" - " mode vepa|bridge|private|passthru|source\n" - " [tap yes|no]\n\n" - " vxlan: id \n" - " [remote ]\n" - " [local ]\n" - " [dev ]\n" - " [source-port-min <0-65535>]\n" - " [source-port-max <0-65535>]\n" - " [destination-port <0-65535>]\n\n" - " wpan: [short-addr <0x0000-0xffff>]\n" - " [pan-id <0x0000-0xffff>]\n" - " [page ]\n" - " [channel ]\n" - " [mac ]\n\n" - " 6lowpan: dev \n" - " dummy:\n\n" - " SLAVE_OPTIONS:\n" - " bridge: [priority <0-63>]\n" - " [path-cost <1-65535>]\n" - " [hairpin yes|no]\n\n" - " team: [config |]\n\n" - " bond: [queue-id <0-65535>]\n\n" - " IP_OPTIONS:\n" - " [ip4 ] [gw4 ]\n" - " [ip6 ] [gw6 ]\n\n")); + nmc_printerr(_("Usage: nmcli connection add { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- " + "([+|-]. )+]\n\n" + " COMMON_OPTIONS:\n" + " type \n" + " [ifname | \"*\"]\n" + " [con-name ]\n" + " [autoconnect yes|no]\n" + " [save yes|no]\n" + " [master ]\n" + " [slave-type ]\n\n" + " TYPE_SPECIFIC_OPTIONS:\n" + " ethernet: [mac ]\n" + " [cloned-mac ]\n" + " [mtu ]\n\n" + " wifi: ssid \n" + " [mac ]\n" + " [cloned-mac ]\n" + " [mtu ]\n" + " [mode infrastructure|ap|adhoc]\n\n" + " wimax: [mac ]\n" + " [nsp ]\n\n" + " pppoe: username \n" + " [password ]\n" + " [service ]\n" + " [mtu ]\n" + " [mac ]\n\n" + " gsm: apn \n" + " [user ]\n" + " [password ]\n\n" + " cdma: [user ]\n" + " [password ]\n\n" + " infiniband: [mac ]\n" + " [mtu ]\n" + " [transport-mode datagram | connected]\n" + " [parent ]\n" + " [p-key ]\n\n" + " bluetooth: [addr ]\n" + " [bt-type panu|nap|dun-gsm|dun-cdma]\n\n" + " vlan: dev \n" + " id \n" + " [flags ]\n" + " [ingress ]\n" + " [egress ]\n" + " [mtu ]\n\n" + " bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | " + "broadcast (3) |\n" + " 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n" + " [primary ]\n" + " [miimon ]\n" + " [downdelay ]\n" + " [updelay ]\n" + " [arp-interval ]\n" + " [arp-ip-target ]\n" + " [lacp-rate slow (0) | fast (1)]\n\n" + " bond-slave: master \n" + " [queue-id <0-65535>]\n\n" + " team: [config |]\n\n" + " team-slave: master \n" + " [config |]\n\n" + " bridge: [stp yes|no]\n" + " [priority ]\n" + " [forward-delay <2-30>]\n" + " [hello-time <1-10>]\n" + " [max-age <6-40>]\n" + " [ageing-time <0-1000000>]\n" + " [multicast-snooping yes|no]\n" + " [mac ]\n\n" + " bridge-slave: master \n" + " [priority <0-63>]\n" + " [path-cost <1-65535>]\n" + " [hairpin yes|no]\n\n" + " vpn: vpn-type " + "vpnc|openvpn|pptp|openconnect|openswan|libreswan|ssh|l2tp|iodine|...\n" + " [user ]\n\n" + " olpc-mesh: ssid \n" + " [channel <1-13>]\n" + " [dhcp-anycast ]\n\n" + " adsl: username \n" + " protocol pppoa|pppoe|ipoatm\n" + " [password ]\n" + " [encapsulation vcmux|llc]\n\n" + " tun: mode tun|tap\n" + " [owner ]\n" + " [group ]\n" + " [pi yes|no]\n" + " [vnet-hdr yes|no]\n" + " [multi-queue yes|no]\n\n" + " ip-tunnel: mode ipip|gre|sit|isatap|vti|ip6ip6|ipip6|ip6gre|vti6\n" + " remote \n" + " [local ]\n" + " [dev ]\n\n" + " macsec: dev \n" + " mode \n" + " [cak ckn ]\n" + " [encrypt yes|no]\n" + " [port 1-65534]\n\n\n" + " macvlan: dev \n" + " mode vepa|bridge|private|passthru|source\n" + " [tap yes|no]\n\n" + " vxlan: id \n" + " [remote ]\n" + " [local ]\n" + " [dev ]\n" + " [source-port-min <0-65535>]\n" + " [source-port-max <0-65535>]\n" + " [destination-port <0-65535>]\n\n" + " wpan: [short-addr <0x0000-0xffff>]\n" + " [pan-id <0x0000-0xffff>]\n" + " [page ]\n" + " [channel ]\n" + " [mac ]\n\n" + " 6lowpan: dev \n" + " dummy:\n\n" + " SLAVE_OPTIONS:\n" + " bridge: [priority <0-63>]\n" + " [path-cost <1-65535>]\n" + " [hairpin yes|no]\n\n" + " team: [config |]\n\n" + " bond: [queue-id <0-65535>]\n\n" + " IP_OPTIONS:\n" + " [ip4 ] [gw4 ]\n" + " [ip6 ] [gw6 ]\n\n")); } static void usage_connection_modify(void) { - g_printerr( + nmc_printerr( _("Usage: nmcli connection modify { ARGUMENTS | help }\n" "\n" "ARGUMENTS := [id | uuid | path] ([+|-]. )+\n" @@ -1325,77 +1327,78 @@ usage_connection_modify(void) static void usage_connection_clone(void) { - g_printerr(_("Usage: nmcli connection clone { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [--temporary] [id | uuid | path] \n" - "\n" - "Clone an existing connection profile. The newly created connection will be\n" - "the exact copy of the , except the uuid property (will be generated) and\n" - "id (provided as argument).\n\n")); + nmc_printerr(_("Usage: nmcli connection clone { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [--temporary] [id | uuid | path] \n" + "\n" + "Clone an existing connection profile. The newly created connection will be\n" + "the exact copy of the , except the uuid property (will be generated) and\n" + "id (provided as argument).\n\n")); } static void usage_connection_edit(void) { - g_printerr(_("Usage: nmcli connection edit { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] \n" - "\n" - "Edit an existing connection profile in an interactive editor.\n" - "The profile is identified by its name, UUID or D-Bus path\n" - "\n" - "ARGUMENTS := [type ] [con-name ]\n" - "\n" - "Add a new connection profile in an interactive editor.\n\n")); + nmc_printerr(_("Usage: nmcli connection edit { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] \n" + "\n" + "Edit an existing connection profile in an interactive editor.\n" + "The profile is identified by its name, UUID or D-Bus path\n" + "\n" + "ARGUMENTS := [type ] [con-name ]\n" + "\n" + "Add a new connection profile in an interactive editor.\n\n")); } static void usage_connection_delete(void) { - g_printerr(_("Usage: nmcli connection delete { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] , ...\n" - "\n" - "Delete connection profiles.\n" - "The profiles are identified by their name, UUID or D-Bus path.\n\n")); + nmc_printerr(_("Usage: nmcli connection delete { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] , ...\n" + "\n" + "Delete connection profiles.\n" + "The profiles are identified by their name, UUID or D-Bus path.\n\n")); } static void usage_connection_monitor(void) { - g_printerr(_("Usage: nmcli connection monitor { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] ...\n" - "\n" - "Monitor connection profile activity.\n" - "This command prints a line whenever the specified connection changes.\n" - "Monitors all connection profiles in case none is specified.\n\n")); + nmc_printerr(_("Usage: nmcli connection monitor { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] ...\n" + "\n" + "Monitor connection profile activity.\n" + "This command prints a line whenever the specified connection changes.\n" + "Monitors all connection profiles in case none is specified.\n\n")); } static void usage_connection_reload(void) { - g_printerr(_("Usage: nmcli connection reload { help }\n" - "\n" - "Reload all connection files from disk.\n\n")); + nmc_printerr(_("Usage: nmcli connection reload { help }\n" + "\n" + "Reload all connection files from disk.\n\n")); } static void usage_connection_load(void) { - g_printerr(_("Usage: nmcli connection load { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [...]\n" - "\n" - "Load/reload one or more connection files from disk. Use this after manually\n" - "editing a connection file to ensure that NetworkManager is aware of its latest\n" - "state.\n\n")); + nmc_printerr( + _("Usage: nmcli connection load { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [...]\n" + "\n" + "Load/reload one or more connection files from disk. Use this after manually\n" + "editing a connection file to ensure that NetworkManager is aware of its latest\n" + "state.\n\n")); } static void usage_connection_import(void) { - g_printerr( + nmc_printerr( _("Usage: nmcli connection import { ARGUMENTS | help }\n" "\n" "ARGUMENTS := [--temporary] type file \n" @@ -1409,23 +1412,24 @@ usage_connection_import(void) static void usage_connection_export(void) { - g_printerr(_("Usage: nmcli connection export { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [id | uuid | path] []\n" - "\n" - "Export a connection. Only VPN connections are supported at the moment.\n" - "The data are directed to standard output or to a file if a name is given.\n\n")); + nmc_printerr( + _("Usage: nmcli connection export { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [id | uuid | path] []\n" + "\n" + "Export a connection. Only VPN connections are supported at the moment.\n" + "The data are directed to standard output or to a file if a name is given.\n\n")); } static void usage_connection_migrate(void) { - g_printerr(_("Usage: nmcli connection migrate { ARGUMENTS | help }\n" - "\n" - "ARGUMENTS := [--plugin ] [id | uuid | path] , ...\n" - "\n" - "Migrate connection profiles to a different settings plugin,\n" - "such as \"keyfile\" (default) or \"ifcfg-rh\".\n\n")); + nmc_printerr(_("Usage: nmcli connection migrate { ARGUMENTS | help }\n" + "\n" + "ARGUMENTS := [--plugin ] [id | uuid | path] , ...\n" + "\n" + "Migrate connection profiles to a different settings plugin,\n" + "such as \"keyfile\" (default) or \"ifcfg-rh\".\n\n")); } static char * @@ -1503,9 +1507,9 @@ got_secrets(GObject *source_object, GAsyncResult *res, gpointer user_data) gs_free_error GError *error = NULL; if (!nm_connection_update_secrets(data->local, NULL, secrets, &error) && error) { - g_printerr(_("Error updating secrets for %s: %s\n"), - data->setting_name, - error->message); + nmc_printerr(_("Error updating secrets for %s: %s\n"), + data->setting_name, + error->message); } } @@ -1613,7 +1617,7 @@ nmc_connection_profile_details(NMConnection *connection, NmCli *nmc) if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) && !nmc->nmc_config.multiline_output && was_output) - g_print("\n"); /* Empty line */ + nmc_print("\n"); /* Empty line */ was_output = FALSE; @@ -1719,7 +1723,7 @@ nmc_active_connection_details(NMActiveConnection *acon, NmCli *nmc) if (NM_IN_SET(nmc->nmc_config.print_output, NMC_PRINT_NORMAL, NMC_PRINT_PRETTY) && !nmc->nmc_config.multiline_output && was_output) - g_print("\n"); + nmc_print("\n"); was_output = FALSE; @@ -2507,7 +2511,7 @@ do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con nm_assert(explicit_acon || con); if (new_line) - g_print("\n"); + nmc_print("\n"); new_line = TRUE; if (without_fields || profile_flds) { @@ -2532,7 +2536,7 @@ do_connections_show(const NMCCommand *cmd, NmCli *nmc, int argc, const char *con /* if there are multiple active connections, separate them with newline. * that is a bit odd, because we already separate connections with newlines, * and commonly don't separate the connection from the first active connection. */ - g_print("\n"); + nmc_print("\n"); } if (explicit_acon) @@ -2800,12 +2804,12 @@ check_activated(ActivateConnectionInfo *info) if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line(); if (reason) { - g_print(_("Connection successfully activated (%s) (D-Bus active path: %s)\n"), - reason, - nm_object_get_path(NM_OBJECT(info->active))); + nmc_print(_("Connection successfully activated (%s) (D-Bus active path: %s)\n"), + reason, + nm_object_get_path(NM_OBJECT(info->active))); } else { - g_print(_("Connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path(NM_OBJECT(info->active))); + nmc_print(_("Connection successfully activated (D-Bus active path: %s)\n"), + nm_object_get_path(NM_OBJECT(info->active))); } activate_connection_info_finish(info); break; @@ -2955,8 +2959,8 @@ activate_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line(); - g_print(_("Connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path(NM_OBJECT(active))); + nmc_print(_("Connection successfully activated (D-Bus active path: %s)\n"), + nm_object_get_path(NM_OBJECT(active))); } activate_connection_info_finish(info); } else { @@ -3325,9 +3329,9 @@ connection_removed_cb(NMClient *client, NMConnection *connection, ConnectionCbIn { if (!connection_cb_info_obj_list_has(info, connection)) return; - g_print(_("Connection '%s' (%s) successfully deleted.\n"), - nm_connection_get_id(connection), - nm_connection_get_uuid(connection)); + nmc_print(_("Connection '%s' (%s) successfully deleted.\n"), + nm_connection_get_id(connection), + nm_connection_get_uuid(connection)); connection_cb_info_finish(info, connection); } @@ -3341,9 +3345,9 @@ down_active_connection_state_cb(NMActiveConnection *active, if (info->nmc->nmc_config.print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line(); - g_print(_("Connection '%s' successfully deactivated (D-Bus active path: %s)\n"), - nm_active_connection_get_id(active), - nm_object_get_path(NM_OBJECT(active))); + nmc_print(_("Connection '%s' successfully deactivated (D-Bus active path: %s)\n"), + nm_active_connection_get_id(active), + nm_object_get_path(NM_OBJECT(active))); g_signal_handlers_disconnect_by_func(G_OBJECT(active), down_active_connection_state_cb, info); connection_cb_info_finish(info, active); @@ -3422,7 +3426,7 @@ do_connection_down(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons arg_num == 1 && nmc->complete); if (!active) { if (!nmc->complete) - g_printerr(_("Error: '%s' is not an active connection.\n"), *arg_ptr); + nmc_printerr(_("Error: '%s' is not an active connection.\n"), *arg_ptr); g_string_printf(nmc->return_text, _("Error: not all active connections found.")); nmc->return_value = NMC_RESULT_ERROR_NOT_FOUND; } @@ -3463,9 +3467,9 @@ do_connection_down(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons active = found_active_cons->pdata[i]; if (!nm_client_deactivate_connection(nmc->client, active, NULL, &error)) { - g_print(_("Connection '%s' deactivation failed: %s\n"), - nm_active_connection_get_id(active), - error->message); + nmc_print(_("Connection '%s' deactivation failed: %s\n"), + nm_active_connection_get_id(active), + error->message); g_clear_error(&error); if (info) { @@ -3944,7 +3948,7 @@ normalized_master_for_slave(const GPtrArray *connections, } if (!out_master) { - g_print(_("Warning: master='%s' doesn't refer to any existing profile.\n"), master); + nmc_print(_("Warning: master='%s' doesn't refer to any existing profile.\n"), master); out_master = master; if (out_type) *out_type = type; @@ -4985,7 +4989,7 @@ complete_property_name(NmCli *nmc, prefix, postfix); if (word_list) - g_print("%s", word_list); + nmc_print("%s", word_list); if (modifier != NM_META_ACCESSOR_MODIFIER_SET) return; @@ -5014,7 +5018,7 @@ complete_property_name(NmCli *nmc, if (!bi->base.property_alias || !g_str_has_prefix(bi->base.property_alias, prefix)) continue; - g_print("%s\n", bi->base.property_alias); + nmc_print("%s\n", bi->base.property_alias); } } else { if (!property_info->is_cli_option) @@ -5022,7 +5026,7 @@ complete_property_name(NmCli *nmc, if (!property_info->property_alias || !g_str_has_prefix(property_info->property_alias, prefix)) continue; - g_print("%s\n", property_info->property_alias); + nmc_print("%s\n", property_info->property_alias); } } } @@ -5035,7 +5039,7 @@ run_rl_generator(rl_compentry_func_t *generator_func, const char *prefix) char *str; while ((str = generator_func(prefix, state))) { - g_print("%s\n", str); + nmc_print("%s\n", str); g_free(str); if (state == 0) state = 1; @@ -5069,7 +5073,7 @@ complete_option(NmCli *nmc, } if (values) { for (; values[0]; values++) - g_print("%s\n", values[0]); + nmc_print("%s\n", values[0]); return TRUE; } @@ -5094,11 +5098,11 @@ complete_existing_setting(NmCli *nmc, NMConnection *connection, const char *pref editor = nm_meta_setting_info_editor_find_by_setting(settings[i]); if (!prefix || g_str_has_prefix(editor->general->setting_name, prefix)) - g_print("%s\n", editor->general->setting_name); + nmc_print("%s\n", editor->general->setting_name); if (editor->alias) { if (!prefix || g_str_has_prefix(editor->alias, prefix)) - g_print("%s\n", editor->alias); + nmc_print("%s\n", editor->alias); } } } @@ -5386,7 +5390,7 @@ nmc_process_connection_properties(NmCli *nmc, if (!chosen) { if (*argc == 1 && nmc->complete) { if (allow_setting_removal && g_str_has_prefix("remove", option)) - g_print("remove\n"); + nmc_print("remove\n"); complete_property_name(nmc, connection, modifier, option, NULL); } g_set_error(error, @@ -5426,7 +5430,7 @@ connection_warnings(NmCli *nmc, NMConnection *connection) deprecated = nmc_connection_check_deprecated(NM_CONNECTION(connection)); if (deprecated) - g_printerr(_("Warning: %s.\n"), deprecated); + nmc_printerr(_("Warning: %s.\n"), deprecated); connections = nmc_get_connections(nmc); id = nm_connection_get_id(connection); @@ -5441,15 +5445,15 @@ connection_warnings(NmCli *nmc, NMConnection *connection) } if (found > 0) { - g_printerr(g_dngettext(GETTEXT_PACKAGE, - "Warning: There is another connection with the name '%1$s'. " - "Reference the connection by its uuid '%2$s'\n", - "Warning: There are %3$u other connections with the name " - "'%1$s'. Reference the connection by its uuid '%2$s'\n", - found), - id, - nm_connection_get_uuid(NM_CONNECTION(connection)), - found); + nmc_printerr(g_dngettext(GETTEXT_PACKAGE, + "Warning: There is another connection with the name '%1$s'. " + "Reference the connection by its uuid '%2$s'\n", + "Warning: There are %3$u other connections with the name " + "'%1$s'. Reference the connection by its uuid '%2$s'\n", + found), + id, + nm_connection_get_uuid(NM_CONNECTION(connection)), + found); } } @@ -5481,9 +5485,9 @@ add_connection_cb(GObject *client, GAsyncResult *result, gpointer user_data) * * This is true for many messages that the user might parse. But this one * seems in particular interesting for a user to parse. */ - g_print(_("Connection '%s' (%s) successfully added.\n"), - nm_connection_get_id(NM_CONNECTION(connection)), - nm_connection_get_uuid(NM_CONNECTION(connection))); + nmc_print(_("Connection '%s' (%s) successfully added.\n"), + nm_connection_get_id(NM_CONNECTION(connection)), + nm_connection_get_uuid(NM_CONNECTION(connection))); g_object_unref(connection); } @@ -5629,7 +5633,8 @@ ask_option(NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstr multi = NM_FLAGS_HAS(inf_flags, NM_META_PROPERTY_INF_FLAG_MULTI); if (multi) - g_print(_("You can specify this option more than once. Press when you're done.\n")); + nmc_print( + _("You can specify this option more than once. Press when you're done.\n")); again: nm_clear_g_free(&value); @@ -5638,7 +5643,7 @@ again: value = nmc_readline(&nmc->nmc_config, "%s", prompt); if (!set_option(nmc, connection, abstract_info, value, FALSE, &error)) { - g_printerr("%s\n", error->message); + nmc_printerr("%s\n", error->message); goto again; } @@ -5740,7 +5745,7 @@ want_provide_opt_args(const NmcConfig *nmc_config, const char *type, guint num) return TRUE; /* Ask for optional arguments. */ - g_print(_("There are %d optional settings for %s.\n"), (int) num, type); + nmc_print(_("There are %d optional settings for %s.\n"), (int) num, type); answer = nmc_readline(nmc_config, _("Do you want to provide them? %s"), prompt_yes_no(TRUE, NULL)); nm_strstrip(answer); @@ -6872,7 +6877,7 @@ load_history_cmds(const char *uuid) kf = g_key_file_new(); if (!g_key_file_load_from_file(kf, filename, G_KEY_FILE_KEEP_COMMENTS, &err)) { if (g_error_matches(err, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE)) - g_print("Warning: %s parse error: %s\n", filename, err->message); + nmc_print("Warning: %s parse error: %s\n", filename, err->message); g_key_file_free(kf); g_free(filename); return; @@ -6911,7 +6916,7 @@ save_history_cmds(const char *uuid) if (!g_key_file_load_from_file(kf, filename, G_KEY_FILE_KEEP_COMMENTS, &error)) { if (!g_error_matches(error, G_FILE_ERROR, G_FILE_ERROR_NOENT) && !g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_NOT_FOUND)) { - g_print("Warning: %s parse error: %s\n", filename, error->message); + nmc_print("Warning: %s parse error: %s\n", filename, error->message); return; } g_clear_error(&error); @@ -6947,7 +6952,7 @@ editor_show_connection(NMConnection *connection, NmCli *nmc) static void editor_show_setting(NMSetting *setting, NmCli *nmc) { - g_print(_("['%s' setting values]\n"), nm_setting_get_name(setting)); + nmc_print(_("['%s' setting values]\n"), nm_setting_get_name(setting)); nmc->nmc_config_mutable.print_output = NMC_PRINT_NORMAL; nmc->nmc_config_mutable.multiline_output = TRUE; @@ -7054,24 +7059,24 @@ fail: static void editor_main_usage(void) { - g_print("------------------------------------------------------------------------------\n"); + nmc_print("------------------------------------------------------------------------------\n"); /* TRANSLATORS: do not translate command names and keywords before :: * However, you should translate terms enclosed in <>. */ - g_print(_("---[ Main menu ]---\n" - "goto [ | ] :: go to a setting or property\n" - "remove [.] | :: remove setting or reset property value\n" - "set [. ] :: set property value\n" - "describe [.] :: describe property\n" - "print [all | [.]] :: print the connection\n" - "verify [all | fix] :: verify the connection\n" - "save [persistent|temporary] :: save the connection\n" - "activate [] [/|] :: activate the connection\n" - "back :: go one level up (back)\n" - "help/? [] :: print this help\n" - "nmcli :: nmcli configuration\n" - "quit :: exit nmcli\n")); - g_print("------------------------------------------------------------------------------\n"); + nmc_print(_("---[ Main menu ]---\n" + "goto [ | ] :: go to a setting or property\n" + "remove [.] | :: remove setting or reset property value\n" + "set [. ] :: set property value\n" + "describe [.] :: describe property\n" + "print [all | [.]] :: print the connection\n" + "verify [all | fix] :: verify the connection\n" + "save [persistent|temporary] :: save the connection\n" + "activate [] [/|] :: activate the connection\n" + "back :: go one level up (back)\n" + "help/? [] :: print this help\n" + "nmcli :: nmcli configuration\n" + "quit :: exit nmcli\n")); + nmc_print("------------------------------------------------------------------------------\n"); } static void @@ -7085,14 +7090,15 @@ editor_main_help(const char *command) switch (cmd) { case NMC_EDITOR_MAIN_CMD_GOTO: - g_print(_("goto [.] | :: enter setting/property for editing\n\n" - "This command enters into a setting or property for editing it.\n\n" - "Examples: nmcli> goto connection\n" - " nmcli connection> goto secondaries\n" - " nmcli> goto ipv4.addresses\n")); + nmc_print( + _("goto [.] | :: enter setting/property for editing\n\n" + "This command enters into a setting or property for editing it.\n\n" + "Examples: nmcli> goto connection\n" + " nmcli connection> goto secondaries\n" + " nmcli> goto ipv4.addresses\n")); break; case NMC_EDITOR_MAIN_CMD_REMOVE: - g_print( + nmc_print( _("remove [.] :: remove setting or reset property value\n\n" "This command removes an entire setting from the connection, or if a property\n" "is given, resets that property to the default value.\n\n" @@ -7100,27 +7106,27 @@ editor_main_help(const char *command) " nmcli> remove eth.mtu\n")); break; case NMC_EDITOR_MAIN_CMD_SET: - g_print(_("set [. ] :: set property value\n\n" - "This command sets property value.\n\n" - "Example: nmcli> set con.id My connection\n")); + nmc_print(_("set [. ] :: set property value\n\n" + "This command sets property value.\n\n" + "Example: nmcli> set con.id My connection\n")); break; case NMC_EDITOR_MAIN_CMD_ADD: - g_print(_("add [. ] :: add property value\n\n" - "This command appends property value.\n\n" - "Example: nmcli> add ipv4.addresses 192.168.1.1/24\n")); + nmc_print(_("add [. ] :: add property value\n\n" + "This command appends property value.\n\n" + "Example: nmcli> add ipv4.addresses 192.168.1.1/24\n")); break; case NMC_EDITOR_MAIN_CMD_DESCRIBE: - g_print(_("describe [.] :: describe property\n\n" - "Shows property description. You can consult nm-settings(5) " - "manual page to see all NM settings and properties.\n")); + nmc_print(_("describe [.] :: describe property\n\n" + "Shows property description. You can consult nm-settings(5) " + "manual page to see all NM settings and properties.\n")); break; case NMC_EDITOR_MAIN_CMD_PRINT: - g_print(_("print [all] :: print setting or connection values\n\n" - "Shows current property or the whole connection.\n\n" - "Example: nmcli ipv4> print all\n")); + nmc_print(_("print [all] :: print setting or connection values\n\n" + "Shows current property or the whole connection.\n\n" + "Example: nmcli ipv4> print all\n")); break; case NMC_EDITOR_MAIN_CMD_VERIFY: - g_print( + nmc_print( _("verify [all | fix] :: verify setting or connection validity\n\n" "Verifies whether the setting or connection is valid and can be saved later.\n" "It indicates invalid values on error. Some errors may be fixed automatically\n" @@ -7130,7 +7136,7 @@ editor_main_help(const char *command) " nmcli bond> verify\n")); break; case NMC_EDITOR_MAIN_CMD_SAVE: - g_print( + nmc_print( _("save [persistent|temporary] :: save the connection\n\n" "Sends the connection profile to NetworkManager that either will save it\n" "persistently, or will only keep it in memory. 'save' without an argument\n" @@ -7142,48 +7148,48 @@ editor_main_help(const char *command) "profile must be deleted.\n")); break; case NMC_EDITOR_MAIN_CMD_ACTIVATE: - g_print(_("activate [] [/|] :: activate the connection\n\n" - "Activates the connection.\n\n" - "Available options:\n" - " - device the connection will be activated on\n" - "/| - AP (Wi-Fi) or NSP (WiMAX) (prepend with / when is " - "not specified)\n")); + nmc_print(_("activate [] [/|] :: activate the connection\n\n" + "Activates the connection.\n\n" + "Available options:\n" + " - device the connection will be activated on\n" + "/| - AP (Wi-Fi) or NSP (WiMAX) (prepend with / when is " + "not specified)\n")); break; case NMC_EDITOR_MAIN_CMD_BACK: - g_print(_("back :: go to upper menu level\n\n")); + nmc_print(_("back :: go to upper menu level\n\n")); break; case NMC_EDITOR_MAIN_CMD_HELP: - g_print(_("help/? [] :: help for the nmcli commands\n\n")); + nmc_print(_("help/? [] :: help for the nmcli commands\n\n")); break; case NMC_EDITOR_MAIN_CMD_NMCLI: - g_print(_("nmcli [ ] :: nmcli configuration\n\n" - "Configures nmcli. The following options are available:\n" - "status-line yes | no [default: no]\n" - "save-confirmation yes | no [default: yes]\n" - "show-secrets yes | no [default: no]\n" - "prompt-color | <0-8> [default: 0]\n" - "%s" /* color table description */ - "\n" - "Examples: nmcli> nmcli status-line yes\n" - " nmcli> nmcli save-confirmation no\n" - " nmcli> nmcli prompt-color 3\n"), - " 0 = normal\n" - " 1 = \33[30mblack\33[0m\n" - " 2 = \33[31mred\33[0m\n" - " 3 = \33[32mgreen\33[0m\n" - " 4 = \33[33myellow\33[0m\n" - " 5 = \33[34mblue\33[0m\n" - " 6 = \33[35mmagenta\33[0m\n" - " 7 = \33[36mcyan\33[0m\n" - " 8 = \33[37mwhite\33[0m\n"); + nmc_print(_("nmcli [ ] :: nmcli configuration\n\n" + "Configures nmcli. The following options are available:\n" + "status-line yes | no [default: no]\n" + "save-confirmation yes | no [default: yes]\n" + "show-secrets yes | no [default: no]\n" + "prompt-color | <0-8> [default: 0]\n" + "%s" /* color table description */ + "\n" + "Examples: nmcli> nmcli status-line yes\n" + " nmcli> nmcli save-confirmation no\n" + " nmcli> nmcli prompt-color 3\n"), + " 0 = normal\n" + " 1 = \33[30mblack\33[0m\n" + " 2 = \33[31mred\33[0m\n" + " 3 = \33[32mgreen\33[0m\n" + " 4 = \33[33myellow\33[0m\n" + " 5 = \33[34mblue\33[0m\n" + " 6 = \33[35mmagenta\33[0m\n" + " 7 = \33[36mcyan\33[0m\n" + " 8 = \33[37mwhite\33[0m\n"); break; case NMC_EDITOR_MAIN_CMD_QUIT: - g_print(_("quit :: exit nmcli\n\n" - "This command exits nmcli. When the connection being edited " - "is not saved, the user is asked to confirm the action.\n")); + nmc_print(_("quit :: exit nmcli\n\n" + "This command exits nmcli. When the connection being edited " + "is not saved, the user is asked to confirm the action.\n")); break; default: - g_print(_("Unknown command: '%s'\n"), command); + nmc_print(_("Unknown command: '%s'\n"), command); break; } } @@ -7244,21 +7250,21 @@ fail: static void editor_sub_help(void) { - g_print("------------------------------------------------------------------------------\n"); + nmc_print("------------------------------------------------------------------------------\n"); /* TRANSLATORS: do not translate command names and keywords before :: * However, you should translate terms enclosed in <>. */ - g_print(_("---[ Property menu ]---\n" - "set [] :: set new value\n" - "add [] :: add new option to the property\n" - "change :: change current value\n" - "remove [ |