[CRIU] [PATCH 1/2] sk-inet: udp -- Don't fail on calling shutdown on disconnected socket

Cyrill Gorcunov gorcunov at gmail.com
Thu Apr 18 12:57:15 MSK 2019


If socket has been connected and shutted down, it may get
disconnected then leaving shutdown mode set inside (which
we pull into image). On restore we should not fail when
calling shutdown over -- the kernel has a hack to inform
listeners even on closed sockets. From userspace perspective
to reuse such socket one have to connect it back, so should
be safe.

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 criu/sk-inet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index cc7e1cc28c1c..60ee4c31559e 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -883,9 +883,14 @@ static int open_inet_sk(struct file_desc *d, int *new_fd)
 	    (ie->proto == IPPROTO_UDP ||
 	     ie->proto == IPPROTO_UDPLITE)) {
 		if (shutdown(sk, sk_decode_shutdown(ie->shutdown))) {
-			pr_perror("Can't shutdown socket into %d",
-				  sk_decode_shutdown(ie->shutdown));
-			goto err;
+			if (ie->state != TCP_CLOSE && errno != ENOTCONN) {
+				pr_perror("Can't shutdown socket into %d",
+					  sk_decode_shutdown(ie->shutdown));
+				goto err;
+			} else {
+				pr_debug("Called shutdown on closed socket, "
+					 "proto %d ino %x", ie->proto, ie->ino);
+			}
 		}
 	}
 
-- 
2.20.1



More information about the CRIU mailing list