923a60
From dfd0017561730f675d65cc826815ce7c932892aa Mon Sep 17 00:00:00 2001
923a60
From: Tom Gundersen <teg@jklm.no>
923a60
Date: Wed, 11 Mar 2015 22:23:38 +0100
923a60
Subject: [PATCH] libudev: monitor - fix error path in send_device
923a60
923a60
Return -errno rather than -1 in case sendmsg() fails.
923a60
923a60
(cherry picked from commit a4445e88cece0444c66d70876b03065158dd4685)
923a60
---
923a60
 src/libudev/libudev-monitor.c | 10 +++++++++-
923a60
 1 file changed, 9 insertions(+), 1 deletion(-)
923a60
923a60
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
923a60
index 3f1fee7f7e..d0486e3d1e 100644
923a60
--- a/src/libudev/libudev-monitor.c
923a60
+++ b/src/libudev/libudev-monitor.c
923a60
@@ -749,12 +749,20 @@ int udev_monitor_send_device(struct udev_monitor *udev_monitor,
923a60
          * If we send to a multicast group, we will get
923a60
          * ECONNREFUSED, which is expected.
923a60
          */
923a60
-        if (destination != NULL)
923a60
+        if (destination)
923a60
                 smsg.msg_name = &destination->snl;
923a60
         else
923a60
                 smsg.msg_name = &udev_monitor->snl_destination;
923a60
         smsg.msg_namelen = sizeof(struct sockaddr_nl);
923a60
         count = sendmsg(udev_monitor->sock, &smsg, 0);
923a60
+        if (count < 0) {
923a60
+                if (!destination && errno == ECONNREFUSED) {
923a60
+                        log_debug("passed unknown number of bytes to netlink monitor %p", udev_monitor);
923a60
+                        return 0;
923a60
+                } else
923a60
+                        return -errno;
923a60
+        }
923a60
+
923a60
         log_debug("passed %zi bytes to netlink monitor %p", count, udev_monitor);
923a60
         return count;
923a60
 }