mirror of
https://github.com/systemd/systemd.git
synced 2026-08-03 14:40:31 +00:00
Merge pull request #24289 from yuwata/sd-device-monitor-set-description
sd-device-monitor: introduce sd_device_monitor_{set,get}_description()
This commit is contained in:
@@ -785,6 +785,8 @@ global:
|
||||
sd_bus_error_setfv;
|
||||
|
||||
sd_device_new_child;
|
||||
sd_device_monitor_set_description;
|
||||
sd_device_monitor_get_description;
|
||||
|
||||
sd_id128_string_equal;
|
||||
|
||||
|
||||
@@ -28,6 +28,15 @@
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
#define log_monitor(m, format, ...) \
|
||||
log_debug("sd-device-monitor(%s): " format, strna(m ? m->description : NULL), ##__VA_ARGS__)
|
||||
#define log_monitor_errno(m, r, format, ...) \
|
||||
log_debug_errno(r, "sd-device-monitor(%s): " format, strna(m ? m->description : NULL), ##__VA_ARGS__)
|
||||
#define log_device_monitor(d, m, format, ...) \
|
||||
log_device_debug(d, "sd-device-monitor(%s): " format, strna(m ? m->description : NULL), ##__VA_ARGS__)
|
||||
#define log_device_monitor_errno(d, m, r, format, ...) \
|
||||
log_device_debug_errno(d, r, "sd-device-monitor(%s): " format, strna(m ? m->description : NULL), ##__VA_ARGS__)
|
||||
|
||||
struct sd_device_monitor {
|
||||
unsigned n_ref;
|
||||
|
||||
@@ -46,6 +55,7 @@ struct sd_device_monitor {
|
||||
|
||||
sd_event *event;
|
||||
sd_event_source *event_source;
|
||||
char *description;
|
||||
sd_device_monitor_handler_t callback;
|
||||
void *userdata;
|
||||
};
|
||||
@@ -139,14 +149,14 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
|
||||
* will not receive any messages.
|
||||
*/
|
||||
|
||||
log_debug("sd-device-monitor: The udev service seems not to be active, disabling the monitor");
|
||||
log_monitor(m, "The udev service seems not to be active, disabling the monitor.");
|
||||
group = MONITOR_GROUP_NONE;
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
sock = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC|SOCK_NONBLOCK, NETLINK_KOBJECT_UEVENT);
|
||||
if (sock < 0)
|
||||
return log_debug_errno(errno, "sd-device-monitor: Failed to create socket: %m");
|
||||
return log_monitor_errno(m, errno, "Failed to create socket: %m");
|
||||
}
|
||||
|
||||
m = new(sd_device_monitor, 1);
|
||||
@@ -164,7 +174,7 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
|
||||
if (fd >= 0) {
|
||||
r = monitor_set_nl_address(m);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "sd-device-monitor: Failed to set netlink address: %m");
|
||||
log_monitor_errno(m, r, "Failed to set netlink address: %m");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -179,12 +189,12 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
|
||||
|
||||
netns = ioctl(m->sock, SIOCGSKNS);
|
||||
if (netns < 0)
|
||||
log_debug_errno(errno, "sd-device-monitor: Unable to get network namespace of udev netlink socket, unable to determine if we are in host netns, ignoring: %m");
|
||||
log_monitor_errno(m, errno, "Unable to get network namespace of udev netlink socket, unable to determine if we are in host netns, ignoring: %m");
|
||||
else {
|
||||
struct stat a, b;
|
||||
|
||||
if (fstat(netns, &a) < 0) {
|
||||
r = log_debug_errno(errno, "sd-device-monitor: Failed to stat netns of udev netlink socket: %m");
|
||||
r = log_monitor_errno(m, errno, "Failed to stat netns of udev netlink socket: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -192,12 +202,12 @@ int device_monitor_new_full(sd_device_monitor **ret, MonitorNetlinkGroup group,
|
||||
if (ERRNO_IS_PRIVILEGE(errno))
|
||||
/* If we can't access PID1's netns info due to permissions, it's fine, this is a
|
||||
* safety check only after all. */
|
||||
log_debug_errno(errno, "sd-device-monitor: No permission to stat PID1's netns, unable to determine if we are in host netns, ignoring: %m");
|
||||
log_monitor_errno(m, errno, "No permission to stat PID1's netns, unable to determine if we are in host netns, ignoring: %m");
|
||||
else
|
||||
log_debug_errno(errno, "sd-device-monitor: Failed to stat PID1's netns, ignoring: %m");
|
||||
log_monitor_errno(m, errno, "Failed to stat PID1's netns, ignoring: %m");
|
||||
|
||||
} else if (!stat_inode_same(&a, &b))
|
||||
log_debug("sd-device-monitor: Netlink socket we listen on is not from host netns, we won't see device events.");
|
||||
log_monitor(m, "Netlink socket we listen on is not from host netns, we won't see device events.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +273,7 @@ _public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_han
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(m->event_source, "sd-device-monitor");
|
||||
(void) sd_event_source_set_description(m->event_source, m->description ?: "sd-device-monitor");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -306,6 +316,29 @@ _public_ sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *
|
||||
return m->event_source;
|
||||
}
|
||||
|
||||
_public_ int sd_device_monitor_set_description(sd_device_monitor *m, const char *description) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
r = free_and_strdup(&m->description, description);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
if (m->event_source)
|
||||
(void) sd_event_source_set_description(m->event_source, description);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
_public_ int sd_device_monitor_get_description(sd_device_monitor *m, const char **ret) {
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(ret, -EINVAL);
|
||||
|
||||
*ret = m->description;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int device_monitor_enable_receiving(sd_device_monitor *m) {
|
||||
int r;
|
||||
|
||||
@@ -313,22 +346,22 @@ int device_monitor_enable_receiving(sd_device_monitor *m) {
|
||||
|
||||
r = sd_device_monitor_filter_update(m);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "sd-device-monitor: Failed to update filter: %m");
|
||||
return log_monitor_errno(m, r, "Failed to update filter: %m");
|
||||
|
||||
if (!m->bound) {
|
||||
/* enable receiving of sender credentials */
|
||||
r = setsockopt_int(m->sock, SOL_SOCKET, SO_PASSCRED, true);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "sd-device-monitor: Failed to set socket option SO_PASSCRED: %m");
|
||||
return log_monitor_errno(m, r, "Failed to set socket option SO_PASSCRED: %m");
|
||||
|
||||
if (bind(m->sock, &m->snl.sa, sizeof(struct sockaddr_nl)) < 0)
|
||||
return log_debug_errno(errno, "sd-device-monitor: Failed to bind monitoring socket: %m");
|
||||
return log_monitor_errno(m, errno, "Failed to bind monitoring socket: %m");
|
||||
|
||||
m->bound = true;
|
||||
|
||||
r = monitor_set_nl_address(m);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "sd-device-monitor: Failed to set address: %m");
|
||||
return log_monitor_errno(m, r, "Failed to set address: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -339,6 +372,7 @@ static sd_device_monitor *device_monitor_free(sd_device_monitor *m) {
|
||||
|
||||
(void) sd_device_monitor_detach_event(m);
|
||||
|
||||
free(m->description);
|
||||
hashmap_free(m->subsystem_filter);
|
||||
set_free(m->tag_filter);
|
||||
hashmap_free(m->match_sysattr_filter);
|
||||
@@ -447,48 +481,48 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) {
|
||||
buflen = recvmsg(m->sock, &smsg, 0);
|
||||
if (buflen < 0) {
|
||||
if (!ERRNO_IS_TRANSIENT(errno))
|
||||
log_debug_errno(errno, "sd-device-monitor: Failed to receive message: %m");
|
||||
log_monitor_errno(m, errno, "Failed to receive message: %m");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (buflen < 32 || (smsg.msg_flags & MSG_TRUNC))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"sd-device-monitor: Invalid message length.");
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EINVAL), "Invalid message length.");
|
||||
|
||||
if (snl.nl.nl_groups == MONITOR_GROUP_NONE) {
|
||||
/* unicast message, check if we trust the sender */
|
||||
if (m->snl_trusted_sender.nl.nl_pid == 0 ||
|
||||
snl.nl.nl_pid != m->snl_trusted_sender.nl.nl_pid)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Unicast netlink message ignored.");
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Unicast netlink message ignored.");
|
||||
|
||||
} else if (snl.nl.nl_groups == MONITOR_GROUP_KERNEL) {
|
||||
if (snl.nl.nl_pid > 0)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Multicast kernel netlink message from PID %"PRIu32" ignored.", snl.nl.nl_pid);
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Multicast kernel netlink message from PID %"PRIu32" ignored.",
|
||||
snl.nl.nl_pid);
|
||||
}
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&smsg);
|
||||
if (!cmsg || cmsg->cmsg_type != SCM_CREDENTIALS)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: No sender credentials received, message ignored.");
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"No sender credentials received, ignoring message.");
|
||||
|
||||
cred = (struct ucred*) CMSG_DATA(cmsg);
|
||||
if (cred->uid != 0)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Sender uid="UID_FMT", message ignored.", cred->uid);
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Sender uid="UID_FMT", message ignored.", cred->uid);
|
||||
|
||||
if (streq(buf.raw, "libudev")) {
|
||||
/* udev message needs proper version magic */
|
||||
if (buf.nlh.magic != htobe32(UDEV_MONITOR_MAGIC))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Invalid message signature (%x != %x)",
|
||||
buf.nlh.magic, htobe32(UDEV_MONITOR_MAGIC));
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Invalid message signature (%x != %x).",
|
||||
buf.nlh.magic, htobe32(UDEV_MONITOR_MAGIC));
|
||||
|
||||
if (buf.nlh.properties_off+32 > (size_t) buflen)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Invalid message length (%u > %zd)",
|
||||
buf.nlh.properties_off+32, buflen);
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Invalid message length (%u > %zd).",
|
||||
buf.nlh.properties_off+32, buflen);
|
||||
|
||||
bufpos = buf.nlh.properties_off;
|
||||
|
||||
@@ -499,18 +533,18 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) {
|
||||
/* kernel message with header */
|
||||
bufpos = strlen(buf.raw) + 1;
|
||||
if ((size_t) bufpos < sizeof("a@/d") || bufpos >= buflen)
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Invalid message length");
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Invalid message length.");
|
||||
|
||||
/* check message header */
|
||||
if (!strstr(buf.raw, "@/"))
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
|
||||
"sd-device-monitor: Invalid message header");
|
||||
return log_monitor_errno(m, SYNTHETIC_ERRNO(EAGAIN),
|
||||
"Invalid message header.");
|
||||
}
|
||||
|
||||
r = device_new_from_nulstr(&device, &buf.raw[bufpos], buflen - bufpos);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "sd-device-monitor: Failed to create device from received message: %m");
|
||||
return log_monitor_errno(m, r, "Failed to create device from received message: %m");
|
||||
|
||||
if (is_initialized)
|
||||
device_set_is_initialized(device);
|
||||
@@ -518,9 +552,9 @@ int device_monitor_receive_device(sd_device_monitor *m, sd_device **ret) {
|
||||
/* Skip device, if it does not pass the current filter */
|
||||
r = passes_filter(m, device);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "sd-device-monitor: Failed to check received device passing filter: %m");
|
||||
return log_device_monitor_errno(device, m, r, "Failed to check received device passing filter: %m");
|
||||
if (r == 0)
|
||||
log_device_debug(device, "sd-device-monitor: Received device does not pass filter, ignoring");
|
||||
log_device_monitor(device, m, "Received device does not pass filter, ignoring.");
|
||||
else
|
||||
*ret = TAKE_PTR(device);
|
||||
|
||||
@@ -576,15 +610,15 @@ int device_monitor_send_device(
|
||||
|
||||
r = device_get_properties_nulstr(device, &buf, &blen);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "sd-device-monitor: Failed to get device properties: %m");
|
||||
return log_device_monitor_errno(device, m, r, "Failed to get device properties: %m");
|
||||
if (blen < 32)
|
||||
return log_device_debug_errno(device, SYNTHETIC_ERRNO(EINVAL),
|
||||
"sd-device-monitor: Length of device property nulstr is too small to contain valid device information");
|
||||
return log_device_monitor_errno(device, m, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Length of device property nulstr is too small to contain valid device information.");
|
||||
|
||||
/* fill in versioned header */
|
||||
r = sd_device_get_subsystem(device, &val);
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "sd-device-monitor: Failed to get device subsystem: %m");
|
||||
return log_device_monitor_errno(device, m, r, "Failed to get device subsystem: %m");
|
||||
nlh.filter_subsystem_hash = htobe32(string_hash32(val));
|
||||
|
||||
if (sd_device_get_devtype(device, &val) >= 0)
|
||||
@@ -616,13 +650,13 @@ int device_monitor_send_device(
|
||||
count = sendmsg(m->sock, &smsg, 0);
|
||||
if (count < 0) {
|
||||
if (!destination && errno == ECONNREFUSED) {
|
||||
log_device_debug(device, "sd-device-monitor: Passed to netlink monitor");
|
||||
log_device_monitor(device, m, "Passed to netlink monitor.");
|
||||
return 0;
|
||||
} else
|
||||
return log_device_debug_errno(device, errno, "sd-device-monitor: Failed to send device to netlink monitor: %m");
|
||||
return log_device_monitor_errno(device, m, errno, "Failed to send device to netlink monitor: %m");
|
||||
}
|
||||
|
||||
log_device_debug(device, "sd-device-monitor: Passed %zi byte to netlink monitor", count);
|
||||
log_device_monitor(device, m, "Passed %zi byte to netlink monitor.", count);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ static void test_receive_device_fail(void) {
|
||||
assert_se(sd_device_get_syspath(loopback, &syspath) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(device_monitor_send_device(monitor_server, monitor_client, loopback) >= 0);
|
||||
assert_se(sd_event_run(sd_device_monitor_get_event(monitor_client), 0) >= 0);
|
||||
@@ -62,13 +62,13 @@ static void test_send_receive_one(sd_device *device, bool subsystem_filter, bool
|
||||
assert_se(sd_device_get_syspath(device, &syspath) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
if (subsystem_filter) {
|
||||
assert_se(sd_device_get_subsystem(device, &subsystem) >= 0);
|
||||
@@ -99,14 +99,14 @@ static void test_subsystem_filter(sd_device *device) {
|
||||
assert_se(sd_device_get_subsystem(device, &subsystem) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, subsystem, NULL) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, false) >= 0);
|
||||
@@ -139,14 +139,14 @@ static void test_tag_filter(sd_device *device) {
|
||||
assert_se(sd_device_get_syspath(device, &syspath) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_filter_add_match_tag(monitor_client, "TEST_SD_DEVICE_MONITOR") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
FOREACH_DEVICE(e, d) {
|
||||
@@ -179,14 +179,14 @@ static void test_sysattr_filter(sd_device *device, const char *sysattr) {
|
||||
assert_se(sd_device_get_sysattr_value(device, sysattr, &sysattr_value) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_filter_add_match_sysattr(monitor_client, sysattr, sysattr_value, true) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
assert_se(sd_device_enumerator_add_match_sysattr(e, sysattr, sysattr_value, false) >= 0);
|
||||
@@ -229,14 +229,14 @@ static void test_parent_filter(sd_device *device) {
|
||||
assert_se(sd_device_get_syspath(parent, &parent_syspath) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_filter_add_match_parent(monitor_client, parent, true) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(sd_device_enumerator_new(&e) >= 0);
|
||||
FOREACH_DEVICE(e, d) {
|
||||
@@ -273,13 +273,13 @@ static void test_sd_device_monitor_filter_remove(sd_device *device) {
|
||||
assert_se(sd_device_get_syspath(device, &syspath) >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_server, "sender") >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_set_description(monitor_client, "receiver") >= 0);
|
||||
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
|
||||
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
|
||||
|
||||
assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, "hoge", NULL) >= 0);
|
||||
assert_se(sd_device_monitor_filter_update(monitor_client) >= 0);
|
||||
|
||||
@@ -144,6 +144,8 @@ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event);
|
||||
int sd_device_monitor_detach_event(sd_device_monitor *m);
|
||||
sd_event *sd_device_monitor_get_event(sd_device_monitor *m);
|
||||
sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
|
||||
int sd_device_monitor_set_description(sd_device_monitor *m, const char *description);
|
||||
int sd_device_monitor_get_description(sd_device_monitor *m, const char **ret);
|
||||
int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata);
|
||||
int sd_device_monitor_stop(sd_device_monitor *m);
|
||||
|
||||
|
||||
@@ -797,6 +797,8 @@ static int worker_spawn(Manager *manager, Event *event) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_device_monitor_set_description(worker_monitor, "worker");
|
||||
|
||||
/* allow the main daemon netlink address to send devices to the worker */
|
||||
r = device_monitor_allow_unicast_sender(worker_monitor, manager->monitor);
|
||||
if (r < 0)
|
||||
@@ -1919,6 +1921,8 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent) {
|
||||
log_warning_errno(r, "Failed to set receive buffer size for device monitor, ignoring: %m");
|
||||
}
|
||||
|
||||
(void) sd_device_monitor_set_description(manager->monitor, "manager");
|
||||
|
||||
r = device_monitor_enable_receiving(manager->monitor);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to bind netlink socket: %m");
|
||||
|
||||
Reference in New Issue
Block a user