diff options
author | 2011-06-28 14:07:46 +0200 | |
---|---|---|
committer | 2011-06-29 02:04:55 +0200 | |
commit | eb9dee2b1022f08cf30fa9aea9ebb0565844f9df (patch) | |
tree | ee9d2564ecced339448dc6d84f2e1658a002672a | |
parent | network: Fix dnsmasq hostsfile creation logic and related tests (diff) | |
download | libvirt-eb9dee2b1022f08cf30fa9aea9ebb0565844f9df.tar.gz libvirt-eb9dee2b1022f08cf30fa9aea9ebb0565844f9df.tar.bz2 libvirt-eb9dee2b1022f08cf30fa9aea9ebb0565844f9df.zip |
network: Don't ignore errors in dnsmasq config file creation
-rw-r--r-- | src/network/bridge_driver.c | 23 | ||||
-rw-r--r-- | src/util/dnsmasq.c | 10 | ||||
-rw-r--r-- | src/util/dnsmasq.h | 4 |
3 files changed, 19 insertions, 18 deletions
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f0cf122d3..660dd6511 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -446,7 +446,8 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx, for (i = 0; i < ipdef->nhosts; i++) { virNetworkDHCPHostDefPtr host = &(ipdef->hosts[i]); if ((host->mac) && VIR_SOCKET_HAS_ADDR(&host->ip)) - dnsmasqAddDhcpHost(dctx, host->mac, &host->ip, host->name); + if (dnsmasqAddDhcpHost(dctx, host->mac, &host->ip, host->name) < 0) + return -1; } if (dnsdef) { @@ -454,7 +455,8 @@ networkBuildDnsmasqHostsfile(dnsmasqContext *dctx, virNetworkDNSHostsDefPtr host = &(dnsdef->hosts[i]); if (VIR_SOCKET_HAS_ADDR(&host->ip)) { for (j = 0; j < host->nnames; j++) - dnsmasqAddHost(dctx, &host->ip, host->names[j]); + if (dnsmasqAddHost(dctx, &host->ip, host->names[j]) < 0) + return -1; } } } @@ -604,14 +606,15 @@ networkBuildDnsmasqArgv(virNetworkObjPtr network, if (network->def->domain) virCommandAddArg(cmd, "--expand-hosts"); - if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) >= 0) { - if (dctx->hostsfile->nhosts) - virCommandAddArgPair(cmd, "--dhcp-hostsfile", - dctx->hostsfile->path); - if (dctx->addnhostsfile->nhosts) - virCommandAddArgPair(cmd, "--addn-hosts", - dctx->addnhostsfile->path); - } + if (networkBuildDnsmasqHostsfile(dctx, ipdef, network->def->dns) < 0) + goto cleanup; + + if (dctx->hostsfile->nhosts) + virCommandAddArgPair(cmd, "--dhcp-hostsfile", + dctx->hostsfile->path); + if (dctx->addnhostsfile->nhosts) + virCommandAddArgPair(cmd, "--addn-hosts", + dctx->addnhostsfile->path); if (ipdef->tftproot) { virCommandAddArgList(cmd, "--enable-tftp", diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c index 4bdbb4416..5baa34f6c 100644 --- a/src/util/dnsmasq.c +++ b/src/util/dnsmasq.c @@ -502,14 +502,13 @@ dnsmasqContextFree(dnsmasqContext *ctx) * * Add dhcp-host entry. */ -void +int dnsmasqAddDhcpHost(dnsmasqContext *ctx, const char *mac, virSocketAddr *ip, const char *name) { - if (ctx->hostsfile) - hostsfileAdd(ctx->hostsfile, mac, ip, name); + return hostsfileAdd(ctx->hostsfile, mac, ip, name); } /* @@ -521,13 +520,12 @@ dnsmasqAddDhcpHost(dnsmasqContext *ctx, * Add additional host entry. */ -void +int dnsmasqAddHost(dnsmasqContext *ctx, virSocketAddr *ip, const char *name) { - if (ctx->addnhostsfile) - addnhostsAdd(ctx->addnhostsfile, ip, name); + return addnhostsAdd(ctx->addnhostsfile, ip, name); } /** diff --git a/src/util/dnsmasq.h b/src/util/dnsmasq.h index 62f6f38f2..d16a54fb8 100644 --- a/src/util/dnsmasq.h +++ b/src/util/dnsmasq.h @@ -68,11 +68,11 @@ typedef struct dnsmasqContext * dnsmasqContextNew(const char *network_name, const char *config_dir); void dnsmasqContextFree(dnsmasqContext *ctx); -void dnsmasqAddDhcpHost(dnsmasqContext *ctx, +int dnsmasqAddDhcpHost(dnsmasqContext *ctx, const char *mac, virSocketAddr *ip, const char *name); -void dnsmasqAddHost(dnsmasqContext *ctx, +int dnsmasqAddHost(dnsmasqContext *ctx, virSocketAddr *ip, const char *name); int dnsmasqSave(const dnsmasqContext *ctx); |