nmcli: always clean up readline on exit

A signal handler is not the only place where we need to clean up after
an in-progress readline() on exit; we may do so when erroring out as
well:

Before (not also the missing line break, which is part of the cleanup):

  $ (sleep 10; nmcli c del 'Red Hat Wi-Fi')
  $ nmcli --ask d wifi connect 'Red Hat Wi-Fi'
  Passwords or encryption keys are required to access the wireless network 'Red Hat Wi-Fi'.
  Password (802-11-wireless-security.psk): Error: Connection activation failed: The device's active connection disappeared.
  $ [terminal messed up, no echo]

After:

  $ (sleep 10; nmcli c del 'Red Hat Wi-Fi')
  $ nmcli --ask d wifi connect 'Red Hat Wi-Fi'
  Passwords or encryption keys are required to access the wireless network 'Red Hat Wi-Fi'.
  Password (802-11-wireless-security.psk):
  Error: Connection activation failed: The device's active connection disappeared.
  $ hello [terminal echo fine, wheee]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1959
This commit is contained in:
Lubomir Rintel 2024-06-05 14:43:43 +02:00
parent 508d43efc9
commit 6de187cb37
2 changed files with 3 additions and 1 deletions

View file

@ -824,7 +824,7 @@ static char *rl_string;
/**
* nmc_cleanup_readline:
*
* Cleanup readline when nmcli is terminated with a signal.
* Cleanup readline when nmcli is terminated.
* It makes sure the terminal is not garbled.
*/
void

View file

@ -1044,6 +1044,8 @@ main(int argc, char *argv[])
if (process_command_line(&nm_cli, argc, argv))
g_main_loop_run(loop);
nmc_cleanup_readline();
if (nm_cli.complete) {
/* Remove error statuses from command completion runs. */
if (nm_cli.return_value < NMC_RESULT_COMPLETE_FILE)