mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-15 10:40:18 +01:00
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.
This commit is contained in:
parent
411243c654
commit
99d3b6930b
6 changed files with 26 additions and 18 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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) \
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue