[CRIU] [PATCH] ipc_ns: close file immediately when we don't need it

Huang Qiang h.huangqiang at huawei.com
Thu Oct 25 04:14:32 EDT 2012


According to Andrew's advice, change the close file logic a bit, to
make the code seems more readable.

Signed-off-by: Huang Qiang <h.huangqiang at huawei.com>
---
 ipc_ns.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/ipc_ns.c b/ipc_ns.c
index d006b3d..d31f162 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -876,10 +876,10 @@ static int prepare_ipc_var(int pid)
 		return -1;

 	ret = pb_read_one(fd, &var, PB_IPCNS_VAR);
+	close_safe(&fd);
 	if (ret <= 0) {
 		pr_err("Failed to read IPC namespace variables\n");
-		ret = -EFAULT;
-		goto err;
+		return -EFAULT;
 	}

 	ipc_sysctl_req(var, CTL_PRINT);
@@ -889,13 +889,10 @@ static int prepare_ipc_var(int pid)

 	if (ret < 0) {
 		pr_err("Failed to prepare IPC namespace variables\n");
-		ret = -EFAULT;
-		goto err;
+		return -EFAULT;
 	}
-	return close_safe(&fd);
-err:
-	close_safe(&fd);
-	return ret;
+
+	return 0;
 }

 int prepare_ipc_ns(int pid)
-- 1.7.1



More information about the CRIU mailing list