]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virlease: Allow infinite lease expiry time
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Dec 2020 15:09:11 +0000 (16:09 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 4 Jan 2021 14:33:31 +0000 (15:33 +0100)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virlease.c

index edfdc6477aeafe1a30c0edb2f01e4b22f7dd79cb..3d68bb660cc13784ba11822d427d42d429d08fd9 100644 (file)
@@ -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;