summaryrefslogtreecommitdiffstats
path: root/src/shared/varlink.c
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2022-10-11 11:36:32 +0200
committerAnita Zhang <the.anitazha@gmail.com>2022-10-14 10:59:09 +0200
commit536827e05ab4bd45302b77178ec7bb7d792c04b0 (patch)
treec19318e85157e423132a0bc17fe54e0fcff162ab /src/shared/varlink.c
parentvarlink: set address field in VarlinkServerSocket (diff)
downloadsystemd-536827e05ab4bd45302b77178ec7bb7d792c04b0.tar.xz
systemd-536827e05ab4bd45302b77178ec7bb7d792c04b0.zip
varlink: refactor adding socket event source to the event loop
Diffstat (limited to 'src/shared/varlink.c')
-rw-r--r--src/shared/varlink.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
index b68cdd9e5b..8b331be667 100644
--- a/src/shared/varlink.c
+++ b/src/shared/varlink.c
@@ -2380,6 +2380,29 @@ int varlink_server_shutdown(VarlinkServer *s) {
return 0;
}
+static int varlink_server_add_socket_event_source(VarlinkServer *s, VarlinkServerSocket *ss, int64_t priority) {
+ _cleanup_(sd_event_source_unrefp) sd_event_source *es = NULL;
+
+ int r;
+
+ assert(s);
+ assert(s->event);
+ assert(ss);
+ assert(ss->fd >= 0);
+ assert(!ss->event_source);
+
+ r = sd_event_add_io(s->event, &es, ss->fd, EPOLLIN, connect_callback, ss);
+ if (r < 0)
+ return r;
+
+ r = sd_event_source_set_priority(es, priority);
+ if (r < 0)
+ return r;
+
+ ss->event_source = TAKE_PTR(es);
+ return 0;
+}
+
int varlink_server_attach_event(VarlinkServer *s, sd_event *e, int64_t priority) {
int r;
@@ -2395,13 +2418,7 @@ int varlink_server_attach_event(VarlinkServer *s, sd_event *e, int64_t priority)
}
LIST_FOREACH(sockets, ss, s->sockets) {
- assert(!ss->event_source);
-
- r = sd_event_add_io(s->event, &ss->event_source, ss->fd, EPOLLIN, connect_callback, ss);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_priority(ss->event_source, priority);
+ r = varlink_server_add_socket_event_source(s, ss, priority);
if (r < 0)
goto fail;
}