summaryrefslogtreecommitdiff
path: root/src/shared/socket-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-24 15:53:04 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-24 15:53:04 +0100
commiteff05270986a13e7de93ae16311f654d3f7c166f (patch)
treec5c7d7c456f8a8b9d3e75cb9e36b5974215003ed /src/shared/socket-util.c
parent96415cad2fdd8d280ae94b02651b5f826a2f7f3d (diff)
util: unify SO_PEERCRED/SO_PEERSEC invocations
Introduce new call getpeercred() which internally just uses SO_PEERCRED but checks if the returned data is actually useful due to namespace quirks.
Diffstat (limited to 'src/shared/socket-util.c')
-rw-r--r--src/shared/socket-util.c7
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;