systemd/backport-socket-util-fix-socket_get_family.patch
wangyuhang a4f95d3244 sync patch from systemd community
(cherry picked from commit 88369f234ec01b60fb047caf87b90ef10a92b0db)
2023-10-10 10:04:24 +08:00

127 lines
3.9 KiB
Diff

From 01ef1b83d7c3afb5d9382b238ad6717f1e12ca8a Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 7 Mar 2023 22:50:41 +0100
Subject: [PATCH] socket-util: fix socket_get_family()
Function didn't actually return anything useful. Quite a shame.
(cherry picked from commit 5f64d2bf332371bdfdcb91b588e57d4c0c20428f)
(cherry picked from commit 59514a6d87be7013d61b4f15b993918f5d1e44e5)
(cherry picked from commit b77f041885fa68cc3bfefcae97b6ca76a327c77a)
Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/01ef1b83d7c3afb5d9382b238ad6717f1e12ca8a
---
src/basic/socket-util.c | 30 +++++++++++++-----------------
src/basic/socket-util.h | 2 +-
src/resolve/resolved-manager.c | 6 +++---
3 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 0dfe2a7dbc..cbbfa01eb5 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -1309,7 +1309,7 @@ ssize_t recvmsg_safe(int sockfd, struct msghdr *msg, int flags) {
return n;
}
-int socket_get_family(int fd, int *ret) {
+int socket_get_family(int fd) {
int af;
socklen_t sl = sizeof(af);
@@ -1323,12 +1323,11 @@ int socket_get_family(int fd, int *ret) {
}
int socket_set_recvpktinfo(int fd, int af, bool b) {
- int r;
if (af == AF_UNSPEC) {
- r = socket_get_family(fd, &af);
- if (r < 0)
- return r;
+ af = socket_get_family(fd);
+ if (af < 0)
+ return af;
}
switch (af) {
@@ -1352,12 +1351,11 @@ int socket_set_recvpktinfo(int fd, int af, bool b) {
int socket_set_unicast_if(int fd, int af, int ifi) {
be32_t ifindex_be = htobe32(ifi);
- int r;
if (af == AF_UNSPEC) {
- r = socket_get_family(fd, &af);
- if (r < 0)
- return r;
+ af = socket_get_family(fd);
+ if (af < 0)
+ return af;
}
switch (af) {
@@ -1374,12 +1372,10 @@ int socket_set_unicast_if(int fd, int af, int ifi) {
}
int socket_set_option(int fd, int af, int opt_ipv4, int opt_ipv6, int val) {
- int r;
-
if (af == AF_UNSPEC) {
- r = socket_get_family(fd, &af);
- if (r < 0)
- return r;
+ af = socket_get_family(fd);
+ if (af < 0)
+ return af;
}
switch (af) {
@@ -1399,9 +1395,9 @@ int socket_get_mtu(int fd, int af, size_t *ret) {
int mtu, r;
if (af == AF_UNSPEC) {
- r = socket_get_family(fd, &af);
- if (r < 0)
- return r;
+ af = socket_get_family(fd);
+ if (af < 0)
+ return af;
}
switch (af) {
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index 5d9c056744..22cdb94c1d 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -304,7 +304,7 @@ struct timespec_large {
ssize_t recvmsg_safe(int sockfd, struct msghdr *msg, int flags);
-int socket_get_family(int fd, int *ret);
+int socket_get_family(int fd);
int socket_set_recvpktinfo(int fd, int af, bool b);
int socket_set_unicast_if(int fd, int af, int ifi);
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 12e7d87f22..9d8fd4191c 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -1630,9 +1630,9 @@ int socket_disable_pmtud(int fd, int af) {
assert(fd >= 0);
if (af == AF_UNSPEC) {
- r = socket_get_family(fd, &af);
- if (r < 0)
- return r;
+ af = socket_get_family(fd);
+ if (af < 0)
+ return af;
}
switch (af) {
--
2.33.0