chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Introduce strv_consume which takes ownership
[elogind.git]
/
src
/
shared
/
socket-util.c
diff --git
a/src/shared/socket-util.c
b/src/shared/socket-util.c
index 75c47d1f76dfdea8b35dab793fdf0a305a3dfe84..5ef2e2244c0406874fd8b7cbdd067a610c853fb2 100644
(file)
--- a/
src/shared/socket-util.c
+++ b/
src/shared/socket-util.c
@@
-422,8
+422,7
@@
const char* socket_address_get_path(const SocketAddress *a) {
}
bool socket_ipv6_is_supported(void) {
}
bool socket_ipv6_is_supported(void) {
- char *l = 0;
- bool enabled;
+ _cleanup_free_ char *l = NULL;
if (access("/sys/module/ipv6", F_OK) != 0)
return 0;
if (access("/sys/module/ipv6", F_OK) != 0)
return 0;
@@
-433,10
+432,7
@@
bool socket_ipv6_is_supported(void) {
return 1;
/* If module was loaded with disable=1 no IPv6 available */
return 1;
/* If module was loaded with disable=1 no IPv6 available */
- enabled = l[0] == '0';
- free(l);
-
- return enabled;
+ return l[0] == '0';
}
bool socket_address_matches_fd(const SocketAddress *a, int fd) {
}
bool socket_address_matches_fd(const SocketAddress *a, int fd) {
@@
-579,6
+575,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);
@@
-588,16
+585,16
@@
int getpeername_pretty(int fd, char **ret) {
return -errno;
if (sa.sa.sa_family == AF_UNIX) {
return -errno;
if (sa.sa.sa_family == AF_UNIX) {
- struct ucred ucred;
+ struct ucred ucred
= {}
;
/* 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.
p
id) < 0)
+ if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.
u
id) < 0)
return -ENOMEM;
return 0;
return -ENOMEM;
return 0;