[libvirt] [PATCH] virsh: fix password auth failed on ssh connection

Seyeong Kim seyeong.kim at canonical.com
Tue Aug 26 05:25:02 UTC 2014


When try to connect to another host using virsh with password auth on ssh env,
can't put password properly because it's waiting IO from STDIN.

This patch check if it's in pts so make that doesn't poll from STDIN.
---
 tools/virsh-domain.c |  3 +++
 tools/virsh.c        | 11 +++++++++++
 tools/virsh.h        |  2 ++
 3 files changed, 16 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 2562326..b079261 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3698,6 +3698,9 @@ vshWatchJob(vshControl *ctl,
     /* don't poll on STDIN if we are not using a terminal */
     if (!vshTTYAvailable(ctl))
         npollfd = 1;
+    /* don't poll on STDIN if we are using a pseudo terminal slave */
+    if (vshPTSAvailable(ctl))
+        npollfd = 1;
 
     GETTIMEOFDAY(&start);
     while (1) {
diff --git a/tools/virsh.c b/tools/virsh.c
index 30a84c1..84f9500 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2429,6 +2429,13 @@ vshTTYAvailable(vshControl *ctl)
 }
 
 
+bool
+vshPTSAvailable(vshControl *ctl)
+{
+    return ctl->ispts;
+}
+
+
 int
 vshTTYDisableInterrupt(vshControl *ctl ATTRIBUTE_UNUSED)
 {
@@ -3646,6 +3653,10 @@ main(int argc, char **argv)
     if (isatty(STDIN_FILENO)) {
         ctl->istty = true;
 
+        char* tty_name = ttyname(STDIN_FILENO);
+        if (strstr(tty_name, "pts"))
+            ctl->ispts = true;
+
 #ifndef WIN32
         if (tcgetattr(STDIN_FILENO, &ctl->termattr) < 0)
             ctl->istty = false;
diff --git a/tools/virsh.h b/tools/virsh.h
index b4df24b..700c786 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -256,6 +256,7 @@ struct _vshControl {
     struct termios termattr;    /* settings of the tty terminal */
 # endif
     bool istty;                 /* is the terminal a tty */
+    bool ispts;                 /* is the terminal a pts */
 };
 
 struct _vshCmdGrp {
@@ -386,6 +387,7 @@ int vshTTYDisableInterrupt(vshControl *ctl);
 int vshTTYRestore(vshControl *ctl);
 int vshTTYMakeRaw(vshControl *ctl, bool report_errors);
 bool vshTTYAvailable(vshControl *ctl);
+bool vshPTSAvailable(vshControl *ctl);
 
 /* waiting for events */
 enum {
-- 
1.9.1




More information about the libvir-list mailing list