1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-06 08:58:35 +03:00

virsh: Fix job watching when STDIN is not a tty

In commit b46c4787dde79b015dad67dedda4ccf6ff1a3082 I changed the code to
watch long running jobs in virsh. Unfortunately I didn't take into
account that poll may get a hangup if the terminal is not a TTY and will
be closed.

This patch avoids polling the STDIN fd when there's no TTY.
This commit is contained in:
Peter Krempa 2013-10-22 15:01:26 +01:00
parent dc33207dbe
commit 47e6396651
3 changed files with 15 additions and 1 deletions

View File

@ -3529,6 +3529,7 @@ vshWatchJob(vshControl *ctl,
bool functionReturn = false; bool functionReturn = false;
sigset_t sigmask, oldsigmask; sigset_t sigmask, oldsigmask;
bool jobStarted = false; bool jobStarted = false;
nfds_t npollfd = 2;
sigemptyset(&sigmask); sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGINT);
@ -3539,9 +3540,13 @@ vshWatchJob(vshControl *ctl,
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action); sigaction(SIGINT, &sig_action, &old_sig_action);
/* don't poll on STDIN if we are not using a terminal */
if (!vshTTYAvailable(ctl))
npollfd = 1;
GETTIMEOFDAY(&start); GETTIMEOFDAY(&start);
while (1) { while (1) {
ret = poll((struct pollfd *)&pollfd, 2, 500); ret = poll((struct pollfd *)&pollfd, npollfd, 500);
if (ret > 0) { if (ret > 0) {
if (pollfd[1].revents & POLLIN && if (pollfd[1].revents & POLLIN &&
saferead(STDIN_FILENO, &retchar, sizeof(retchar)) > 0) { saferead(STDIN_FILENO, &retchar, sizeof(retchar)) > 0) {

View File

@ -2226,6 +2226,13 @@ vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED,
} }
bool
vshTTYAvailable(vshControl *ctl)
{
return ctl->istty;
}
int int
vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED) vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED)
{ {

View File

@ -365,6 +365,8 @@ bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
int vshTTYDisableInterrupt(vshControl *ctl); int vshTTYDisableInterrupt(vshControl *ctl);
int vshTTYRestore(vshControl *ctl); int vshTTYRestore(vshControl *ctl);
int vshTTYMakeRaw(vshControl *ctl, bool report_errors); int vshTTYMakeRaw(vshControl *ctl, bool report_errors);
bool vshTTYAvailable(vshControl *ctl);
/* allocation wrappers */ /* allocation wrappers */
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);