mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-10 01:34:51 +00:00
virsh-domain: Refactor cmdTTYConsole
Use the new XML helpers and use virXPathString rather than hand-rolling the code.
This commit is contained in:
parent
9f5f5bd7d6
commit
27a3fa715e
@ -11184,37 +11184,23 @@ static bool
|
|||||||
cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
|
cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathObjectPtr obj = NULL;
|
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
virDomainPtr dom;
|
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
char *doc;
|
char *tty = NULL;
|
||||||
|
|
||||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
if (virshDomainGetXML(ctl, cmd, 0, &xml, &ctxt) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
doc = virDomainGetXMLDesc(dom, 0);
|
if (!(tty = virXPathString("string(/domain/devices/console/@tty)", ctxt)))
|
||||||
if (!doc)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt);
|
vshPrint(ctl, "%s\n", tty);
|
||||||
VIR_FREE(doc);
|
|
||||||
if (!xml)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
|
|
||||||
if (obj == NULL || obj->type != XPATH_STRING ||
|
|
||||||
obj->stringval == NULL || obj->stringval[0] == 0) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
vshPrint(ctl, "%s\n", (const char *)obj->stringval);
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xmlXPathFreeObject(obj);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
virshDomainFree(dom);
|
VIR_FREE(tty);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user