Skip to content

Commit 9546a0b

Browse files
Tuong Liendavem330
authored andcommitted
tipc: fix wrong connect() return code
The current 'tipc_wait_for_connect()' function does a wait-loop for the condition 'sk->sk_state != TIPC_CONNECTING' to conclude if the socket connecting has done. However, when the condition is met, it returns '0' even in the case the connecting is actually failed, the socket state is set to 'TIPC_DISCONNECTING' (e.g. when the server socket has closed..). This results in a wrong return code for the 'connect()' call from user, making it believe that the connection is established and go ahead with building, sending a message, etc. but finally failed e.g. '-EPIPE'. This commit fixes the issue by changing the wait condition to the 'tipc_sk_connected(sk)', so the function will return '0' only when the connection is really established. Otherwise, either the socket 'sk_err' if any or '-ETIMEDOUT'/'-EINTR' will be returned correspondingly. Acked-by: Ying Xue <[email protected]> Acked-by: Jon Maloy <[email protected]> Signed-off-by: Tuong Lien <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 49afb80 commit 9546a0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/tipc/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,8 +2443,8 @@ static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
24432443
return sock_intr_errno(*timeo_p);
24442444

24452445
add_wait_queue(sk_sleep(sk), &wait);
2446-
done = sk_wait_event(sk, timeo_p,
2447-
sk->sk_state != TIPC_CONNECTING, &wait);
2446+
done = sk_wait_event(sk, timeo_p, tipc_sk_connected(sk),
2447+
&wait);
24482448
remove_wait_queue(sk_sleep(sk), &wait);
24492449
} while (!done);
24502450
return 0;

0 commit comments

Comments
 (0)