diff options
author | Thomas Haller <thaller@redhat.com> | 2018-10-09 13:08:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-10-10 09:55:45 +0200 |
commit | 428d26299024e6232ef4243ee3d7ae8295878592 (patch) | |
tree | d45edae73fc8771abfeb9abdee1f04c4a711c05b | |
parent | 2f291e3ceaf1dc266ac03fb3c438a0cfa8105b58 (diff) |
cli: don't use global variable nm_cli in nmc_terminal_spawn_pager()
print_required_fields() still accesses the global variable.
We can only move the uses of globals up the call-stack, one
bit at a time.
-rw-r--r-- | clients/cli/connections.c | 3 | ||||
-rw-r--r-- | clients/cli/general.c | 6 | ||||
-rw-r--r-- | clients/cli/nmcli.c | 8 | ||||
-rw-r--r-- | clients/cli/nmcli.h | 2 | ||||
-rw-r--r-- | clients/cli/utils.c | 23 | ||||
-rw-r--r-- | clients/cli/utils.h | 2 |
6 files changed, 26 insertions, 18 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 5355755d0..e81343e06 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -1988,8 +1988,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv) } } - /* Optionally start paging the output. */ - nmc_terminal_spawn_pager (&nmc->nmc_config); + nm_cli_spawn_pager (nmc); items = con_show_get_items (nmc, active_only, show_active_fields, order); g_ptr_array_add (items, NULL); diff --git a/clients/cli/general.c b/clients/cli/general.c index 6bdbd1b26..d1f3e6f6d 100644 --- a/clients/cli/general.c +++ b/clients/cli/general.c @@ -546,8 +546,7 @@ print_permissions (void *user_data) permissions[i++] = GINT_TO_POINTER (perm); permissions[i++] = NULL; - /* Optionally start paging the output. */ - nmc_terminal_spawn_pager (&nmc->nmc_config); + nm_cli_spawn_pager (nmc); if (!nmc_print (&nmc->nmc_config, permissions, @@ -1270,8 +1269,7 @@ do_overview (NmCli *nmc, int argc, char **argv) /* Register polkit agent */ nmc_start_polkit_agent_start_try (nmc); - /* Optionally start paging the output. */ - nmc_terminal_spawn_pager (&nmc->nmc_config); + nm_cli_spawn_pager (nmc); /* The VPN connections don't have devices (yet?). */ p = nm_client_get_active_connections (nmc->client); diff --git a/clients/cli/nmcli.c b/clients/cli/nmcli.c index bbfc310d6..df152c1f8 100644 --- a/clients/cli/nmcli.c +++ b/clients/cli/nmcli.c @@ -998,6 +998,14 @@ nmc_value_transforms_register (void) nmc_convert_bytes_to_string); } +void +nm_cli_spawn_pager (NmCli *nmc) +{ + if (nmc->pager_pid > 0) + return; + nmc->pager_pid = nmc_terminal_spawn_pager (&nmc->nmc_config); +} + static void nmc_cleanup (NmCli *nmc) { diff --git a/clients/cli/nmcli.h b/clients/cli/nmcli.h index 286168556..0ccf1653d 100644 --- a/clients/cli/nmcli.h +++ b/clients/cli/nmcli.h @@ -167,6 +167,8 @@ void nmc_clear_sigint (void); void nmc_set_sigquit_internal (void); void nmc_exit (void); +void nm_cli_spawn_pager (NmCli *nmc); + void nmc_empty_output_fields (NmcOutputData *output_data); #define NMC_OUTPUT_DATA_DEFINE_SCOPED(out) \ diff --git a/clients/cli/utils.c b/clients/cli/utils.c index 5c5d50cf5..f9ff489c0 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -36,6 +36,7 @@ #include "nm-meta-setting-access.h" #include "common.h" +#include "nmcli.h" #include "settings.h" #define ML_HEADER_WIDTH 79 @@ -1445,38 +1446,38 @@ pager_fallback (void) _exit(EXIT_SUCCESS); } -void +pid_t nmc_terminal_spawn_pager (const NmcConfig *nmc_config) { const char *pager = getenv ("PAGER"); + pid_t pager_pid; pid_t parent_pid; int fd[2]; - if ( nm_cli.nmc_config.in_editor - || nm_cli.pager_pid > 0 + if ( nmc_config->in_editor || nmc_config->print_output == NMC_PRINT_TERSE || !nmc_config->use_colors || g_strcmp0 (pager, "") == 0 || getauxval (AT_SECURE)) - return; + return 0; if (pipe (fd) == -1) { g_printerr (_("Failed to create pager pipe: %s\n"), strerror (errno)); - return; + return 0; } parent_pid = getpid (); - nm_cli.pager_pid = fork (); - if (nm_cli.pager_pid == -1) { + pager_pid = fork (); + if (pager_pid == -1) { g_printerr (_("Failed to fork pager: %s\n"), strerror (errno)); nm_close (fd[0]); nm_close (fd[1]); - return; + return 0; } /* In the child start the pager */ - if (nm_cli.pager_pid == 0) { + if (pager_pid == 0) { dup2 (fd[0], STDIN_FILENO); nm_close (fd[0]); nm_close (fd[1]); @@ -1521,6 +1522,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config) nm_close (fd[0]); nm_close (fd[1]); + return pager_pid; } /*****************************************************************************/ @@ -1587,8 +1589,7 @@ print_required_fields (const NmcConfig *nmc_config, gboolean field_names = of_flags & NMC_OF_FLAG_FIELD_NAMES; gboolean section_prefix = of_flags & NMC_OF_FLAG_SECTION_PREFIX; - /* Optionally start paging the output. */ - nmc_terminal_spawn_pager (nmc_config); + nm_cli_spawn_pager (&nm_cli); /* --- Main header --- */ if ( nmc_config->print_output == NMC_PRINT_PRETTY diff --git a/clients/cli/utils.h b/clients/cli/utils.h index 00692f4a7..b84b35bff 100644 --- a/clients/cli/utils.h +++ b/clients/cli/utils.h @@ -40,7 +40,7 @@ gboolean nmc_parse_args (nmc_arg_t *arg_arr, gboolean last, int *argc, char ***a char *ssid_to_hex (const char *str, gsize len); void nmc_terminal_erase_line (void); void nmc_terminal_show_progress (const char *str); -void nmc_terminal_spawn_pager (const NmcConfig *nmc_config); +pid_t nmc_terminal_spawn_pager (const NmcConfig *nmc_config); char *nmc_colorize (const NmcConfig *nmc_config, NMMetaColor color, const char * fmt, ...) _nm_printf (3, 4); void nmc_filter_out_colors_inplace (char *str); char *nmc_filter_out_colors (const char *str); |