conf: fix formatting of udp chardev attributes

It is possible (although possibly not very useful) to leave out
the service attribute when using <source mode='bind'/>

Fix the formatter bug introduced by commit 4a0da34 and format
the host when its present (checked for non-NULL inside
virBufferEscapeString) instead of basing it on the presence
of the service attribute.

https://bugzilla.redhat.com/show_bug.cgi?id=1455825
This commit is contained in:
Ján Tomko 2017-09-26 13:30:10 +02:00
parent 93575f3451
commit fcd5c61cd4
2 changed files with 5 additions and 9 deletions

View File

@ -23307,18 +23307,14 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
case VIR_DOMAIN_CHR_TYPE_UDP: case VIR_DOMAIN_CHR_TYPE_UDP:
if (def->data.udp.bindService || def->data.udp.bindHost) { if (def->data.udp.bindService || def->data.udp.bindHost) {
virBufferAddLit(buf, "<source mode='bind'"); virBufferAddLit(buf, "<source mode='bind'");
if (def->data.udp.bindService)
virBufferEscapeString(buf, " host='%s'", def->data.udp.bindHost); virBufferEscapeString(buf, " host='%s'", def->data.udp.bindHost);
if (def->data.udp.bindService)
virBufferEscapeString(buf, " service='%s'", def->data.udp.bindService); virBufferEscapeString(buf, " service='%s'", def->data.udp.bindService);
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
if (def->data.udp.connectService || def->data.udp.connectHost) { if (def->data.udp.connectService || def->data.udp.connectHost) {
virBufferAddLit(buf, "<source mode='connect'"); virBufferAddLit(buf, "<source mode='connect'");
if (def->data.udp.connectService)
virBufferEscapeString(buf, " host='%s'", def->data.udp.connectHost); virBufferEscapeString(buf, " host='%s'", def->data.udp.connectHost);
if (def->data.udp.connectService)
virBufferEscapeString(buf, " service='%s'", def->data.udp.connectService); virBufferEscapeString(buf, " service='%s'", def->data.udp.connectService);
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }

View File

@ -29,7 +29,7 @@
<target type='virtio' name='test3'/> <target type='virtio' name='test3'/>
</channel> </channel>
<channel type='udp'> <channel type='udp'>
<source mode='bind'/> <source mode='bind' host='localhost'/>
<source mode='connect' service='5678'/> <source mode='connect' service='5678'/>
<target type='virtio' name='test4'/> <target type='virtio' name='test4'/>
</channel> </channel>