diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-02 15:51:31 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-02 15:55:44 +0100 |
commit | f36a9d5909019845d131e0c6c61f22b1d1956ca1 (patch) | |
tree | 7023bf19207e1903da61bef6a87d3a4fa2317178 /src/shared/varlink.c | |
parent | test-sizeof: print size socklen_t (diff) | |
download | systemd-f36a9d5909019845d131e0c6c61f22b1d1956ca1.tar.xz systemd-f36a9d5909019845d131e0c6c61f22b1d1956ca1.zip |
tree-wide: use the return value from sockaddr_un_set_path()
It fully initializes the address structure, so no need for pre-initialization,
and also returns the length of the address, so no need to recalculate using
SOCKADDR_UN_LEN().
socklen_t is unsigned, so let's not use an int for it. (It doesn't matter, but
seems cleaner and more portable to not assume anything about the type.)
Diffstat (limited to 'src/shared/varlink.c')
-rw-r--r-- | src/shared/varlink.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c index 012ce5308c..dff7d32535 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -271,6 +271,7 @@ static int varlink_new(Varlink **ret) { int varlink_connect_address(Varlink **ret, const char *address) { _cleanup_(varlink_unrefp) Varlink *v = NULL; union sockaddr_union sockaddr; + socklen_t sockaddr_len; int r; assert_return(ret, -EINVAL); @@ -279,6 +280,7 @@ int varlink_connect_address(Varlink **ret, const char *address) { r = sockaddr_un_set_path(&sockaddr.un, address); if (r < 0) return r; + sockaddr_len = r; r = varlink_new(&v); if (r < 0) @@ -290,7 +292,7 @@ int varlink_connect_address(Varlink **ret, const char *address) { v->fd = fd_move_above_stdio(v->fd); - if (connect(v->fd, &sockaddr.sa, SOCKADDR_UN_LEN(sockaddr.un)) < 0) { + if (connect(v->fd, &sockaddr.sa, sockaddr_len) < 0) { if (!IN_SET(errno, EAGAIN, EINPROGRESS)) return -errno; @@ -2224,6 +2226,7 @@ int varlink_server_listen_fd(VarlinkServer *s, int fd) { int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t m) { union sockaddr_union sockaddr; + socklen_t sockaddr_len; _cleanup_close_ int fd = -1; int r; @@ -2234,6 +2237,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t r = sockaddr_un_set_path(&sockaddr.un, address); if (r < 0) return r; + sockaddr_len = r; fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (fd < 0) @@ -2244,7 +2248,7 @@ int varlink_server_listen_address(VarlinkServer *s, const char *address, mode_t (void) sockaddr_un_unlink(&sockaddr.un); RUN_WITH_UMASK(~m & 0777) - if (bind(fd, &sockaddr.sa, SOCKADDR_UN_LEN(sockaddr.un)) < 0) + if (bind(fd, &sockaddr.sa, sockaddr_len) < 0) return -errno; if (listen(fd, SOMAXCONN) < 0) |