diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-02 15:54:22 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-02 15:56:30 +0100 |
commit | 86fca584c38fad0bed9c7cd7ca3117e3f990c0d9 (patch) | |
tree | 5c30b99e12d8c7e34579d52a6caa4e319d6d0fd5 | |
parent | 425d925f24a64662a3ef3b5b9abb905bb70825c2 (diff) | |
download | systemd-86fca584c38fad0bed9c7cd7ca3117e3f990c0d9.tar.gz |
core/execute: use return value from sockaddr_un_set_path(), remove duplicate check
-rw-r--r-- | src/core/execute.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index 58055a33c4..76e1b28d37 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -383,9 +383,10 @@ static int open_terminal_as(const char *path, int flags, int nfd) { } static int acquire_path(const char *path, int flags, mode_t mode) { - union sockaddr_union sa = {}; + union sockaddr_union sa; + socklen_t sa_len; _cleanup_close_ int fd = -1; - int r, salen; + int r; assert(path); @@ -398,20 +399,19 @@ static int acquire_path(const char *path, int flags, mode_t mode) { if (errno != ENXIO) /* ENXIO is returned when we try to open() an AF_UNIX file system socket on Linux */ return -errno; - if (strlen(path) >= sizeof(sa.un.sun_path)) /* Too long, can't be a UNIX socket */ - return -ENXIO; /* So, it appears the specified path could be an AF_UNIX socket. Let's see if we can connect to it. */ + r = sockaddr_un_set_path(&sa.un, path); + if (r < 0) + return r == -EINVAL ? -ENXIO : r; + sa_len = r; + fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) return -errno; - salen = sockaddr_un_set_path(&sa.un, path); - if (salen < 0) - return salen; - - if (connect(fd, &sa.sa, salen) < 0) + if (connect(fd, &sa.sa, sa_len) < 0) return errno == EINVAL ? -ENXIO : -errno; /* Propagate initial error if we get EINVAL, i.e. we have * indication that his wasn't an AF_UNIX socket after all */ @@ -420,7 +420,7 @@ static int acquire_path(const char *path, int flags, mode_t mode) { else if ((flags & O_ACCMODE) == O_WRONLY) r = shutdown(fd, SHUT_RD); else - return TAKE_FD(fd); + r = 0; if (r < 0) return -errno; |