summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-04-25 17:23:24 +0200
committerLuca Boccassi <luca.boccassi@gmail.com>2024-04-25 22:17:30 +0200
commitb24c384b5dab5f568a263311f89881dc5c799a3b (patch)
tree025fbc04dfd09f3117001da89cf9c618331b30c0
parentMerge pull request #32445 from DaanDeMeyer/mkosi-images (diff)
downloadsystemd-b24c384b5dab5f568a263311f89881dc5c799a3b.tar.xz
systemd-b24c384b5dab5f568a263311f89881dc5c799a3b.zip
varlink: make errors returned by verify_unix_socket() systematic
Previously, if we encountered a non-socket fd we'd return ENOTSOCK the first time, but the subsequent times we'd return ENOMEDIUM, due to caching. Let's make sure we return the same errors all the the time.
-rw-r--r--src/shared/varlink.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/shared/varlink.c b/src/shared/varlink.c
index d96967b8e6..034e72b1db 100644
--- a/src/shared/varlink.c
+++ b/src/shared/varlink.c
@@ -3170,6 +3170,16 @@ int varlink_take_fd(Varlink *v, size_t i) {
static int verify_unix_socket(Varlink *v) {
assert(v);
+ /* Returns:
+ * • 0 if this is an AF_UNIX socket
+ * • -ENOTSOCK if this is not a socket at all
+ * • -ENOMEDIUM if this is a socket, but not an AF_UNIX socket
+ *
+ * Reminder:
+ * • v->af is < 0 if we haven't checked what kind of address family the thing is yet.
+ * • v->af == AF_UNSPEC if we checked but it's not a socket
+ * • otherwise: v->af contains the address family we determined */
+
if (v->af < 0) {
struct stat st;
@@ -3185,7 +3195,8 @@ static int verify_unix_socket(Varlink *v) {
return v->af;
}
- return v->af == AF_UNIX ? 0 : -ENOMEDIUM;
+ return v->af == AF_UNIX ? 0 :
+ v->af == AF_UNSPEC ? -ENOTSOCK : -ENOMEDIUM;
}
int varlink_set_allow_fd_passing_input(Varlink *v, bool b) {