[CRIU] [PATCH v2 1/5] net: Extrack ioctl() call from kerndat_socket_netns()

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 2 15:46:20 MSK 2018


Refactoring, no functional change.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/net.h |    1 +
 criu/net.c         |   26 +++++++++++++++-----------
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/criu/include/net.h b/criu/include/net.h
index 796dcc415..74f0969ad 100644
--- a/criu/include/net.h
+++ b/criu/include/net.h
@@ -48,5 +48,6 @@ extern int move_veth_to_bridge(void);
 extern int kerndat_link_nsid(void);
 extern int net_get_nsid(int rtsk, int fd, int *nsid);
 extern int kerndat_nsid(void);
+extern void check_has_netns_ioc(int fd, bool *kdat_val, const char *name);
 
 #endif /* __CR_NET_H__ */
diff --git a/criu/net.c b/criu/net.c
index 4a272120e..01f7f299b 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2721,26 +2721,30 @@ struct ns_id *get_socket_ns(int lfd)
 	return ns;
 }
 
+void check_has_netns_ioc(int fd, bool *kdat_val, const char *name)
+{
+	int ns_fd;
+
+	ns_fd = ioctl(fd, SIOCGSKNS);
+	*kdat_val = (ns_fd >= 0);
+
+	if (ns_fd < 0)
+		pr_warn("Unable to get %s network namespace\n", name);
+	else
+		close(ns_fd);
+}
+
 int kerndat_socket_netns(void)
 {
-	int sk, ns_fd;
+	int sk;
 
 	sk = socket(AF_UNIX, SOCK_DGRAM, 0);
 	if (sk < 0) {
 		pr_perror("Unable to create socket");
 		return -1;
 	}
-	ns_fd = ioctl(sk, SIOCGSKNS);
-	if (ns_fd < 0) {
-		pr_warn("Unable to get a socket network namespace\n");
-		kdat.sk_ns = false;
-		close(sk);
-		return 0;
-	}
+	check_has_netns_ioc(sk, &kdat.sk_ns, "socket");
 	close(sk);
-	close(ns_fd);
-
-	kdat.sk_ns = true;
 
 	return 0;
 }



More information about the CRIU mailing list