<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p><tt>Long ago, I submitted an issue:
        <a class="moz-txt-link-freetext" href="https://github.com/kimchi-project/kimchi/issues/1170">https://github.com/kimchi-project/kimchi/issues/1170</a> ...</tt></p>
    <p><tt>Test by following script:</tt></p>
    <blockquote>
      <p><tt>import subprocess<br>
          import os<br>
          import time<br>
          <br>
          def _check_remote_libvirt_conn(remote_host,<br>
                  user='root', transport='ssh'):<br>
          <br>
              FNULL = open(os.devnull, 'w')<br>
              dest_uri = 'qemu+%s://%s@%s/system' % (transport, user,
          remote_host)<br>
              cmd = ['virsh', '-c', dest_uri, 'list']<br>
              proc = subprocess.Popen(cmd, stdout=FNULL, stderr=FNULL,<br>
                      shell=True, preexec_fn=os.setsid)<br>
              timeout = 0<br>
              while proc.poll() is None:<br>
                  time.sleep(1)<br>
                  timeout += 1<br>
                  if timeout == 5:<br>
                      print("killed")<br>
                      os.killpg(os.getpgid(proc.pid), signal.SIGTERM)<br>
          <br>
          if __name__ == '__main__':<br>
              _check_remote_libvirt_conn('localhost')</tt></p>
    </blockquote>
    <p><tt>`proc` is timeout every time although the connection is
        normal tested by `virsh -c &lt;uri&gt;` list <br>
      </tt></p>
    <p><tt><br>
      </tt></p>
    <p><tt>The following is the reason of changing(From Python Document
        2.7.14):<br>
      </tt></p>
    <p><tt> Do not use stdout=PIPE or stderr=PIPE with this function as
        <font color="#330099">that can deadlock</font> based on the
        child process output volume. Use Popen with the communicate()
        method when you need pipes.</tt></p>
    <p><tt> Using shell=True can be <font color="#330099">a security
          hazard</font>. See the warning under Frequently Used Arguments
        for details.<br>
      </tt></p>
    <p><tt>At the same time, if not change, it does not work.<br>
      </tt></p>
    <p><tt><br>
      </tt></p>
    <p><tt>diff --git a/model/vms.py b/model/vms.py</tt><tt><br>
      </tt><tt>index 6da4f3b..92e771f 100644</tt><tt><br>
      </tt><tt>--- a/model/vms.py</tt><tt><br>
      </tt><tt>+++ b/model/vms.py</tt><tt><br>
      </tt><tt>@@ -1885,10 +1885,11 @@ class VMModel(object):</tt><tt><br>
      </tt><tt>     def _check_remote_libvirt_conn(self, remote_host,</tt><tt><br>
      </tt><tt>                                    user='root',
        transport='ssh'):</tt><tt><br>
      </tt><tt> </tt><tt><br>
      </tt><tt>+        FNULL = open(os.devnull, 'w')</tt><tt><br>
      </tt><tt>         dest_uri = 'qemu+%s://%s@%s/system' %
        (transport, user, remote_host)</tt><tt><br>
      </tt><tt>         cmd = ['virsh', '-c', dest_uri, 'list']</tt><tt><br>
      </tt><tt>-        proc = subprocess.Popen(cmd,
        stdout=subprocess.PIPE,</tt><tt><br>
      </tt><tt>-                                shell=True,
        preexec_fn=os.setsid)</tt><tt><br>
      </tt><tt>+        proc = subprocess.Popen(cmd, stdout=FNULL,
        stderr=FNULL,</tt><tt><br>
      </tt><tt>+                                shell=False,
        preexec_fn=os.setsid)</tt><tt><br>
      </tt><tt>         timeout = 0</tt><tt><br>
      </tt><tt>         while proc.poll() is None:</tt><tt><br>
      </tt><tt>             time.sleep(1)</tt><br>
      <br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Regards
River (Fu.Lin)</pre>
  </body>
</html>