diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2010-08-18 17:09:59 +0100 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2010-08-18 17:09:59 +0100 |
commit | daefca342654607db724ce79e212d29d029d662d (patch) | |
tree | c487c5f03b5243b31e19a2bbe487fd5889bf4ac6 | |
parent | 7faaa30132c201c228fafada4bb066efe51e6517 (diff) | |
download | xen-daefca342654607db724ce79e212d29d029d662d.tar.gz xen-daefca342654607db724ce79e212d29d029d662d.tar.bz2 xen-daefca342654607db724ce79e212d29d029d662d.zip |
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@citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r-- | tools/libxl/libxl.c | 12 | ||||
-rw-r--r-- | tools/libxl/libxl.h | 2 | ||||
-rw-r--r-- | tools/libxl/xl_cmdimpl.c | 4 |
3 files changed, 13 insertions, 5 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index c95272d432..c31c659d09 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -959,12 +959,20 @@ int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num, libxl_conso 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 --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index c757a9f09d..d9de4f67a8 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -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 --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 323dd04803..b5a1cddb47 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1851,7 +1851,7 @@ int main_cd_insert(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); |