diff options
author | Thomas Haller <thaller@redhat.com> | 2020-04-02 13:33:10 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-04-04 19:28:41 +0200 |
commit | 873f4795b293b23ad3c9e9f7e457b9acf96eb5e5 (patch) | |
tree | 61599e710f76929033bb1063518d99784637a627 | |
parent | 2d83df38200121c9c0db56d62d07264da6c22d20 (diff) | |
download | NetworkManager-873f4795b293b23ad3c9e9f7e457b9acf96eb5e5.tar.gz |
cli: add and use nm_cli_global_readline global variable
We should try to avoid access to global variables. For libreadline
callbacks we still need a global variable.
Introduce a global variable nm_cli_global_readline, specially for this
use. It makes the places clear where we use it, and discourages
the use at other places, where we better avoid global variables.
-rw-r--r-- | clients/cli/common.c | 2 | ||||
-rw-r--r-- | clients/cli/connections.c | 10 | ||||
-rw-r--r-- | clients/cli/nmcli.c | 2 | ||||
-rw-r--r-- | clients/cli/nmcli.h | 2 |
4 files changed, 10 insertions, 6 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index a5d9bcbb1a..7e9bcba860 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -1118,7 +1118,7 @@ nmc_rl_gen_func_ifnames (const char *text, int state) const char **ifnames; char *ret; - devices = nm_client_get_devices (nm_cli.client); + devices = nm_client_get_devices (nm_cli_global_readline->client); if (devices->len == 0) return NULL; diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 65fde6db22..ff3314236b 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -5827,7 +5827,7 @@ gen_vpn_uuids (const char *text, int state) const char **uuids; char *ret; - connections = nm_client_get_connections (nm_cli.client); + connections = nm_client_get_connections (nm_cli_global_readline->client); if (connections->len < 1) return NULL; @@ -5844,7 +5844,7 @@ gen_vpn_ids (const char *text, int state) const char **ids; char *ret; - connections = nm_client_get_connections (nm_cli.client); + connections = nm_client_get_connections (nm_cli_global_readline->client); if (connections->len < 1) return NULL; @@ -9253,7 +9253,7 @@ gen_func_connection_names (const char *text, int state) const char **connection_names; char *ret; - connections = nm_client_get_connections (nm_cli.client); + connections = nm_client_get_connections (nm_cli_global_readline->client); if (connections->len == 0) return NULL; @@ -9276,10 +9276,10 @@ gen_func_active_connection_names (const char *text, int state) const char **connections; char *ret; - if (!nm_cli.client) + if (!nm_cli_global_readline->client) return NULL; - acs = nm_client_get_active_connections (nm_cli.client); + acs = nm_client_get_active_connections (nm_cli_global_readline->client); if (!acs || acs->len == 0) return NULL; diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index 5fbd6d7261..6751a080c1 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -101,6 +101,8 @@ NmCli nm_cli = { .editor_save_confirmation = TRUE, }; +const NmCli *const nm_cli_global_readline = &nm_cli; + /*****************************************************************************/ typedef struct { diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 4615b04689..f9a0661629 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -137,6 +137,8 @@ typedef struct _NmCli { extern NmCli nm_cli; +extern const NmCli *const nm_cli_global_readline; + /* Error quark for GError domain */ #define NMCLI_ERROR (nmcli_error_quark ()) GQuark nmcli_error_quark (void); |