[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] tools/libxl: fix "xl console" for primary console



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1282147799 -3600
# Node ID 9a4acc688e9fcb87d1b92e658c33a240182ebc06
# Parent  aa078b53ff624a7f49fb9b92e9925000afbb3c1c
tools/libxl: fix "xl console" for primary console

libxl_console_constype is an enum and can therefore be unsigned so
using -1 as a sentinel for unset in main_console fails to work as
expected.

Arrange for all valid enum values to be > 0 and use 0 as the sentinal
instead.

If the user does not request a specific type then always use the
primary console since using "-n" but not "-t" is not meaningful as we
do not know which type to request.

Also make libxl_console_exec reject invalid values of type.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c      |   12 ++++++++++--
 tools/libxl/libxl.h      |    2 +-
 tools/libxl/xl_cmdimpl.c |    4 ++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff -r aa078b53ff62 -r 9a4acc688e9f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Aug 18 17:09:25 2010 +0100
+++ b/tools/libxl/libxl.c       Wed Aug 18 17:09:59 2010 +0100
@@ -959,12 +959,20 @@ int libxl_console_exec(libxl_ctx *ctx, u
     char *cons_num_s = libxl_sprintf(&gc, "%d", cons_num);
     char *cons_type_s;
 
-    if (type == LIBXL_CONSTYPE_PV)
+    switch (type) {
+    case LIBXL_CONSTYPE_PV:
         cons_type_s = "pv";
-    else
+        break;
+    case LIBXL_CONSTYPE_SERIAL:
         cons_type_s = "serial";
+        break;
+    default:
+        goto out;
+    }
 
     execl(p, p, domid_s, "--num", cons_num_s, "--type", cons_type_s, (void 
*)NULL);
+
+out:
     libxl_free_all(&gc);
     return ERROR_FAIL;
 }
diff -r aa078b53ff62 -r 9a4acc688e9f tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Aug 18 17:09:25 2010 +0100
+++ b/tools/libxl/libxl.h       Wed Aug 18 17:09:59 2010 +0100
@@ -155,7 +155,7 @@ typedef enum {
 } libxl_qemu_machine_type;
 
 typedef enum {
-    LIBXL_CONSTYPE_SERIAL,
+    LIBXL_CONSTYPE_SERIAL = 1,
     LIBXL_CONSTYPE_PV,
 } libxl_console_constype;
 
diff -r aa078b53ff62 -r 9a4acc688e9f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Aug 18 17:09:25 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed Aug 18 17:09:59 2010 +0100
@@ -1851,7 +1851,7 @@ int main_console(int argc, char **argv)
 int main_console(int argc, char **argv)
 {
     int opt = 0, num = 0;
-    libxl_console_constype type = -1;
+    libxl_console_constype type = 0;
 
     while ((opt = getopt(argc, argv, "hn:t:")) != -1) {
         switch (opt) {
@@ -1882,7 +1882,7 @@ int main_console(int argc, char **argv)
     }
 
     find_domain(argv[optind]);
-    if (type <= 0 && num == 0)
+    if (!type)
         libxl_primary_console_exec(&ctx, domid);
     else
         libxl_console_exec(&ctx, domid, num, type);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.