There's a race condition for if the VM gets powered off between the
[invirt/packages/invirt-remote.git] / files / usr / sbin / sipb-xen-remote-control
index 1ad8721..6d30d71 100755 (executable)
@@ -23,10 +23,21 @@ def main(argv):
 
     if machine_name not in vms:
         print >>sys.stderr, "machine '%s' is not on" % machine_name
-        return 2
+        return 1
     host = vms[machine_name]['host']
 
-    return call(['remctl', host, 'remote', 'control'] + argv[1:])
+    p = Popen(['remctl', host, 'remote', 'control'] + argv[1:],
+              stdout=PIPE, stderr=PIPE)
+    (out, err) = p.communicate()
+    if p.returncode == 1:
+        print >>sys.stderr, "machine '%s' is not on" % machine_name
+        return 1
+    elif p.returncode == 34:
+        print >>sys.stderr, "ERROR: invalid command"
+        return 34
+    sys.stderr.write(err)
+    sys.stdout.write(out)
+    return p.returncode
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv))