diff options
Diffstat (limited to 'clients/cli/utils.c')
| -rw-r--r-- | clients/cli/utils.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c index e21c108d..1b940467 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 @@ -919,6 +920,8 @@ nmc_empty_output_fields (NmcOutputData *output_data) /* Empty output_data array */ if (output_data->output_data->len > 0) g_ptr_array_remove_range (output_data->output_data, 0, output_data->output_data->len); + + g_ptr_array_unref (output_data->output_data); } /*****************************************************************************/ @@ -1098,7 +1101,7 @@ _print_fill (const NmcConfig *nmc_config, /* don't mark the entry for display. This is to shorten the output in case * the property is the default value. But we only do that, if the user * opts in to this behavior (-overview), or of the property marks itself - * elegible to be hidden. + * eligible to be hidden. * * In general, only new API shall mark itself eligible to be hidden. * Long established properties cannot, because it would be a change @@ -1273,7 +1276,7 @@ _print_do (const NmcConfig *nmc_config, title = header_cell->title; width1 = strlen (title); - width2 = nmc_string_screen_width (title, NULL); /* Width of the string (in screen colums) */ + width2 = nmc_string_screen_width (title, NULL); /* Width of the string (in screen columns) */ g_string_append_printf (str, "%-*s", (int) (header_cell->width + width1 - width2), title); g_string_append_c (str, ' '); /* Column separator */ table_width += header_cell->width + width1 - width2 + 1; @@ -1355,7 +1358,7 @@ _print_do (const NmcConfig *nmc_config, const PrintDataHeaderCell *header_cell = &header_row[i_col]; width1 = strlen (text); - width2 = nmc_string_screen_width (text, NULL); /* Width of the string (in screen colums) */ + width2 = nmc_string_screen_width (text, NULL); /* Width of the string (in screen columns) */ g_string_append_printf (str, "%-*s", (int) (header_cell->width + width1 - width2), text); g_string_append_c (str, ' '); /* Column separator */ table_width += header_cell->width + width1 - width2 + 1; @@ -1445,38 +1448,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 +1524,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config) nm_close (fd[0]); nm_close (fd[1]); + return pager_pid; } /*****************************************************************************/ @@ -1587,8 +1591,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 @@ -1728,7 +1731,7 @@ print_required_fields (const NmcConfig *nmc_config, g_string_append_c (str, ':'); /* Column separator */ } else { width1 = strlen (value); - width2 = nmc_string_screen_width (value, NULL); /* Width of the string (in screen colums) */ + width2 = nmc_string_screen_width (value, NULL); /* Width of the string (in screen columns) */ g_string_append_printf (str, "%-*s", field_values[idx].width + width1 - width2, strlen (value) > 0 ? value : not_set_str); g_string_append_c (str, ' '); /* Column separator */ table_width += field_values[idx].width + width1 - width2 + 1; |