cli: avoid passing full NmCli global variable to nm_cli_spawn_pager()

We should not use global variables, and we should minimize the state
that we pass around. Instead of requiring the full NmCli struct in
nm_cli_spawn_pager(), pass only the necessary data.

This reduces our use of global variables.
This commit is contained in:
Thomas Haller
2020-04-02 13:59:53 +02:00
parent 7627173c0e
commit dbf697c759
5 changed files with 20 additions and 12 deletions

View File

@@ -911,11 +911,12 @@ signal_handler (gpointer user_data)
}
void
nm_cli_spawn_pager (NmCli *nmc)
nm_cli_spawn_pager (const NmcConfig *nmc_config,
NmcPagerData *pager_data)
{
if (nmc->pager_pid > 0)
if (pager_data->pid != 0)
return;
nmc->pager_pid = nmc_terminal_spawn_pager (&nmc->nmc_config);
pager_data->pid = nmc_terminal_spawn_pager (nmc_config);
}
static void
@@ -937,13 +938,14 @@ nmc_cleanup (NmCli *nmc)
nm_clear_g_free (&nmc->required_fields);
if (nmc->pager_pid > 0) {
if (nmc->pager_data.pid != 0) {
pid_t pid = nm_steal_int (&nmc->pager_data.pid);
fclose (stdout);
fclose (stderr);
do {
ret = waitpid (nmc->pager_pid, NULL, 0);
ret = waitpid (pid, NULL, 0);
} while (ret == -1 && errno == EINTR);
nmc->pager_pid = 0;
}
nm_clear_g_free (&nmc->palette_buffer);