core/execute: use return value from sockaddr_un_set_path(), remove duplicate check

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-03-02 15:54:22 +01:00
parent 425d925f24
commit 86fca584c3
1 changed files with 10 additions and 10 deletions

View File

@ -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;