On 10/22/2013 04:57 PM, Nehal J Wani wrote: > On Tue, Oct 22, 2013 at 9:10 PM, Eric Blake <eblake@xxxxxxxxxx> wrote: >> On 10/22/2013 04:15 PM, Daniel P. Berrange wrote: >>> On Tue, Oct 22, 2013 at 04:15:37PM +0530, Nehal J Wani wrote: >>>> Q1. The --dhcp-script option will require libvirt to provide a script >>>> or executable file to be run. Now as the man page says, this file is >>>> executed "Whenever a new DHCP ease is created, or an old one >>>> destroyed". Life was easy with the script, as it used the command sed >>>> to remove the destroyed lease. eblake had suggested me to use a C >>>> program instead. So I wanted to finalize whether to go with C or >>>> continue with shell script. >>> >>> Libvirt aims to avoid shell code whereever possible, since it is really >>> a very bad language from terms of reliability and security. eg quoting >>> rules are easy to get wrong, error handling is awful, portability is >>> non-trivial. >> >> For examples of writing a helper C program, see how src/util/iohelper.c >> is compiled into libvirt_iohelper. >> > > What are libvirt's views on python as a helper program? C would be better: we want libvirtd to run even on systems that don't have python installed. But if you can demonstrate what you want your program to do by first mocking it up in a different language to get the management of file handling between your program and libvirtd correct, and only then convert to a proper C program, it wouldn't be the end of the world. >>> Ideally do not invent any new format - use a format that we already >>> have a parser for - eg the src/util/virconf.h or src/util/virkeyfile.h >>> APIs for loading configs. >> >> or XML, if the config file format is insufficient. >> > > Actually, the leases file generated by dnsmasq follows the format of > space separated parameters (For which I had created a parser in the > earlier versions of the patch). But considering the fact that each > time the script is called, in case the first argument is "del" or > "old" I'll need to replace the existing lease with the new one, for > which I am a bit confused as to which format should be followed and > whether it would be easier to code it in C (I can't think of anything > easier than loading the whole file into buffer and then replacing the > corresponding line, and then writing back to the file { Hoping that > existing semaphores will take care of the reader-writers problem :) } > ). Is life more easy handling XML, or ini-style formats (using the > existing helpers)? I guess it all depends on what sort of data you are trying to store in the file for reuse by libvirt the next time it parses the file. Reusing your code that directly parsed the dnsmasq file by making your file use the same format is probably an acceptable form of reuse, as long as we are relatively sure that there is no way to introduce ambiguity in the parse due to crazy user naming conventions. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list