[CRIU] [PATCH] zdtm/cwd02: avoid resolving an abs path

Andrey Vagin avagin at openvz.org
Wed Dec 24 11:32:25 PST 2014


We may not have permissions for this.

Reported-by: Mr Jenkins
Fixes: 7dbd38dbc939 ("zdtm: set additional groups along with uids and gids")
Cc: Ruslan Kuprieiev <kupruser at gmail.com>
Signed-off-by: Andrew Vagin <avagin at openvz.org>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/cwd02.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/test/zdtm/live/static/cwd02.c b/test/zdtm/live/static/cwd02.c
index e7747f4..173ddb4 100644
--- a/test/zdtm/live/static/cwd02.c
+++ b/test/zdtm/live/static/cwd02.c
@@ -16,8 +16,7 @@ TEST_OPTION(dirname, string, "directory name", 1);
 
 int main(int argc, char **argv)
 {
-	char cwd0[256];
-	int fd, pid, p[2], aux;
+	int cwd, fd, pid, p[2], aux;
 	struct stat std, stf;
 
 	test_init(argc, argv);
@@ -31,8 +30,9 @@ int main(int argc, char **argv)
 		exit(aux ? 1 : 0);
 	}
 
-	if (!getcwd(cwd0, sizeof(cwd0))) {
-		err("can't get cwd: %m\n");
+	cwd = open(".", O_DIRECTORY | O_RDONLY);
+	if (cwd == -1) {
+		err("Unable to open the current dir");
 		exit(1);
 	}
 
@@ -82,8 +82,8 @@ int main(int argc, char **argv)
 
 cleanup:
 	/* return to the initial dir before writing out results */
-	if (chdir(cwd0)) {
-		err("can't change directory to %s: %m\n", cwd0);
+	if (fchdir(cwd)) {
+		err("can't restore cwd");
 		exit(1);
 	}
 
-- 
1.9.3



More information about the CRIU mailing list