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/tty-ask-password-agent | |
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/tty-ask-password-agent')
-rw-r--r-- | src/tty-ask-password-agent/tty-ask-password-agent.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index 784dd0df72..0e33c0b48f 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -57,17 +57,19 @@ static const char *arg_device = NULL; static int send_passwords(const char *socket_name, char **passwords) { _cleanup_(erase_and_freep) char *packet = NULL; _cleanup_close_ int socket_fd = -1; - union sockaddr_union sa = {}; + union sockaddr_union sa; + socklen_t sa_len; size_t packet_length = 1; char **p, *d; ssize_t n; - int salen; + int r; assert(socket_name); - salen = sockaddr_un_set_path(&sa.un, socket_name); - if (salen < 0) - return salen; + r = sockaddr_un_set_path(&sa.un, socket_name); + if (r < 0) + return r; + sa_len = r; STRV_FOREACH(p, passwords) packet_length += strlen(*p) + 1; @@ -86,7 +88,7 @@ static int send_passwords(const char *socket_name, char **passwords) { if (socket_fd < 0) return log_debug_errno(errno, "socket(): %m"); - n = sendto(socket_fd, packet, packet_length, MSG_NOSIGNAL, &sa.sa, salen); + n = sendto(socket_fd, packet, packet_length, MSG_NOSIGNAL, &sa.sa, sa_len); if (n < 0) return log_debug_errno(errno, "sendto(): %m"); |