[PATCH 3/3] leaseshelper: Report more errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Some functions or code paths that may fail don't report error
(e.g. when acquiring PID file fails) leading to a silent quit
of the leaseshelper. This makes it super hard for us and users
to debug what is happening. Fortunately, dnsmasq captures both
stdout and stderr so we can write an error message there.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/network/leaseshelper.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index c4258cae4e..947f838126 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -131,8 +131,10 @@ main(int argc, char **argv)
      * events for expired leases. So, libvirtd sets another env var for this
      * purpose */
     if (!interface &&
-        !(interface = getenv("VIR_BRIDGE_NAME")))
-        goto cleanup;
+        !(interface = getenv("VIR_BRIDGE_NAME"))) {
+        fprintf(stderr, _("interface not set\n"));
+        exit(EXIT_FAILURE);
+    }
 
     ip = argv[3];
     mac = argv[2];
@@ -160,13 +162,21 @@ main(int argc, char **argv)
     pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
 
     /* Try to claim the pidfile, exiting if we can't */
-    if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0)
+    if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0) {
+        fprintf(stderr,
+                _("Unable to acquire PID file: %s\n errno=%d"),
+                pid_file, errno);
         goto cleanup;
+    }
 
     /* Since interfaces can be hot plugged, we need to make sure that the
      * corresponding custom lease file exists. If not, 'touch' it */
-    if (virFileTouch(custom_lease_file, 0644) < 0)
+    if (virFileTouch(custom_lease_file, 0644) < 0) {
+        fprintf(stderr,
+                _("Unable to create: %s\n errno=%d"),
+                custom_lease_file, errno);
         goto cleanup;
+    }
 
     switch ((enum virLeaseActionFlags) action) {
     case VIR_LEASE_ACTION_ADD:
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux