Skip to content

Commit b24c384

Browse files
poetteringbluca
authored andcommitted
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.
1 parent 536b5c0 commit b24c384

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/shared/varlink.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3170,6 +3170,16 @@ int varlink_take_fd(Varlink *v, size_t i) {
31703170
static int verify_unix_socket(Varlink *v) {
31713171
assert(v);
31723172

3173+
/* Returns:
3174+
* • 0 if this is an AF_UNIX socket
3175+
* • -ENOTSOCK if this is not a socket at all
3176+
* • -ENOMEDIUM if this is a socket, but not an AF_UNIX socket
3177+
*
3178+
* Reminder:
3179+
* • v->af is < 0 if we haven't checked what kind of address family the thing is yet.
3180+
* • v->af == AF_UNSPEC if we checked but it's not a socket
3181+
* • otherwise: v->af contains the address family we determined */
3182+
31733183
if (v->af < 0) {
31743184
struct stat st;
31753185

@@ -3185,7 +3195,8 @@ static int verify_unix_socket(Varlink *v) {
31853195
return v->af;
31863196
}
31873197

3188-
return v->af == AF_UNIX ? 0 : -ENOMEDIUM;
3198+
return v->af == AF_UNIX ? 0 :
3199+
v->af == AF_UNSPEC ? -ENOTSOCK : -ENOMEDIUM;
31893200
}
31903201

31913202
int varlink_set_allow_fd_passing_input(Varlink *v, bool b) {

0 commit comments

Comments
 (0)