When adding a new lease by our leaseshelper then virLeaseNew() is
called. Here, we check for DNSMASQ_LEASE_EXPIRES environment
variable which is the expiration time for the lease. For infinite
lease time the value is zero. However, our code is not prepared
for that and adds "expiry-time" into the JSON file only if lease
expiry time is non-zero. This breaks the assumption that the
"expiry-time" attribute is always present (as can be seen in
virLeaseReadCustomLeaseFile() and virLeasePrintLeases()).
Store "expiry-time" always.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/util/virlease.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/util/virlease.c b/src/util/virlease.c
index edfdc6477a..3d68bb660c 100644
--- a/src/util/virlease.c
+++ b/src/util/virlease.c
@@ -227,14 +227,13 @@ virLeaseNew(virJSONValuePtr *lease_ret,
/* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES
* (dnsmasq < 2.52) */
virTrimSpaces(exptime, NULL);
- }
- if (!exptime ||
- virStrToLong_ll(exptime, NULL, 10, &expirytime) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Unable to convert lease expiry time to long long:
%s"),
- NULLSTR(exptime));
- return -1;
+ if (virStrToLong_ll(exptime, NULL, 10, &expirytime) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to convert lease expiry time to long long:
%s"),
+ NULLSTR(exptime));
+ return -1;
+ }
}
/* Create new lease */
@@ -252,7 +251,7 @@ virLeaseNew(virJSONValuePtr *lease_ret,
return -1;
if (server_duid && virJSONValueObjectAppendString(lease_new,
"server-duid", server_duid) < 0)
return -1;
- if (expirytime && virJSONValueObjectAppendNumberLong(lease_new,
"expiry-time", expirytime) < 0)
+ if (virJSONValueObjectAppendNumberLong(lease_new, "expiry-time",
expirytime) < 0)
return -1;
*lease_ret = lease_new;
--
2.26.2