[CRIU] [PATCH 1/2] proc_parse: Add ability to not print error if entry is optional

Cyrill Gorcunov gorcunov at openvz.org
Tue Sep 11 17:21:56 EDT 2012


Will need it for epoll parsing where context might exist
but no target assigned.

Reported-by: Andrew Vagin <avagin at parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-check.c           |    8 ++++----
 eventfd.c            |    2 +-
 eventpoll.c          |    2 +-
 include/proc_parse.h |    2 +-
 inotify.c            |    2 +-
 proc_parse.c         |    9 ++++++---
 signalfd.c           |    2 +-
 7 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/cr-check.c b/cr-check.c
index cd0be8c..e815766 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -164,7 +164,7 @@ static int check_fdinfo_eventfd(void)
 		return -1;
 	}
 
-	ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, check_one_fdinfo, &proc_cnt);
+	ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, false, check_one_fdinfo, &proc_cnt);
 	close(fd);
 
 	if (ret) {
@@ -200,7 +200,7 @@ static int check_fdinfo_signalfd(void)
 		return -1;
 	}
 
-	ret = parse_fdinfo(fd, FD_TYPES__SIGNALFD, check_one_sfd, NULL);
+	ret = parse_fdinfo(fd, FD_TYPES__SIGNALFD, false, check_one_sfd, NULL);
 	close(fd);
 
 	if (ret) {
@@ -241,7 +241,7 @@ static int check_fdinfo_eventpoll(void)
 		return -1;
 	}
 
-	ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, check_one_epoll, &proc_fd);
+	ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, false, check_one_epoll, &proc_fd);
 	close(efd);
 	close(pfd[0]);
 	close(pfd[1]);
@@ -283,7 +283,7 @@ static int check_fdinfo_inotify(void)
 		return -1;
 	}
 
-	ret = parse_fdinfo(ifd, FD_TYPES__INOTIFY, check_one_inotify, &proc_wd);
+	ret = parse_fdinfo(ifd, FD_TYPES__INOTIFY, false, check_one_inotify, &proc_wd);
 	close(ifd);
 
 	if (ret < 0) {
diff --git a/eventfd.c b/eventfd.c
index 75c8b84..e7dfe2d 100644
--- a/eventfd.c
+++ b/eventfd.c
@@ -77,7 +77,7 @@ static int dump_eventfd_entry(union fdinfo_entries *e, void *arg)
 static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
 {
 	struct eventfd_dump_arg da = { .id = id, .p = p, };
-	return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da);
+	return parse_fdinfo(lfd, FD_TYPES__EVENTFD, false, dump_eventfd_entry, &da);
 }
 
 static const struct fdtype_ops eventfd_ops = {
diff --git a/eventpoll.c b/eventpoll.c
index 103d128..dd9d23f 100644
--- a/eventpoll.c
+++ b/eventpoll.c
@@ -89,7 +89,7 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
 		     &e, PB_EVENTPOLL))
 		return -1;
 
-	return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &id);
+	return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, false, dump_eventpoll_entry, &id);
 }
 
 static const struct fdtype_ops eventpoll_ops = {
diff --git a/include/proc_parse.h b/include/proc_parse.h
index b04acbf..bb54d3c 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -136,7 +136,7 @@ union fdinfo_entries {
 	InotifyWdEntry ify;
 };
 
-extern int parse_fdinfo(int fd, int type,
+extern int parse_fdinfo(int fd, int type, bool optional,
 		int (*cb)(union fdinfo_entries *e, void *arg), void *arg);
 
 #endif /* PROC_PARSE_H__ */
diff --git a/inotify.c b/inotify.c
index 46b1797..9dc638e 100644
--- a/inotify.c
+++ b/inotify.c
@@ -95,7 +95,7 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
 	if (pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie, PB_INOTIFY))
 		return -1;
 
-	return parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &id);
+	return parse_fdinfo(lfd, FD_TYPES__INOTIFY, false, dump_inotify_entry, &id);
 }
 
 static const struct fdtype_ops inotify_ops = {
diff --git a/proc_parse.c b/proc_parse.c
index 8023a41..ede6363 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -714,7 +714,7 @@ static void parse_fhandle_encoded(char *tok, FhEntry *fh)
 
 #define fdinfo_field(str, field)	!strncmp(str, field":", sizeof(field))
 
-int parse_fdinfo(int fd, int type,
+int parse_fdinfo(int fd, int type, bool optional,
 		int (*cb)(union fdinfo_entries *e, void *arg), void *arg)
 {
 	FILE *f;
@@ -825,8 +825,11 @@ int parse_fdinfo(int fd, int type,
 
 	fclose(f);
 	if (!entry_met) {
-		pr_err("No records of type %d found in fdinfo file\n", type);
-		goto parse_err;
+		if (!optional) {
+			pr_err("No records of type %d found in fdinfo file\n", type);
+			goto parse_err;
+		} else
+			return -2;
 	}
 
 	return 0;
diff --git a/signalfd.c b/signalfd.c
index 578fec0..0abd477 100644
--- a/signalfd.c
+++ b/signalfd.c
@@ -57,7 +57,7 @@ static int dump_signalfd_entry(union fdinfo_entries *e, void *arg)
 static int dump_one_signalfd(int lfd, u32 id, const struct fd_parms *p)
 {
 	struct signalfd_dump_arg da = { .id = id, .p = p, };
-	return parse_fdinfo(lfd, FD_TYPES__SIGNALFD, dump_signalfd_entry, &da);
+	return parse_fdinfo(lfd, FD_TYPES__SIGNALFD, false, dump_signalfd_entry, &da);
 }
 
 static const struct fdtype_ops signalfd_ops = {
-- 
1.7.7.6



More information about the CRIU mailing list