[CRIU] [PATCH 1/5] parse_mountinfo: add the "end" block into the main loop

Oleg Nesterov oleg at redhat.com
Sun Mar 29 10:23:57 PDT 2015


Preparation to simplify the review. parse_mountinfo() assumes that:

1. The "err:" block does all the necessary cleanups on failure.

   This is wrong, see the next patch.

2. We can never skip the mountpoint.

   This is true, but we are going to change this.

s/goto err/goto end/ in the main loop, add the "end:" label which inserts
the new mount_info into the list and then checks ret != 0 to figure out
whether we need to abort.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 proc_parse.c |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/proc_parse.c b/proc_parse.c
index 3009905..a06a65a 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -991,22 +991,19 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
 
 	while (fgets(str, sizeof(str), f)) {
 		struct mount_info *new;
-		int ret;
+		int ret = -1;
 		char *fst = NULL;
 
 		new = mnt_entry_alloc();
 		if (!new)
-			goto err;
+			goto end;
 
 		new->nsid = nsid;
 
-		new->next = list;
-		list = new;
-
 		ret = parse_mountinfo_ent(str, new, &fst);
 		if (ret < 0) {
 			pr_err("Bad format in %d mountinfo\n", pid);
-			goto err;
+			goto end;
 		}
 
 		pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n",
@@ -1019,9 +1016,17 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
 			if (ret) {
 				pr_err("Failed to parse FS specific data on %s\n",
 						new->mountpoint);
-				goto err;
+				goto end;
 			}
 		}
+end:
+		if (new) {
+			new->next = list;
+			list = new;
+		}
+
+		if (ret)
+			goto err;
 	}
 out:
 	fclose(f);
-- 
1.5.5.1



More information about the CRIU mailing list