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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user