X Tutup
Skip to content

Commit deb2b73

Browse files
committed
sd-device: drop priority and description from sd_device_monitor_attach_event() and sd_device_monitor_start()
Now we have sd_device_monitor_get_event_soruce(). So, it is not necessary to include these parameters in the functions for sd_device_monitor.
1 parent bf7712b commit deb2b73

File tree

9 files changed

+44
-43
lines changed

9 files changed

+44
-43
lines changed

src/core/device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,13 @@ static void device_enumerate(Manager *m) {
802802
goto fail;
803803
}
804804

805-
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
805+
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
806806
if (r < 0) {
807807
log_error_errno(r, "Failed to attach event to device monitor: %m");
808808
goto fail;
809809
}
810810

811-
r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m, "systemd-device-monitor");
811+
r = sd_device_monitor_start(m->device_monitor, device_dispatch_io, m);
812812
if (r < 0) {
813813
log_error_errno(r, "Failed to start device monitor: %m");
814814
goto fail;

src/libsystemd/sd-device/device-monitor.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct sd_device_monitor {
3737

3838
sd_event *event;
3939
sd_event_source *event_source;
40-
int64_t event_priority;
4140
sd_device_monitor_handler_t callback;
4241
void *userdata;
4342
};
@@ -200,14 +199,13 @@ static int device_monitor_event_handler(sd_event_source *s, int fd, uint32_t rev
200199
return 0;
201200
}
202201

203-
_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description) {
204-
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
202+
_public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata) {
205203
int r;
206204

207205
assert_return(m, -EINVAL);
208206

209207
if (!m->event) {
210-
r = sd_device_monitor_attach_event(m, NULL, 0);
208+
r = sd_device_monitor_attach_event(m, NULL);
211209
if (r < 0)
212210
return r;
213211
}
@@ -219,21 +217,11 @@ _public_ int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_han
219217
m->callback = callback;
220218
m->userdata = userdata;
221219

222-
r = sd_event_add_io(m->event, &s, m->sock, EPOLLIN, device_monitor_event_handler, m);
220+
r = sd_event_add_io(m->event, &m->event_source, m->sock, EPOLLIN, device_monitor_event_handler, m);
223221
if (r < 0)
224222
return r;
225223

226-
r = sd_event_source_set_priority(s, m->event_priority);
227-
if (r < 0)
228-
return r;
229-
230-
if (description) {
231-
r = sd_event_source_set_description(s, description);
232-
if (r < 0)
233-
return r;
234-
}
235-
236-
m->event_source = TAKE_PTR(s);
224+
(void) sd_event_source_set_description(m->event_source, "sd-device-monitor");
237225

238226
return 0;
239227
}
@@ -247,7 +235,7 @@ _public_ int sd_device_monitor_detach_event(sd_device_monitor *m) {
247235
return 0;
248236
}
249237

250-
_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority) {
238+
_public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event) {
251239
int r;
252240

253241
assert_return(m, -EINVAL);
@@ -261,8 +249,6 @@ _public_ int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *even
261249
return 0;
262250
}
263251

264-
m->event_priority = priority;
265-
266252
return 0;
267253
}
268254

src/libsystemd/sd-device/test-sd-device-monitor.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ static int test_loopback(bool subsystem_filter, bool tag_filter, bool use_bpf) {
3939
assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
4040

4141
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
42-
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 0);
42+
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
43+
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
4344

4445
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
4546
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
46-
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath, "loopback-monitor") >= 0);
47+
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
48+
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
4749

4850
if (subsystem_filter) {
4951
assert_se(sd_device_get_subsystem(loopback, &subsystem) >= 0);
@@ -82,12 +84,14 @@ static void test_subsystem_filter(void) {
8284
assert_se(device_add_property(loopback, "SEQNUM", "10") >= 0);
8385

8486
assert_se(device_monitor_new_full(&monitor_server, MONITOR_GROUP_NONE, -1) >= 0);
85-
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL, NULL) >= 0);
87+
assert_se(sd_device_monitor_start(monitor_server, NULL, NULL) >= 0);
88+
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_server), "sender") >= 0);
8689

8790
assert_se(device_monitor_new_full(&monitor_client, MONITOR_GROUP_NONE, -1) >= 0);
8891
assert_se(device_monitor_allow_unicast_sender(monitor_client, monitor_server) >= 0);
8992
assert_se(sd_device_monitor_filter_add_match_subsystem_devtype(monitor_client, subsystem, NULL) >= 0);
90-
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath, "subsystem-filter") >= 0);
93+
assert_se(sd_device_monitor_start(monitor_client, monitor_handler, (void *) syspath) >= 0);
94+
assert_se(sd_event_source_set_description(sd_device_monitor_get_event_source(monitor_client), "receiver") >= 0);
9195

9296
assert_se(sd_device_enumerator_new(&e) >= 0);
9397
assert_se(sd_device_enumerator_add_match_subsystem(e, subsystem, false) >= 0);

src/login/logind.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -832,14 +832,16 @@ static int manager_connect_udev(Manager *m) {
832832
if (r < 0)
833833
return r;
834834

835-
r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event, 0);
835+
r = sd_device_monitor_attach_event(m->device_seat_monitor, m->event);
836836
if (r < 0)
837837
return r;
838838

839-
r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m, "logind-seat-monitor");
839+
r = sd_device_monitor_start(m->device_seat_monitor, manager_dispatch_seat_udev, m);
840840
if (r < 0)
841841
return r;
842842

843+
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_seat_monitor), "logind-seat-monitor");
844+
843845
r = sd_device_monitor_new(&m->device_monitor);
844846
if (r < 0)
845847
return r;
@@ -856,14 +858,16 @@ static int manager_connect_udev(Manager *m) {
856858
if (r < 0)
857859
return r;
858860

859-
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
861+
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
860862
if (r < 0)
861863
return r;
862864

863-
r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m, "logind-device-monitor");
865+
r = sd_device_monitor_start(m->device_monitor, manager_dispatch_device_udev, m);
864866
if (r < 0)
865867
return r;
866868

869+
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_monitor), "logind-device-monitor");
870+
867871
/* Don't watch keys if nobody cares */
868872
if (!manager_all_buttons_ignored(m)) {
869873
r = sd_device_monitor_new(&m->device_button_monitor);
@@ -878,13 +882,15 @@ static int manager_connect_udev(Manager *m) {
878882
if (r < 0)
879883
return r;
880884

881-
r = sd_device_monitor_attach_event(m->device_button_monitor, m->event, 0);
885+
r = sd_device_monitor_attach_event(m->device_button_monitor, m->event);
882886
if (r < 0)
883887
return r;
884888

885-
r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m, "logind-button-monitor");
889+
r = sd_device_monitor_start(m->device_button_monitor, manager_dispatch_button_udev, m);
886890
if (r < 0)
887891
return r;
892+
893+
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_button_monitor), "logind-button-monitor");
888894
}
889895

890896
/* Don't bother watching VCSA devices, if nobody cares */
@@ -898,13 +904,15 @@ static int manager_connect_udev(Manager *m) {
898904
if (r < 0)
899905
return r;
900906

901-
r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event, 0);
907+
r = sd_device_monitor_attach_event(m->device_vcsa_monitor, m->event);
902908
if (r < 0)
903909
return r;
904910

905-
r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m, "logind-vcsa-monitor");
911+
r = sd_device_monitor_start(m->device_vcsa_monitor, manager_dispatch_vcsa_udev, m);
906912
if (r < 0)
907913
return r;
914+
915+
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(m->device_vcsa_monitor), "logind-vcsa-monitor");
908916
}
909917

910918
return 0;

src/network/networkd-manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ static int manager_connect_udev(Manager *m) {
240240
if (r < 0)
241241
return log_error_errno(r, "Could not add device monitor filter: %m");
242242

243-
r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
243+
r = sd_device_monitor_attach_event(m->device_monitor, m->event);
244244
if (r < 0)
245245
return log_error_errno(r, "Failed to attach event to device monitor: %m");
246246

247-
r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m, "networkd-device-monitor");
247+
r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m);
248248
if (r < 0)
249249
return log_error_errno(r, "Failed to start device monitor: %m");
250250

src/rfkill/rfkill.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ static int wait_for_initialized(
138138
if (r < 0)
139139
return log_error_errno(r, "Failed to add rfkill device match to monitor: %m");
140140

141-
r = sd_device_monitor_attach_event(monitor, event, 0);
141+
r = sd_device_monitor_attach_event(monitor, event);
142142
if (r < 0)
143143
return log_error_errno(r, "Failed to attach event to device monitor: %m");
144144

145-
r = sd_device_monitor_start(monitor, device_monitor_handler, &data, "rfkill-device-monitor");
145+
r = sd_device_monitor_start(monitor, device_monitor_handler, &data);
146146
if (r < 0)
147147
return log_error_errno(r, "Failed to start device monitor: %m");
148148

src/systemd/sd-device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ sd_device_monitor *sd_device_monitor_ref(sd_device_monitor *m);
103103
sd_device_monitor *sd_device_monitor_unref(sd_device_monitor *m);
104104

105105
int sd_device_monitor_set_receive_buffer_size(sd_device_monitor *m, size_t size);
106-
int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event, int64_t priority);
106+
int sd_device_monitor_attach_event(sd_device_monitor *m, sd_event *event);
107107
int sd_device_monitor_detach_event(sd_device_monitor *m);
108108
sd_event *sd_device_monitor_get_event(sd_device_monitor *m);
109109
sd_event_source *sd_device_monitor_get_event_source(sd_device_monitor *m);
110-
int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata, const char *description);
110+
int sd_device_monitor_start(sd_device_monitor *m, sd_device_monitor_handler_t callback, void *userdata);
111111
int sd_device_monitor_stop(sd_device_monitor *m);
112112

113113
int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor *m, const char *subsystem, const char *devtype);

src/udev/udevadm-monitor.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
6767

6868
(void) sd_device_monitor_set_receive_buffer_size(monitor, 128*1024*1024);
6969

70-
r = sd_device_monitor_attach_event(monitor, event, 0);
70+
r = sd_device_monitor_attach_event(monitor, event);
7171
if (r < 0)
7272
return log_error_errno(r, "Failed to attach event: %m");
7373

@@ -84,10 +84,13 @@ static int setup_monitor(MonitorNetlinkGroup sender, sd_event *event, sd_device_
8484
return log_error_errno(r, "Failed to apply tag filter '%s': %m", tag);
8585
}
8686

87-
r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender), sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
87+
r = sd_device_monitor_start(monitor, device_monitor_handler, INT_TO_PTR(sender));
8888
if (r < 0)
8989
return log_error_errno(r, "Failed to start device monitor: %m");
9090

91+
(void) sd_event_source_set_description(sd_device_monitor_get_event_source(monitor),
92+
sender == MONITOR_GROUP_UDEV ? "device-monitor-udev" : "device-monitor-kernel");
93+
9194
*ret = TAKE_PTR(monitor);
9295
return 0;
9396
}

src/udev/udevadm-trigger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,11 @@ int trigger_main(int argc, char *argv[], void *userdata) {
305305
if (r < 0)
306306
return log_error_errno(r, "Failed to create device monitor object: %m");
307307

308-
r = sd_device_monitor_attach_event(m, event, 0);
308+
r = sd_device_monitor_attach_event(m, event);
309309
if (r < 0)
310310
return log_error_errno(r, "Failed to attach event to device monitor: %m");
311311

312-
r = sd_device_monitor_start(m, device_monitor_handler, settle_set, "udevadm-trigger-device-monitor");
312+
r = sd_device_monitor_start(m, device_monitor_handler, settle_set);
313313
if (r < 0)
314314
return log_error_errno(r, "Failed to start device monitor: %m");
315315
}

0 commit comments

Comments
 (0)
X Tutup