[CRIU] [PATCH] fdset: Make fdset open helpers to work in all-or-nothing manner

Cyrill Gorcunov gorcunov at openvz.org
Tue Jan 31 04:38:40 EST 2012


When cr_fdset_open or prep_cr_fdset_for_restore is called
the caller expects either all operations are successfull
or there is some error happened and NULL returned, but
instead at moment partially filled fdset might be returned.

Fix it -- we either should get all or nothing.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 crtools.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/crtools.c b/crtools.c
index 926d26b..d7f956d 100644
--- a/crtools.c
+++ b/crtools.c
@@ -157,15 +157,18 @@ struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask, struct cr_fdset
 			pr_perror("Unable to open %s\n", path);
 			goto err;
 		}
+		cr_fdset->fds[i] = ret;
 
 		pr_debug("Opened %s with %d\n", path, ret);
 		if (write_img(ret, &fdset_template[i].magic))
 			goto err;
-
-		cr_fdset->fds[i] = ret;
 	}
-err:
+
 	return cr_fdset;
+
+err:
+	close_cr_fdset(&cr_fdset);
+	return NULL;
 }
 
 struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask)
@@ -194,6 +197,7 @@ struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask)
 			pr_perror("Unable to open %s\n", path);
 			goto err;
 		}
+		cr_fdset->fds[i] = ret;
 
 		pr_debug("Opened %s with %d\n", path, ret);
 		if (read_img(ret, &magic) < 0)
@@ -203,11 +207,13 @@ struct cr_fdset *prep_cr_fdset_for_restore(int pid, unsigned long use_mask)
 			pr_err("Magic doesn't match for %s\n", path);
 			goto err;
 		}
-
-		cr_fdset->fds[i] = ret;
 	}
-err:
+
 	return cr_fdset;
+
+err:
+	close_cr_fdset(&cr_fdset);
+	return NULL;
 }
 
 void close_cr_fdset(struct cr_fdset **cr_fdset)
-- 
1.7.7.6



More information about the CRIU mailing list