chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util: unify SO_PEERCRED/SO_PEERSEC invocations
[elogind.git]
/
src
/
shared
/
socket-util.c
diff --git
a/src/shared/socket-util.c
b/src/shared/socket-util.c
index 75c47d1f76dfdea8b35dab793fdf0a305a3dfe84..45ada7eb3ff6ee04d314a8c583edb82a8bec9911 100644
(file)
--- 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 getpeername_pretty(int fd, char **ret) {
union sockaddr_union sa;
socklen_t salen;
+ int r;
assert(fd >= 0);
assert(ret);
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 */
/* 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;
if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.pid) < 0)
return -ENOMEM;