mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
Merge pull request #10722 from yuwata/sd-device-monitor-change-arguments
sd-device-monitor: slightly re-design API arguments
This commit is contained in:
commit
f57dfcba08
@ -802,13 +802,13 @@ static void device_enumerate(Manager *m) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to attach event to device monitor: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m, "systemd-device-monitor");
|
||||
r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to start device monitor: %m");
|
||||
goto fail;
|
||||
|
@ -659,6 +659,7 @@ global:
|
||||
sd_device_monitor_attach_event;
|
||||
sd_device_monitor_detach_event;
|
||||
sd_device_monitor_get_event;
|
||||
sd_device_monitor_get_event_source;
|
||||
sd_device_monitor_start;
|
||||
sd_device_monitor_stop;
|
||||
|
||||
|
@ -37,7 +37,6 @@ struct sd_device_monitor {
|
||||
|
||||
sd_event *event;
|
||||
sd_event_source *event_source;
|
||||
int64_t event_priority;
|
||||
sd_device_monitor_handler_t callback;
|
||||
void *userdata;
|
||||
};
|
||||
@ -200,14 +199,13 @@ static int device_monitor_event_handler(sd_event_source *s, int fd, uint32_t rev
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description) {
|
||||
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
|
||||
_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
|
||||
if (!m->event) {
|
||||
r = sd_device_monitor_attach_event(m, NULL, 0);
|
||||
r = sd_device_monitor_attach_event(m, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -219,21 +217,11 @@ _public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_han
|
||||
m->callback = callback;
|
||||
m->userdata = userdata;
|
||||
|
||||
r = sd_event_add_io(m->event, &s, m->sock, EPOLLIN, device_monitor_event_handler, m);
|
||||
r = sd_event_add_io(m->event, &m->event_source, m->sock, EPOLLIN, device_monitor_event_handler, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_event_source_set_priority(s, m->event_priority);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (description) {
|
||||
r = sd_event_source_set_description(s, description);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
m->event_source = TAKE_PTR(s);
|
||||
(void) sd_event_source_set_description(m->event_source, "sd-device-monitor");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -247,7 +235,7 @@ _public_ int sd_device_monitor_detach_event(sd_device_monitor *m) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority) {
|
||||
_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
@ -261,8 +249,6 @@ _public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *even
|
||||
return 0;
|
||||
}
|
||||
|
||||
m->event_priority = priority;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -272,6 +258,12 @@ _public_ sd_event *sd_device_monitor_get_event(sd_device_monitor *m) {
|
||||
return m->event;
|
||||
}
|
||||
|
||||
_public_ sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m) {
|
||||
assert_return(m, NULL);
|
||||
|
||||
return m->event_source;
|
||||
}
|
||||
|
||||
int device_monitor_enable_receiving(sd_device_monitor *m) {
|
||||
int r;
|
||||
|
||||
|
@ -39,11 +39,13 @@ static int test_loopback(bool subsystem_filter, bool tag_filter, bool use_bpf) {
|
||||
assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 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(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath, "loopback-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);
|
||||
|
||||
if (subsystem_filter) {
|
||||
assert_se(sd_device_get_subsystem(loopback, &subsystem) >= 0);
|
||||
@ -82,12 +84,14 @@ static void test_subsystem_filter(void) {
|
||||
assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
|
||||
|
||||
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
|
||||
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 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(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, "subsystem-filter") >= 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);
|
||||
|
@ -832,14 +832,16 @@ static int manager_connect_udev(Manager *m) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m, "logind-seat-monitor");
|
||||
r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_seat_monitor), "logind-seat-monitor");
|
||||
|
||||
r = sd_device_monitor_new(&m->device_monitor);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -856,14 +858,16 @@ static int manager_connect_udev(Manager *m) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m, "logind-device-monitor");
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_monitor), "logind-device-monitor");
|
||||
|
||||
/* Don't watch keys if nobody cares */
|
||||
if (!manager_all_buttons_ignored(m)) {
|
||||
r = sd_device_monitor_new(&m->device_button_monitor);
|
||||
@ -878,13 +882,15 @@ static int manager_connect_udev(Manager *m) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_button_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_button_monitor, m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m, "logind-button-monitor");
|
||||
r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_button_monitor), "logind-button-monitor");
|
||||
}
|
||||
|
||||
/* Don't bother watching VCSA devices, if nobody cares */
|
||||
@ -898,13 +904,15 @@ static int manager_connect_udev(Manager *m) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m, "logind-vcsa-monitor");
|
||||
r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_vcsa_monitor), "logind-vcsa-monitor");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -240,11 +240,11 @@ static int manager_connect_udev(Manager *m) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not add device monitor filter: %m");
|
||||
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
|
||||
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach event to device monitor: %m");
|
||||
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m, "networkd-device-monitor");
|
||||
r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start device monitor: %m");
|
||||
|
||||
|
@ -138,11 +138,11 @@ static int wait_for_initialized(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add rfkill device match to monitor: %m");
|
||||
|
||||
r = sd_device_monitor_attach_event(monitor, event, 0);
|
||||
r = sd_device_monitor_attach_event(monitor, event);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach event to device monitor: %m");
|
||||
|
||||
r = sd_device_monitor_start(monitor, device_monitor_handler, &data, "rfkill-device-monitor");
|
||||
r = sd_device_monitor_start(monitor, device_monitor_handler, &data);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start device monitor: %m");
|
||||
|
||||
|
@ -103,10 +103,11 @@ sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m);
|
||||
sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m);
|
||||
|
||||
int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size);
|
||||
int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority);
|
||||
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);
|
||||
int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description);
|
||||
sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
|
||||
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);
|
||||
|
||||
int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype);
|
||||
|
@ -67,7 +67,7 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
|
||||
|
||||
(void) sd_device_monitor_set_receive_buffer_size(monitor, 128*1024*1024);
|
||||
|
||||
r = sd_device_monitor_attach_event(monitor, event, 0);
|
||||
r = sd_device_monitor_attach_event(monitor, event);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach event: %m");
|
||||
|
||||
@ -84,10 +84,13 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
|
||||
return log_error_errno(r, "Failed to apply tag filter '%s': %m", tag);
|
||||
}
|
||||
|
||||
r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender), sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
|
||||
r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender));
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start device monitor: %m");
|
||||
|
||||
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(monitor),
|
||||
sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
|
||||
|
||||
*ret = TAKE_PTR(monitor);
|
||||
return 0;
|
||||
}
|
||||
|
@ -305,11 +305,11 @@ int trigger_main(int argc, char *argv[], void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create device monitor object: %m");
|
||||
|
||||
r = sd_device_monitor_attach_event(m, event, 0);
|
||||
r = sd_device_monitor_attach_event(m, event);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach event to device monitor: %m");
|
||||
|
||||
r = sd_device_monitor_start(m, device_monitor_handler, settle_set, "udevadm-trigger-device-monitor");
|
||||
r = sd_device_monitor_start(m, device_monitor_handler, settle_set);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start device monitor: %m");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user