1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <linux/filter.h>
5 #include <linux/netlink.h>
11 #include <sys/socket.h>
16 #include "alloc-util.h"
19 #include "format-util.h"
20 #include "libudev-private.h"
21 #include "libudev-device-internal.h"
23 #include "mount-util.h"
24 #include "socket-util.h"
25 #include "string-util.h"
28 * SECTION:libudev-monitor
29 * @short_description: device event source
31 * Connects to a device event source.
37 * Opaque object handling an event source.
43 union sockaddr_union snl
;
44 union sockaddr_union snl_trusted_sender
;
45 union sockaddr_union snl_destination
;
47 struct udev_list filter_subsystem_list
;
48 struct udev_list filter_tag_list
;
52 enum udev_monitor_netlink_group
{
58 #define UDEV_MONITOR_MAGIC 0xfeedcafe
59 struct udev_monitor_netlink_header
{
60 /* "libudev" prefix to distinguish libudev and kernel messages */
63 * magic to protect against daemon <-> library message format mismatch
64 * used in the kernel from socket filter rules; needs to be stored in network order
67 /* total length of header structure known to the sender */
69 /* properties string buffer */
70 unsigned properties_off
;
71 unsigned properties_len
;
73 * hashes of primary device properties strings, to let libudev subscribers
74 * use in-kernel socket filters; values need to be stored in network order
76 unsigned filter_subsystem_hash
;
77 unsigned filter_devtype_hash
;
78 unsigned filter_tag_bloom_hi
;
79 unsigned filter_tag_bloom_lo
;
82 static struct udev_monitor
*udev_monitor_new(struct udev
*udev
) {
83 struct udev_monitor
*udev_monitor
;
85 udev_monitor
= new0(struct udev_monitor
, 1);
86 if (udev_monitor
== NULL
) {
90 udev_monitor
->n_ref
= 1;
91 udev_monitor
->udev
= udev
;
92 udev_list_init(udev
, &udev_monitor
->filter_subsystem_list
, false);
93 udev_list_init(udev
, &udev_monitor
->filter_tag_list
, true);
97 static void monitor_set_nl_address(struct udev_monitor
*udev_monitor
) {
98 union sockaddr_union snl
;
102 assert(udev_monitor
);
104 /* get the address the kernel has assigned us
105 * it is usually, but not necessarily the pid
107 addrlen
= sizeof(struct sockaddr_nl
);
108 r
= getsockname(udev_monitor
->sock
, &snl
.sa
, &addrlen
);
110 udev_monitor
->snl
.nl
.nl_pid
= snl
.nl
.nl_pid
;
113 struct udev_monitor
*udev_monitor_new_from_netlink_fd(struct udev
*udev
, const char *name
, int fd
) {
114 struct udev_monitor
*udev_monitor
;
118 group
= UDEV_MONITOR_NONE
;
119 else if (streq(name
, "udev")) {
121 * We do not support subscribing to uevents if no instance of
122 * udev is running. Uevents would otherwise broadcast the
123 * processing data of the host into containers, which is not
126 * Containers will currently not get any udev uevents, until
127 * a supporting infrastructure is available.
129 * We do not set a netlink multicast group here, so the socket
130 * will not receive any messages.
132 if (access("/run/udev/control", F_OK
) < 0 && dev_is_devtmpfs() <= 0) {
133 log_debug("the udev service seems not to be active, disable the monitor");
134 group
= UDEV_MONITOR_NONE
;
136 group
= UDEV_MONITOR_UDEV
;
137 } else if (streq(name
, "kernel"))
138 group
= UDEV_MONITOR_KERNEL
;
144 udev_monitor
= udev_monitor_new(udev
);
145 if (udev_monitor
== NULL
)
149 udev_monitor
->sock
= socket(PF_NETLINK
, SOCK_RAW
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, NETLINK_KOBJECT_UEVENT
);
150 if (udev_monitor
->sock
< 0) {
151 log_debug_errno(errno
, "error getting socket: %m");
152 return mfree(udev_monitor
);
155 udev_monitor
->bound
= true;
156 udev_monitor
->sock
= fd
;
157 monitor_set_nl_address(udev_monitor
);
160 udev_monitor
->snl
.nl
.nl_family
= AF_NETLINK
;
161 udev_monitor
->snl
.nl
.nl_groups
= group
;
163 /* default destination for sending */
164 udev_monitor
->snl_destination
.nl
.nl_family
= AF_NETLINK
;
165 udev_monitor
->snl_destination
.nl
.nl_groups
= UDEV_MONITOR_UDEV
;
171 * udev_monitor_new_from_netlink:
172 * @udev: udev library context
173 * @name: name of event source
175 * Create new udev monitor and connect to a specified event
176 * source. Valid sources identifiers are "udev" and "kernel".
178 * Applications should usually not connect directly to the
179 * "kernel" events, because the devices might not be useable
180 * at that time, before udev has configured them, and created
181 * device nodes. Accessing devices at the same time as udev,
182 * might result in unpredictable behavior. The "udev" events
183 * are sent out after udev has finished its event processing,
184 * all rules have been processed, and needed device nodes are
187 * The initial refcount is 1, and needs to be decremented to
188 * release the resources of the udev monitor.
190 * Returns: a new udev monitor, or #NULL, in case of an error
192 _public_
struct udev_monitor
*udev_monitor_new_from_netlink(struct udev
*udev
, const char *name
) {
193 return udev_monitor_new_from_netlink_fd(udev
, name
, -1);
196 static void bpf_stmt(struct sock_filter
*ins
, unsigned *i
,
197 unsigned short code
, unsigned data
) {
198 ins
[(*i
)++] = (struct sock_filter
) {
204 static void bpf_jmp(struct sock_filter
*ins
, unsigned *i
,
205 unsigned short code
, unsigned data
,
206 unsigned short jt
, unsigned short jf
) {
207 ins
[(*i
)++] = (struct sock_filter
) {
216 * udev_monitor_filter_update:
217 * @udev_monitor: monitor
219 * Update the installed socket filter. This is only needed,
220 * if the filter was removed or changed.
222 * Returns: 0 on success, otherwise a negative error value.
224 _public_
int udev_monitor_filter_update(struct udev_monitor
*udev_monitor
)
226 struct sock_filter ins
[512];
227 struct sock_fprog filter
;
229 struct udev_list_entry
*list_entry
;
232 if (udev_list_get_entry(&udev_monitor
->filter_subsystem_list
) == NULL
&&
233 udev_list_get_entry(&udev_monitor
->filter_tag_list
) == NULL
)
236 memzero(ins
, sizeof(ins
));
239 /* load magic in A */
240 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(struct udev_monitor_netlink_header
, magic
));
241 /* jump if magic matches */
242 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, UDEV_MONITOR_MAGIC
, 1, 0);
243 /* wrong magic, pass packet */
244 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
246 if (udev_list_get_entry(&udev_monitor
->filter_tag_list
) != NULL
) {
249 /* count tag matches, to calculate end of tag match block */
251 udev_list_entry_foreach(list_entry
, udev_list_get_entry(&udev_monitor
->filter_tag_list
))
254 /* add all tags matches */
255 udev_list_entry_foreach(list_entry
, udev_list_get_entry(&udev_monitor
->filter_tag_list
)) {
256 uint64_t tag_bloom_bits
= util_string_bloom64(udev_list_entry_get_name(list_entry
));
257 uint32_t tag_bloom_hi
= tag_bloom_bits
>> 32;
258 uint32_t tag_bloom_lo
= tag_bloom_bits
& 0xffffffff;
260 /* load device bloom bits in A */
261 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(struct udev_monitor_netlink_header
, filter_tag_bloom_hi
));
262 /* clear bits (tag bits & bloom bits) */
263 bpf_stmt(ins
, &i
, BPF_ALU
|BPF_AND
|BPF_K
, tag_bloom_hi
);
264 /* jump to next tag if it does not match */
265 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, tag_bloom_hi
, 0, 3);
267 /* load device bloom bits in A */
268 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(struct udev_monitor_netlink_header
, filter_tag_bloom_lo
));
269 /* clear bits (tag bits & bloom bits) */
270 bpf_stmt(ins
, &i
, BPF_ALU
|BPF_AND
|BPF_K
, tag_bloom_lo
);
271 /* jump behind end of tag match block if tag matches */
273 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, tag_bloom_lo
, 1 + (tag_matches
* 6), 0);
276 /* nothing matched, drop packet */
277 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0);
280 /* add all subsystem matches */
281 if (udev_list_get_entry(&udev_monitor
->filter_subsystem_list
) != NULL
) {
282 udev_list_entry_foreach(list_entry
, udev_list_get_entry(&udev_monitor
->filter_subsystem_list
)) {
283 uint32_t hash
= util_string_hash32(udev_list_entry_get_name(list_entry
));
285 /* load device subsystem value in A */
286 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(struct udev_monitor_netlink_header
, filter_subsystem_hash
));
287 if (udev_list_entry_get_value(list_entry
) == NULL
) {
288 /* jump if subsystem does not match */
289 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 1);
291 /* jump if subsystem does not match */
292 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 3);
294 /* load device devtype value in A */
295 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(struct udev_monitor_netlink_header
, filter_devtype_hash
));
296 /* jump if value does not match */
297 hash
= util_string_hash32(udev_list_entry_get_value(list_entry
));
298 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 1);
301 /* matched, pass packet */
302 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
304 if (i
+1 >= ELEMENTSOF(ins
))
308 /* nothing matched, drop packet */
309 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0);
312 /* matched, pass packet */
313 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
316 memzero(&filter
, sizeof(filter
));
319 err
= setsockopt(udev_monitor
->sock
, SOL_SOCKET
, SO_ATTACH_FILTER
, &filter
, sizeof(filter
));
320 return err
< 0 ? -errno
: 0;
323 int udev_monitor_allow_unicast_sender(struct udev_monitor
*udev_monitor
, struct udev_monitor
*sender
)
325 udev_monitor
->snl_trusted_sender
.nl
.nl_pid
= sender
->snl
.nl
.nl_pid
;
330 * udev_monitor_enable_receiving:
331 * @udev_monitor: the monitor which should receive events
333 * Binds the @udev_monitor socket to the event source.
335 * Returns: 0 on success, otherwise a negative error value.
337 _public_
int udev_monitor_enable_receiving(struct udev_monitor
*udev_monitor
)
342 udev_monitor_filter_update(udev_monitor
);
344 if (!udev_monitor
->bound
) {
345 err
= bind(udev_monitor
->sock
,
346 &udev_monitor
->snl
.sa
, sizeof(struct sockaddr_nl
));
348 udev_monitor
->bound
= true;
352 monitor_set_nl_address(udev_monitor
);
354 return log_debug_errno(errno
, "bind failed: %m");
356 /* enable receiving of sender credentials */
357 err
= setsockopt(udev_monitor
->sock
, SOL_SOCKET
, SO_PASSCRED
, &on
, sizeof(on
));
359 log_debug_errno(errno
, "setting SO_PASSCRED failed: %m");
365 * udev_monitor_set_receive_buffer_size:
366 * @udev_monitor: the monitor which should receive events
367 * @size: the size in bytes
369 * Set the size of the kernel socket buffer. This call needs the
370 * appropriate privileges to succeed.
372 * Returns: 0 on success, otherwise -1 on error.
374 _public_
int udev_monitor_set_receive_buffer_size(struct udev_monitor
*udev_monitor
, int size
)
376 if (udev_monitor
== NULL
)
378 if (setsockopt(udev_monitor
->sock
, SOL_SOCKET
, SO_RCVBUFFORCE
, &size
, sizeof(size
)) < 0)
384 int udev_monitor_disconnect(struct udev_monitor
*udev_monitor
) {
385 assert(udev_monitor
);
387 udev_monitor
->sock
= safe_close(udev_monitor
->sock
);
391 static struct udev_monitor
*udev_monitor_free(struct udev_monitor
*udev_monitor
) {
392 assert(udev_monitor
);
394 udev_monitor_disconnect(udev_monitor
);
395 udev_list_cleanup(&udev_monitor
->filter_subsystem_list
);
396 udev_list_cleanup(&udev_monitor
->filter_tag_list
);
397 return mfree(udev_monitor
);
402 * @udev_monitor: udev monitor
404 * Take a reference of a udev monitor.
406 * Returns: the passed udev monitor
410 * udev_monitor_unref:
411 * @udev_monitor: udev monitor
413 * Drop a reference of a udev monitor. If the refcount reaches zero,
414 * the bound socket will be closed, and the resources of the monitor
419 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_monitor
, udev_monitor
, udev_monitor_free
);
422 * udev_monitor_get_udev:
423 * @udev_monitor: udev monitor
425 * Retrieve the udev library context the monitor was created with.
427 * Returns: the udev library context
429 _public_
struct udev
*udev_monitor_get_udev(struct udev_monitor
*udev_monitor
)
431 if (udev_monitor
== NULL
)
433 return udev_monitor
->udev
;
437 * udev_monitor_get_fd:
438 * @udev_monitor: udev monitor
440 * Retrieve the socket file descriptor associated with the monitor.
442 * Returns: the socket file descriptor
444 _public_
int udev_monitor_get_fd(struct udev_monitor
*udev_monitor
)
446 if (udev_monitor
== NULL
)
448 return udev_monitor
->sock
;
451 static int passes_filter(struct udev_monitor
*udev_monitor
, struct udev_device
*udev_device
)
453 struct udev_list_entry
*list_entry
;
455 if (udev_list_get_entry(&udev_monitor
->filter_subsystem_list
) == NULL
)
457 udev_list_entry_foreach(list_entry
, udev_list_get_entry(&udev_monitor
->filter_subsystem_list
)) {
458 const char *subsys
= udev_list_entry_get_name(list_entry
);
459 const char *dsubsys
= udev_device_get_subsystem(udev_device
);
461 const char *ddevtype
;
463 if (!streq(dsubsys
, subsys
))
466 devtype
= udev_list_entry_get_value(list_entry
);
469 ddevtype
= udev_device_get_devtype(udev_device
);
470 if (ddevtype
== NULL
)
472 if (streq(ddevtype
, devtype
))
478 if (udev_list_get_entry(&udev_monitor
->filter_tag_list
) == NULL
)
480 udev_list_entry_foreach(list_entry
, udev_list_get_entry(&udev_monitor
->filter_tag_list
)) {
481 const char *tag
= udev_list_entry_get_name(list_entry
);
483 if (udev_device_has_tag(udev_device
, tag
))
490 * udev_monitor_receive_device:
491 * @udev_monitor: udev monitor
493 * Receive data from the udev monitor socket, allocate a new udev
494 * device, fill in the received data, and return the device.
496 * Only socket connections with uid=0 are accepted.
498 * The monitor socket is by default set to NONBLOCK. A variant of poll() on
499 * the file descriptor returned by udev_monitor_get_fd() should to be used to
500 * wake up when new devices arrive, or alternatively the file descriptor
501 * switched into blocking mode.
503 * The initial refcount is 1, and needs to be decremented to
504 * release the resources of the udev device.
506 * Returns: a new udev device, or #NULL, in case of an error
508 _public_
struct udev_device
*udev_monitor_receive_device(struct udev_monitor
*udev_monitor
)
510 struct udev_device
*udev_device
;
513 char cred_msg
[CMSG_SPACE(sizeof(struct ucred
))];
514 struct cmsghdr
*cmsg
;
515 union sockaddr_union snl
;
518 struct udev_monitor_netlink_header nlh
;
523 bool is_initialized
= false;
526 if (udev_monitor
== NULL
) {
531 iov
.iov_len
= sizeof(buf
);
532 memzero(&smsg
, sizeof(struct msghdr
));
535 smsg
.msg_control
= cred_msg
;
536 smsg
.msg_controllen
= sizeof(cred_msg
);
537 smsg
.msg_name
= &snl
;
538 smsg
.msg_namelen
= sizeof(snl
);
540 buflen
= recvmsg(udev_monitor
->sock
, &smsg
, 0);
543 log_debug("unable to receive message");
547 if (buflen
< 32 || (smsg
.msg_flags
& MSG_TRUNC
)) {
548 log_debug("invalid message length");
553 if (snl
.nl
.nl_groups
== 0) {
554 /* unicast message, check if we trust the sender */
555 if (udev_monitor
->snl_trusted_sender
.nl
.nl_pid
== 0 ||
556 snl
.nl
.nl_pid
!= udev_monitor
->snl_trusted_sender
.nl
.nl_pid
) {
557 log_debug("unicast netlink message ignored");
561 } else if (snl
.nl
.nl_groups
== UDEV_MONITOR_KERNEL
) {
562 if (snl
.nl
.nl_pid
> 0) {
563 log_debug("multicast kernel netlink message from PID %"PRIu32
" ignored",
570 cmsg
= CMSG_FIRSTHDR(&smsg
);
571 if (cmsg
== NULL
|| cmsg
->cmsg_type
!= SCM_CREDENTIALS
) {
572 log_debug("no sender credentials received, message ignored");
577 cred
= (struct ucred
*)CMSG_DATA(cmsg
);
578 if (cred
->uid
!= 0) {
579 log_debug("sender uid="UID_FMT
", message ignored", cred
->uid
);
584 if (memcmp(buf
.raw
, "libudev", 8) == 0) {
585 /* udev message needs proper version magic */
586 if (buf
.nlh
.magic
!= htobe32(UDEV_MONITOR_MAGIC
)) {
587 log_debug("unrecognized message signature (%x != %x)",
588 buf
.nlh
.magic
, htobe32(UDEV_MONITOR_MAGIC
));
592 if (buf
.nlh
.properties_off
+32 > (size_t)buflen
) {
593 log_debug("message smaller than expected (%u > %zd)",
594 buf
.nlh
.properties_off
+32, buflen
);
599 bufpos
= buf
.nlh
.properties_off
;
601 /* devices received from udev are always initialized */
602 is_initialized
= true;
604 /* kernel message with header */
605 bufpos
= strlen(buf
.raw
) + 1;
606 if ((size_t)bufpos
< sizeof("a@/d") || bufpos
>= buflen
) {
607 log_debug("invalid message length");
612 /* check message header */
613 if (strstr(buf
.raw
, "@/") == NULL
) {
614 log_debug("unrecognized message header");
620 udev_device
= udev_device_new_from_nulstr(udev_monitor
->udev
, &buf
.raw
[bufpos
], buflen
- bufpos
);
622 log_debug_errno(errno
, "could not create device: %m");
627 udev_device_set_is_initialized(udev_device
);
629 /* skip device, if it does not pass the current filter */
630 if (!passes_filter(udev_monitor
, udev_device
)) {
631 struct pollfd pfd
[1];
634 udev_device_unref(udev_device
);
636 /* if something is queued, get next device */
637 pfd
[0].fd
= udev_monitor
->sock
;
638 pfd
[0].events
= POLLIN
;
639 rc
= poll(pfd
, 1, 0);
650 int udev_monitor_receive_sd_device(struct udev_monitor
*udev_monitor
, sd_device
**ret
) {
651 _cleanup_(udev_device_unrefp
) struct udev_device
*udev_device
= NULL
;
655 udev_device
= udev_monitor_receive_device(udev_monitor
);
659 *ret
= sd_device_ref(udev_device
->device
);
663 int udev_monitor_send_device(struct udev_monitor
*udev_monitor
,
664 struct udev_monitor
*destination
, struct udev_device
*udev_device
)
666 const char *buf
, *val
;
668 struct udev_monitor_netlink_header nlh
= {
670 .magic
= htobe32(UDEV_MONITOR_MAGIC
),
671 .header_size
= sizeof nlh
,
673 struct iovec iov
[2] = {
674 { .iov_base
= &nlh
, .iov_len
= sizeof nlh
},
676 struct msghdr smsg
= {
680 struct udev_list_entry
*list_entry
;
681 uint64_t tag_bloom_bits
;
683 blen
= udev_device_get_properties_monitor_buf(udev_device
, &buf
);
685 log_debug("device buffer is too small to contain a valid device");
689 /* fill in versioned header */
690 val
= udev_device_get_subsystem(udev_device
);
691 nlh
.filter_subsystem_hash
= htobe32(util_string_hash32(val
));
693 val
= udev_device_get_devtype(udev_device
);
695 nlh
.filter_devtype_hash
= htobe32(util_string_hash32(val
));
697 /* add tag bloom filter */
699 udev_list_entry_foreach(list_entry
, udev_device_get_tags_list_entry(udev_device
))
700 tag_bloom_bits
|= util_string_bloom64(udev_list_entry_get_name(list_entry
));
701 if (tag_bloom_bits
> 0) {
702 nlh
.filter_tag_bloom_hi
= htobe32(tag_bloom_bits
>> 32);
703 nlh
.filter_tag_bloom_lo
= htobe32(tag_bloom_bits
& 0xffffffff);
706 /* add properties list */
707 nlh
.properties_off
= iov
[0].iov_len
;
708 nlh
.properties_len
= blen
;
709 iov
[1].iov_base
= (char *)buf
;
710 iov
[1].iov_len
= blen
;
713 * Use custom address for target, or the default one.
715 * If we send to a multicast group, we will get
716 * ECONNREFUSED, which is expected.
719 smsg
.msg_name
= &destination
->snl
;
721 smsg
.msg_name
= &udev_monitor
->snl_destination
;
722 smsg
.msg_namelen
= sizeof(struct sockaddr_nl
);
723 count
= sendmsg(udev_monitor
->sock
, &smsg
, 0);
725 if (!destination
&& errno
== ECONNREFUSED
) {
726 log_debug("passed device to netlink monitor %p", udev_monitor
);
732 log_debug("passed %zi byte device to netlink monitor %p", count
, udev_monitor
);
737 * udev_monitor_filter_add_match_subsystem_devtype:
738 * @udev_monitor: the monitor
739 * @subsystem: the subsystem value to match the incoming devices against
740 * @devtype: the devtype value to match the incoming devices against
742 * This filter is efficiently executed inside the kernel, and libudev subscribers
743 * will usually not be woken up for devices which do not match.
745 * The filter must be installed before the monitor is switched to listening mode.
747 * Returns: 0 on success, otherwise a negative error value.
749 _public_
int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor
*udev_monitor
, const char *subsystem
, const char *devtype
)
751 if (udev_monitor
== NULL
)
753 if (subsystem
== NULL
)
755 if (udev_list_entry_add(&udev_monitor
->filter_subsystem_list
, subsystem
, devtype
) == NULL
)
761 * udev_monitor_filter_add_match_tag:
762 * @udev_monitor: the monitor
763 * @tag: the name of a tag
765 * This filter is efficiently executed inside the kernel, and libudev subscribers
766 * will usually not be woken up for devices which do not match.
768 * The filter must be installed before the monitor is switched to listening mode.
770 * Returns: 0 on success, otherwise a negative error value.
772 _public_
int udev_monitor_filter_add_match_tag(struct udev_monitor
*udev_monitor
, const char *tag
)
774 if (udev_monitor
== NULL
)
778 if (udev_list_entry_add(&udev_monitor
->filter_tag_list
, tag
, NULL
) == NULL
)
784 * udev_monitor_filter_remove:
785 * @udev_monitor: monitor
787 * Remove all filters from monitor.
789 * Returns: 0 on success, otherwise a negative error value.
791 _public_
int udev_monitor_filter_remove(struct udev_monitor
*udev_monitor
)
793 static const struct sock_fprog filter
= { 0, NULL
};
795 udev_list_cleanup(&udev_monitor
->filter_subsystem_list
);
796 if (setsockopt(udev_monitor
->sock
, SOL_SOCKET
, SO_ATTACH_FILTER
, &filter
, sizeof(filter
)) < 0)