Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset terminal on erroneous console exit #6519

Merged
merged 2 commits into from Sep 13, 2018
Merged

Conversation

mcktr
Copy link
Member

@mcktr mcktr commented Aug 5, 2018

This ensures that the terminal is reset on an erroneous exit when using the Icinga 2 console. The problematic state only occurs if Icinga 2 is compiled with libedit support.

Test

  1. Start the Icinga 2 console and choose an invalid port.
metis ~/Coding/icinga/icinga2/build_debug (fix/erroneous-console-exit) # /home/michael/bin/icinga2/sbin/icinga2 console --connect https://localhost:9999/
Icinga 2 (version: v2.9.1-50-g51b900b30)
Type $help to view available commands.
<1> =>
  1. Now hit the tab key. The console (correctly) terminates with an critical error because of the invalid port.
metis ~/Coding/icinga/icinga2/build_debug (fix/erroneous-console-exit) # /home/michael/bin/icinga2/sbin/icinga2 console --connect https://localhost:9999/
Icinga 2 (version: v2.9.1-50-g51b900b30)
Type $help to view available commands.
<1> => critical/TcpSocket: Invalid socket: Connection refused
critical/ConsoleCommand: HTTP query failed: std::exception

  1. Hit the return key.
metis ~/Coding/icinga/icinga2/build_debug (fix/erroneous-console-exit) # /home/michael/bin/icinga2/sbin/icinga2 console --connect https://localhost:9999/
Icinga 2 (version: v2.9.1-50-g51b900b30)
Type $help to view available commands.
<1> => critical/TcpSocket: Invalid socket: Connection refused
critical/ConsoleCommand: HTTP query failed: std::exception
metis ~/Coding/icinga/icinga2/build_debug (fix/erroneous-console-exit) #
  1. The terminal stays intact.

fixes #6382

This ensures that the terminal is resetted on an erroneous exit when using the Icinga 2 console.

refs #6382
@mcktr mcktr added bug Something isn't working area/cli Command line helpers labels Aug 5, 2018
@Crunsher
Copy link
Contributor

Crunsher commented Aug 6, 2018

Nice, this has always been bugging me but never enough to fix it myself ^_^

@Crunsher
Copy link
Contributor

Crunsher commented Aug 6, 2018

While testing this I noticed I can't reproduce this anymore. Meaning the result with the master and your PR is the same. So I went and looked up rl_deprep_terminal:
Function: void rl_deprep_terminal (void)
Undo the effects of rl_prep_terminal(), leaving the terminal in the state in which it was before the most recent call to rl_prep_terminal().

Is rl_prep_terminal called somehow by the library? Because we don't do so explicitly.

@mcktr
Copy link
Member Author

mcktr commented Aug 6, 2018

I just tested the master on Debian 9 and I can reproduce #6382.

root@testing-deb9-icinga2:~# /tmp/icinga2/sbin/icinga2 console --connect https://localhost:9999/
Icinga 2 (version: v2.9.1-55-g33492420f)
Type $help to view available commands.
<1> => critical/TcpSocket: Invalid socket: Connection refused
critical/ConsoleCommand: HTTP query failed: std::exception
root@testing-deb9-icinga2:~# root@testing-deb9-icinga2:~# root@testing-deb9-icinga2:~# root@testing-deb9-icinga2:~#

Notice that this only occurse if you press the tab key.

The function rl_reset_terminal seems to fit better here. Unfortunately this works for /tmp/icinga2/lib/icinga2/sbin/icinga2 console --connect https://localhost:9999/ but not for /tmp/icinga2/sbin/icinga2 console --connect https://localhost:9999/.

From a look I into the library I guess rl_prep_terminal is not called by the library. Basicly the two functions set the tty mode (rl_prep_terminal for raw mode and rl_deprep_terminal for cooked mode). I can't rule out that the raw mode getting set during the readline call, but in an other fashion.

@dnsmichi dnsmichi added this to the 2.10.0 milestone Sep 11, 2018
@dnsmichi dnsmichi self-requested a review September 13, 2018 11:14
@dnsmichi
Copy link
Contributor

Current

screen shot 2018-09-13 at 13 15 54

Fixed

screen shot 2018-09-13 at 13 32 46

@dnsmichi
Copy link
Contributor

(Ok you cannot set it, but terminal 1 is broken, terminal 2 works)

Copy link
Contributor

@dnsmichi dnsmichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@dnsmichi dnsmichi merged commit c8d4e78 into master Sep 13, 2018
@dnsmichi dnsmichi deleted the fix/erroneous-console-exit branch September 13, 2018 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Command line helpers bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

icinga2 console breaks the terminal on errors
3 participants