diff options
Diffstat (limited to 'src/shared/socket-util.c')
-rw-r--r-- | src/shared/socket-util.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c index 75c47d1f76..45ada7eb3f 100644 --- a/src/shared/socket-util.c +++ b/src/shared/socket-util.c @@ -579,6 +579,7 @@ int sockaddr_pretty(const struct sockaddr *_sa, socklen_t salen, bool translate_ int getpeername_pretty(int fd, char **ret) { union sockaddr_union sa; socklen_t salen; + int r; assert(fd >= 0); assert(ret); @@ -593,9 +594,9 @@ int getpeername_pretty(int fd, char **ret) { /* UNIX connection sockets are anonymous, so let's use * PID/UID as pretty credentials instead */ - salen = sizeof(ucred); - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &salen) < 0) - return -errno; + r = getpeercred(fd, &ucred); + if (r < 0) + return r; if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.pid) < 0) return -ENOMEM; |