[libvirt] [PATCH] virt-xml-validate: Allow input to be read from stdin

Johannes Holmberg johannes.holmberg at dataductus.se
Mon May 20 13:02:36 UTC 2019


On Mon, 2019-05-20 at 14:18 +0200, Martin Kletzander wrote:
> On Mon, May 20, 2019 at 11:57:13AM +0000, Johannes Holmberg wrote:
> > ---
> > 
> > Hello,
> > 
> > This is an updated version of a patch I submitted on 2015-06-10. I
> > got
> > some feedback on it but then moved on to a different project and
> > forgot about it. Anyway, I've updated the patch according to the
> > feedback so if you are still interested, here it is! :)
> > 
> 
> Hi, thanks for the patch.  Wouldn't it be easier and cleaner if we
> just did:
> 
> if [ "$XMLFILE" = "-" ]; then
>   XMLFILE=/dev/stdin
> fi
> 
> ??

I tried it but the problem is that if the SCHEMA-NAME argument is not
supplied, the validation needs two passes, one to read the root tag,
and another one to do the actual xml validation. If I use /dev/stdin
the second pass will (sometimes) fail because the input is already
exhausted.

It works if the input is redirected from a file:

$ ./virt-xml-validate - < asdf.xml 
/dev/stdin validates

But if I pipe it from another program it fails:

$ cat asdf.xml | ./virt-xml-validate -
/dev/stdin:1: parser error : Document is empty

 /Johannes





More information about the libvir-list mailing list