[CRIU] [PATCH 1/3] check: Add inotify/epoll/eventfd

Cyrill Gorcunov gorcunov at openvz.org
Fri May 4 08:31:12 EDT 2012


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-check.c |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 115 insertions(+), 1 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index 8cec6d8..936494c 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -1,6 +1,9 @@
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/eventfd.h>
+#include <sys/epoll.h>
+#include <sys/inotify.h>
 #include <fcntl.h>
 #include "proc_parse.h"
 #include "sockets.h"
@@ -10,7 +13,6 @@
 #include "syscall.h"
 #include "files.h"
 #include "sk-inet.h"
-
 static int check_map_files(void)
 {
 	int ret;
@@ -140,6 +142,115 @@ static int check_proc_stat(void)
 	return 0;
 }
 
+static int read_self_fdinfo(int fd, char *buf, size_t size)
+{
+	int fdinfo, ret;
+
+	snprintf(buf, size, "/proc/self/fdinfo/%d", fd);
+	fdinfo = open(buf, O_RDONLY);
+	if (fdinfo < 0) {
+		pr_msg("Can't open %s\n", buf);
+		return -1;
+	}
+
+	ret = read(fdinfo, buf, size);
+	ret = (ret > 0 ? ret - 1 : 0);
+	buf[ret] = '\0';
+
+	return -!!!ret;
+}
+
+static int check_eventpoll(void)
+{
+	struct epoll_event ev;
+	int fd, ret;
+	char buf[64];
+	int pipefd[2];
+
+	if (pipe(pipefd)) {
+		pr_msg("eventpoll: Can't create pipes\n");
+		return -1;
+	}
+
+	fd = epoll_create(1);
+	if (fd < 0) {
+		pr_msg("eventpoll: Can't create eventpoll file\n");
+		return -1;
+	}
+
+	memset(&ev, 0xff, sizeof(ev));
+	ev.events = EPOLLIN | EPOLLOUT;
+
+	if (epoll_ctl(fd, EPOLL_CTL_ADD, pipefd[0], &ev)) {
+		pr_msg("eventpoll: Can't add file\n");
+		goto err;
+	}
+
+	ret = read_self_fdinfo(fd, buf, sizeof(buf));
+
+	if (ret || !strstr(buf, "tfd:")) {
+		pr_msg("eventpoll: Bad format\n");
+		ret = -1;
+	}
+
+err:
+	close_safe(&fd);
+	close_safe(&pipefd[0]);
+	close_safe(&pipefd[1]);
+	return ret;
+}
+
+static int check_eventfd(void)
+{
+	int fd, ret;
+	char buf[64];
+
+	fd = eventfd(0, 0);
+	if (fd < 0) {
+		pr_msg("eventfd: Can't create eventfd file\n");
+		return -1;
+	}
+
+	ret = read_self_fdinfo(fd, buf, sizeof(buf));
+	close(fd);
+
+	if (ret || !strstr(buf, "count-raw:")) {
+		pr_msg("eventfd: Bad format\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+static int check_inotify(void)
+{
+	int fd, wd, ret;
+	char buf[64];
+
+	fd = inotify_init();
+	if (fd < 0) {
+		pr_msg("inotify: Can't create inotify file\n");
+		return -1;
+	}
+
+	wd = inotify_add_watch(fd, "/", IN_ALL_EVENTS);
+	if (wd < 0) {
+		close(fd);
+		pr_msg("inotify: Can't add inotify target\n");
+		return -1;
+	}
+
+	ret = read_self_fdinfo(fd, buf, sizeof(buf));
+	close(fd);
+
+	if (ret || !strstr(buf, "wd:")) {
+		pr_msg("inotify: Bad format\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 int cr_check(void)
 {
 	int ret = 0;
@@ -153,6 +264,9 @@ int cr_check(void)
 	ret |= check_fcntl();
 	ret |= check_proc_stat();
 	ret |= check_tcp_repair();
+	ret |= check_eventfd();
+	ret |= check_eventpoll();
+	ret |= check_inotify();
 
 	if (!ret)
 		pr_msg("Looks good.\n");
-- 
1.7.7.6



More information about the CRIU mailing list