Fix: tools: make crm_mon exit upon loss of the attached pseudo-terminal
Previously when crm_mon was running in console mode, if the attached
pseudo-terminal got lost, crm_mon would persist in the background and
raise the CPU usage to 100%.
The situation triggers if use_pty is enabled for sudo, in which case
it creates a separate pseudo-terminal device for its child process.
A producer:
- Enable use_pty by adding Defaults use_pty to /etc/sudoers
- Open a console and execute: > sudo su -
- crm_mon
- Open another console, find the PID of crm_mon's bash parent and kill it:
- kill -9 $(ps -C crm_mon -o ppid=)
The pty device created by sudo from the first console is basically
deleted, but crm_mon continues running in the background and raises the
CPU usage.
This commit fixes it by watching more conditions from stdin and exiting upon
(G_IO_ERR | G_IO_HUP).
The similar was reported and fixed for the more command:
https://github.com/util-linux/util-linux/pull/2635
https://github.com/util-linux/util-linux/pull/2795
The tail command is also impacted but hasn't been fixed so far.
There's the relevant discussion here:
https://github.com/sudo-project/sudo/issues/367
Fixes T16