[CRIU] [crtools-bot for Pavel Emelyanov ] check: Add some basic checks

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 2 05:15:28 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit e6c88abd623dad858597f1a097d9e5c1ec278997
Author: Pavel Emelyanov <xemul at parallels.com>
Date:   Fri Mar 2 14:01:57 2012 +0400

    check: Add some basic checks
    
    * /proc/<pid>/map_files
    * sock diag
    * ns_last_pid sysctl
    * SO_PEEK_OFF sockoptions
    
    Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-check.c         |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/util-net.h |    4 +++
 parasite.c         |    4 ---
 3 files changed, 76 insertions(+), 5 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index 3383b37..6b4601c 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -1,7 +1,78 @@
+#include <unistd.h>
+#include <sys/socket.h>
+#include "sockets.h"
 #include "crtools.h"
 #include "log.h"
+#include "util-net.h"
+
+static int check_map_files(void)
+{
+	int ret;
+
+	ret = access("/proc/self/map_files", R_OK);
+	if (!ret)
+		return 0;
+
+	pr_msg("/proc/<pid>/map_files directory is missing.\n");
+	return -1;
+}
+
+static int check_sock_diag(void)
+{
+	int ret;
+
+	ret = collect_sockets();
+	if (!ret)
+		return 0;
+
+	pr_msg("sock diag infrastructure is incomplete.\n");
+	return -1;
+}
+
+static int check_ns_last_pid(void)
+{
+	int ret;
+
+	ret = access(LAST_PID_PATH, W_OK);
+	if (!ret)
+		return 0;
+
+	pr_msg("%s sysctl is missing.\n", LAST_PID_PATH);
+	return -1;
+}
+
+static int check_sock_peek_off(void)
+{
+	int sk;
+	int ret, off, sz;
+
+	sk = socket(PF_UNIX, SOCK_DGRAM, 0);
+	if (sk < 0) {
+		pr_perror("Can't create unix socket for check");
+		return -1;
+	}
+
+	ret = getsockopt(sk, SOL_SOCKET, SO_PEEK_OFF, &off, (socklen_t *)&sz);
+	close(sk);
+
+	if ((ret == 0) && (off == -1) && (sz == sizeof(int)))
+		return 0;
+
+	pr_msg("SO_PEEK_OFF sockoption doesn't work.\n");
+	return -1;
+}
 
 int cr_check(void)
 {
-	return 0;
+	int ret = 0;
+
+	ret |= check_map_files();
+	ret |= check_sock_diag();
+	ret |= check_ns_last_pid();
+	ret |= check_sock_peek_off();
+
+	if (!ret)
+		pr_msg("Looks good.\n");
+
+	return ret;
 }
diff --git a/include/util-net.h b/include/util-net.h
index dbcad61..c5a8c46 100644
--- a/include/util-net.h
+++ b/include/util-net.h
@@ -4,6 +4,10 @@
 #define UNIX_PATH_MAX (sizeof(struct sockaddr_un) - \
 			(size_t)((struct sockaddr_un *) 0)->sun_path)
 
+#ifndef SO_PEEK_OFF
+#define SO_PEEK_OFF            42
+#endif
+
 extern int send_fd(int sock, struct sockaddr_un *saddr, int len, int fd);
 extern int recv_fd(int sock);
 #endif
diff --git a/parasite.c b/parasite.c
index fe5a325..b6c6bba 100644
--- a/parasite.c
+++ b/parasite.c
@@ -11,10 +11,6 @@
 
 #ifdef CONFIG_X86_64
 
-#ifndef SO_PEEK_OFF
-#define SO_PEEK_OFF            42
-#endif
-
 static void *brk_start, *brk_end, *brk_tail;
 
 static struct page_entry page;


More information about the CRIU mailing list