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

Submitted by Cyrill Gorcunov on April 18, 2019, 9:57 a.m.

Details

Message ID 20190418095716.20750-2-gorcunov@gmail.com
State Accepted
Series "sk-inet: Support shutdowned udp sockets"
Commit 692b854085040e606ed247fd6800ea76cd5c3865
Headers show

Commit Message

Cyrill Gorcunov April 18, 2019, 9:57 a.m.
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@gmail.com>
---
 criu/sk-inet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

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);
+			}
 		}
 	}