[libvirt] [PATCH 5/6] leaseshelper: split out virLeaseNewFromArgv
Daniel P. Berrange
berrange at redhat.com
Tue Jan 19 10:14:33 UTC 2016
On Tue, Jan 19, 2016 at 10:54:04AM +0100, Ján Tomko wrote:
> For the actions ADD and OLD, split out creating the new lease object,
> along with processing all the program args and environment variables
> that are only needed in this case.
> ---
> src/network/leaseshelper.c | 156 ++++++++++++++++++++++++++-------------------
> 1 file changed, 91 insertions(+), 65 deletions(-)
>
> diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
> index eb1c0c7..547e1d8 100644
> --- a/src/network/leaseshelper.c
> +++ b/src/network/leaseshelper.c
> @@ -281,22 +281,102 @@ virLeasePrintLeases(virJSONValuePtr leases_array_new,
> return ret;
> }
>
> +static int
> +virLeaseNewFromArgv(virJSONValuePtr *lease_ret,
> + int argc,
> + char **argv,
I would have a slight preference for keeping argc/argv only
referenced in main, and instead pass in the named parameters
for the bits you need here, but not the end of the world.
> + const char *ip,
> + const char *server_duid)
> +{
> + virJSONValuePtr lease_new = NULL;
> + const char *clientid = virGetEnvAllowSUID("DNSMASQ_CLIENT_ID");
> + const char *exptime_tmp = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES");
> + const char *hostname = virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME");
> + const char *iaid = virGetEnvAllowSUID("DNSMASQ_IAID");
> + const char *mac = NULL;
> + long long expirytime = 0;
> + char *exptime = NULL;
> + int ret = -1;
> +
> + /* In case hostname is known, it is the 5th argument */
> + if (argc == 5)
> + hostname = argv[4];
> +
> + /* In case hostname is still unknown, use the last known one */
> + if (!hostname)
> + hostname = virGetEnvAllowSUID("DNSMASQ_OLD_HOSTNAME");
> +
> + /* Check if it is an IPv6 lease */
> + if (iaid) {
> + mac = virGetEnvAllowSUID("DNSMASQ_MAC");
> + clientid = argv[2];
> + } else {
> + mac = argv[2];
> + }
ACK
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list