summaryrefslogtreecommitdiffstats
path: root/src/shared/varlink.c
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2022-10-04 10:04:57 +0200
committerAnita Zhang <the.anitazha@gmail.com>2022-10-11 11:04:57 +0200
commitc14e841f31682a383edce68a9142a01589a95f50 (patch)
tree6c3bb0e07fc70f05c79ce056dd446adb018deb5f /src/shared/varlink.c
parentrepart: Don't fail on missing verity sig partition (diff)
downloadsystemd-c14e841f31682a383edce68a9142a01589a95f50.tar.xz
systemd-c14e841f31682a383edce68a9142a01589a95f50.zip
varlink: set address field in VarlinkServerSocket
Diffstat (limited to 'src/shared/varlink.c')
-rw-r--r--src/shared/varlink.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
index 580ebac4db..b68cdd9e5b 100644
--- a/src/shared/varlink.c
+++ b/src/shared/varlink.c
@@ -2197,6 +2197,16 @@ int varlink_server_add_connection(VarlinkServer *server, int fd, Varlink **ret)
return 0;
}
+static VarlinkServerSocket *varlink_server_socket_free(VarlinkServerSocket *ss) {
+ if (!ss)
+ return NULL;
+
+ free(ss->address);
+ return mfree(ss);
+}
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(VarlinkServerSocket *, varlink_server_socket_free);
+
static int connect_callback(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
VarlinkServerSocket *ss = ASSERT_PTR(userdata);
_cleanup_close_ int cfd = -1;
@@ -2233,12 +2243,13 @@ static int connect_callback(sd_event_source *source, int fd, uint32_t revents, v
return 0;
}
-int varlink_server_listen_fd(VarlinkServer *s, int fd) {
- _cleanup_free_ VarlinkServerSocket *ss = NULL;
+static int varlink_server_create_listen_fd_socket(VarlinkServer *s, int fd, VarlinkServerSocket **ret_ss) {
+ _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
int r;
- assert_return(s, -EINVAL);
- assert_return(fd >= 0, -EBADF);
+ assert(s);
+ assert(fd >= 0);
+ assert(ret_ss);
r = fd_nonblock(fd, true);
if (r < 0)
@@ -2263,11 +2274,27 @@ int varlink_server_listen_fd(VarlinkServer *s, int fd) {
return r;
}
+ *ret_ss = TAKE_PTR(ss);
+ return 0;
+}
+
+int varlink_server_listen_fd(VarlinkServer *s, int fd) {
+ _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
+ int r;
+
+ assert_return(s, -EINVAL);
+ assert_return(fd >= 0, -EBADF);
+
+ r = varlink_server_create_listen_fd_socket(s, fd, &ss);
+ if (r < 0)
+ return r;
+
LIST_PREPEND(sockets, s->sockets, TAKE_PTR(ss));
return 0;
}
int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t m) {
+ _cleanup_(varlink_server_socket_freep) VarlinkServerSocket *ss = NULL;
union sockaddr_union sockaddr;
socklen_t sockaddr_len;
_cleanup_close_ int fd = -1;
@@ -2299,10 +2326,15 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t
if (listen(fd, SOMAXCONN) < 0)
return -errno;
- r = varlink_server_listen_fd(s, fd);
+ r = varlink_server_create_listen_fd_socket(s, fd, &ss);
if (r < 0)
return r;
+ r = free_and_strdup(&ss->address, address);
+ if (r < 0)
+ return r;
+
+ LIST_PREPEND(sockets, s->sockets, TAKE_PTR(ss));
TAKE_FD(fd);
return 0;
}