]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-device/device-monitor.c
tree-wide: make sure our control buffers are properly aligned
[thirdparty/systemd.git] / src / libsystemd / sd-device / device-monitor.c
index b86932663e753c3a1fd6f56647d7b77de773ac1a..20a422c77cf347add270c7d417b486ab2ee62c70 100644 (file)
@@ -3,7 +3,7 @@
 #include <errno.h>
 #include <linux/filter.h>
 #include <linux/netlink.h>
-#include <sys/socket.h>
+#include <unistd.h>
 
 #include "sd-device.h"
 #include "sd-event.h"
@@ -17,7 +17,6 @@
 #include "format-util.h"
 #include "hashmap.h"
 #include "io-util.h"
-#include "missing.h"
 #include "mountpoint-util.h"
 #include "set.h"
 #include "socket-util.h"
@@ -93,14 +92,8 @@ _public_ int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, siz
         assert_return(m, -EINVAL);
         assert_return((size_t) n == size, -EINVAL);
 
-        if (m->bound)
-                return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
-                                       "sd-device-monitor: Socket fd is already bound. "
-                                       "It may be dangerous to change buffer size. "
-                                       "Refusing to change buffer size.");
-
-        if (setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUF, n) < 0) {
-                r = setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUFFORCE, n);
+        if (setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUFFORCE, n) < 0) {
+                r = setsockopt_int(m->sock, SOL_SOCKET, SO_RCVBUF, n);
                 if (r < 0)
                         return r;
         }
@@ -368,13 +361,13 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) {
                 .iov_base = &buf,
                 .iov_len = sizeof(buf)
         };
-        char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
+        CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred))) control;
         union sockaddr_union snl;
         struct msghdr smsg = {
                 .msg_iov = &iov,
                 .msg_iovlen = 1,
-                .msg_control = cred_msg,
-                .msg_controllen = sizeof(cred_msg),
+                .msg_control = &control,
+                .msg_controllen = sizeof(control),
                 .msg_name = &snl,
                 .msg_namelen = sizeof(snl),
         };
@@ -754,7 +747,7 @@ _public_ int sd_device_monitor_filter_remove(sd_device_monitor *m) {
         m->subsystem_filter = hashmap_free_free_free(m->subsystem_filter);
         m->tag_filter = set_free_free(m->tag_filter);
 
-        if (setsockopt(m->sock, SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof(filter)) < 0)
+        if (setsockopt(m->sock, SOL_SOCKET, SO_DETACH_FILTER, &filter, sizeof(filter)) < 0)
                 return -errno;
 
         m->filter_uptodate = true;