]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Fix job watching when STDIN is not a tty
authorPeter Krempa <pkrempa@redhat.com>
Tue, 22 Oct 2013 14:01:26 +0000 (15:01 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 22 Oct 2013 14:01:26 +0000 (15:01 +0100)
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.

tools/virsh-domain.c
tools/virsh.c
tools/virsh.h

index b75f33139fd3fc4586f04f6cf382d3db58e5783e..5aabccdfb533e3068b151d97c2315464b229260d 100644 (file)
@@ -3529,6 +3529,7 @@ vshWatchJob(vshControl *ctl,
     bool functionReturn = false;
     sigset_t sigmask, oldsigmask;
     bool jobStarted = false;
+    nfds_t npollfd = 2;
 
     sigemptyset(&sigmask);
     sigaddset(&sigmask, SIGINT);
@@ -3539,9 +3540,13 @@ vshWatchJob(vshControl *ctl,
     sigemptyset(&sig_action.sa_mask);
     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);
     while (1) {
-        ret = poll((struct pollfd *)&pollfd, 2, 500);
+        ret = poll((struct pollfd *)&pollfd, npollfd, 500);
         if (ret > 0) {
             if (pollfd[1].revents & POLLIN &&
                 saferead(STDIN_FILENO, &retchar, sizeof(retchar)) > 0) {
index a76229a25414f7d845ab72d4db46e31221ccb3ef..8425f53a77a65c5bb6e164f4c8b0ae34e5c071a4 100644 (file)
@@ -2226,6 +2226,13 @@ vshTTYIsInterruptCharacter(vshControl *ctl ATTRIBUTE_UNUSED,
 }
 
 
+bool
+vshTTYAvailable(vshControl *ctl)
+{
+    return ctl->istty;
+}
+
+
 int
 vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED)
 {
index f978d94f6b2089d13d0969ec4861b06b88fc37ed..b84378806148a9b83da4d435ac322ea3dd36d911 100644 (file)
@@ -365,6 +365,8 @@ bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
 int vshTTYDisableInterrupt(vshControl *ctl);
 int vshTTYRestore(vshControl *ctl);
 int vshTTYMakeRaw(vshControl *ctl, bool report_errors);
+bool vshTTYAvailable(vshControl *ctl);
+
 
 /* allocation wrappers */
 void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);