From 3463c34e33e65c1aadf71c42db7d9666030686c7 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 29 Jan 2009 17:02:00 +0000 Subject: [PATCH] fix VNC port reporting when vncunused is set --- ChangeLog | 11 +++++++++++ src/util.c | 2 +- src/xend_internal.c | 15 +++++++++------ tests/sexpr2xmltest.c | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index cadf3efc4d..3838db9334 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Thu Jan 29 16:41:07 GMT 2009 John Levon + + * src/util.c: allow strtol replacements for libvirt proxy + + * src/xend_internal.c: fix VNC port reporting when vncunused + is set + + * tests/sexpr2xmldata/sexpr2xml-fv-autoport.sexpr: + * tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml: + * tests/sexpr2xmltest.c: add a test + Thu Jan 29 13:07:05 +0100 2009 Jim Meyering * Makefile.cfg: disable some new checks diff --git a/src/util.c b/src/util.c index e0499998c8..aa3ae8666b 100644 --- a/src/util.c +++ b/src/util.c @@ -1041,6 +1041,7 @@ cleanup: return rc; } +#endif /* PROXY */ /* Like strtol, but produce an "int" result, and check more carefully. @@ -1123,7 +1124,6 @@ virStrToLong_ull(char const *s, char **end_ptr, int base, unsigned long long *re *result = val; return 0; } -#endif /* PROXY */ /** * virSkipSpaces: diff --git a/src/xend_internal.c b/src/xend_internal.c index e7efcc1658..48e046afcc 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -612,7 +612,9 @@ sexpr_get(virConnectPtr xend, const char *fmt, ...) * * convenience function to lookup an int value in the S-Expression * - * Returns the value found or 0 if not found (but may not be an error) + * Returns the value found or 0 if not found (but may not be an error). + * This function suffers from the flaw that zero is both a correct + * return value and an error indicator: careful! */ static int sexpr_int(const struct sexpr *sexpr, const char *name) @@ -2090,15 +2092,16 @@ xenDaemonParseSxprGraphicsNew(virConnectPtr conn, port = xenStoreDomainGetVNCPort(conn, def->id); xenUnifiedUnlock(priv); + // Didn't find port entry in xenstore if (port == -1) { - // Didn't find port entry in xenstore - port = sexpr_int(node, "device/vfb/vncdisplay"); + const char *str = sexpr_node(node, "device/vfb/vncdisplay"); + int val; + if (str != NULL && virStrToLong_i(str, NULL, 0, &val) == 0) + port = val; } - if ((unused && STREQ(unused, "1")) || port == -1) { + if ((unused && STREQ(unused, "1")) || port == -1) graphics->data.vnc.autoport = 1; - port = -1; - } if (port >= 0 && port < 5900) port += 5900; diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c index 9033d2015a..09cf45a5d4 100644 --- a/tests/sexpr2xmltest.c +++ b/tests/sexpr2xmltest.c @@ -127,6 +127,7 @@ mymain(int argc, char **argv) DO_TEST("pv-vfb-orig", "pv-vfb-orig", 2); DO_TEST("pv-vfb-new", "pv-vfb-new", 3); DO_TEST("pv-vfb-new-vncdisplay", "pv-vfb-new-vncdisplay", 3); + DO_TEST("fv-autoport", "fv-autoport", 3); DO_TEST("pv-bootloader", "pv-bootloader", 1); DO_TEST("disk-file", "disk-file", 2);