]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Allow VIRSH_DEFAULT_CONNECT_URI to override default URI. Don't asusme there is always...
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 25 Aug 2006 22:40:33 +0000 (22:40 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 25 Aug 2006 22:40:33 +0000 (22:40 +0000)
ChangeLog
src/virsh.c

index dab533b6081df911e1c85bf5a8c7ce22e0080da9..8f93897ebd1745d767e83d1a24414ef680623cce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Aug 25 17:42:12 EDT 2006 Daniel Berrange <berrange@redhat.com>
+
+       * src/virsh.c: Allow VIRSH_DEFAULT_CONNECT_URI to be set to
+       override the default Xen connection attempt in favour of a
+       different backend. Fix 'virsh list' so that it doesn't assume
+       there is always a Domain-0 (a Xen-ism).
+       
 Thu Aug 24 16:43:47 EDT 2006 Daniel Berrange <berrange@redhat.com>
 
        * tests/virshtest.c: Test suite for validating output / operation
index 5ccd0bd2b9cf9c3897bbc5893800d9494a3b1fa2..df6676fe9e4f9a3e1046c342f3039adf3c6d110d 100644 (file)
@@ -319,24 +319,24 @@ static vshCmdInfo info_list[] = {
 static int
 cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
 {
-    int *ids, maxid, i;
+    int *ids = NULL, maxid, i;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
 
     maxid = virConnectNumOfDomains(ctl->conn);
-    if (maxid <= 0) {
-        /* strange, there should be at least dom0... */
+    if (maxid < 0) {
         vshError(ctl, FALSE, "failed to list active domains.");
         return FALSE;
     }
-    ids = vshMalloc(ctl, sizeof(int) * maxid);
+    if (maxid) {
+        ids = vshMalloc(ctl, sizeof(int) * maxid);
 
-    if (virConnectListDomains(ctl->conn, &ids[0], maxid) < 0) {
-        vshError(ctl, FALSE, "failed to list active domains.");
-        return FALSE;
+        if (virConnectListDomains(ctl->conn, &ids[0], maxid) < 0) {
+            vshError(ctl, FALSE, "failed to list active domains.");
+            return FALSE;
+        }
     }
-
     vshPrintExtra(ctl, "%3s %-20s %s\n", "Id", "Name", "State");
     vshPrintExtra(ctl, "----------------------------------\n");
 
@@ -357,7 +357,8 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
                  0 ? "no state" : vshDomainStateToString(info.state));
         virDomainFree(dom);
     }
-    free(ids);
+    if (ids)
+        free(ids);
     return TRUE;
 }
 
@@ -2377,6 +2378,7 @@ int
 main(int argc, char **argv)
 {
     vshControl _ctl, *ctl = &_ctl;
+    char *defaultConn;
     int ret = TRUE;
 
     if (!(progname = strrchr(argv[0], '/')))
@@ -2387,6 +2389,10 @@ main(int argc, char **argv)
     memset(ctl, 0, sizeof(vshControl));
     ctl->imode = TRUE;          /* default is interactive mode */
 
+    if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
+      ctl->name = strdup(defaultConn);
+    }
+
     if (!vshParseArgv(ctl, argc, argv))
         exit(EXIT_FAILURE);