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

Andrey Vagin avagin at openvz.org
Tue Dec 9 01:26:07 PST 2014


We may not have permissions for this.

Reported-by: Ruslan Kuprieiev <kupruser at gmail.com>
Cc: Ruslan Kuprieiev <kupruser at gmail.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/cwd00.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/test/zdtm/live/static/cwd00.c b/test/zdtm/live/static/cwd00.c
index d8d0397..e725bfc 100644
--- a/test/zdtm/live/static/cwd00.c
+++ b/test/zdtm/live/static/cwd00.c
@@ -2,6 +2,8 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
 #include <string.h>
 
 #include "zdtmtst.h"
@@ -14,12 +16,14 @@ TEST_OPTION(dirname, string, "directory name", 1);
 
 int main(int argc, char **argv)
 {
-	char cwd0[256], cwd1[256], cwd2[256];
+	char cwd1[256], cwd2[256];
+	int fd;
 
 	test_init(argc, argv);
 
-	if (!getcwd(cwd0, sizeof(cwd0))) {
-		err("can't get cwd: %m\n");
+	fd = open(".", O_DIRECTORY | O_RDONLY);
+	if (fd == -1) {
+		err("Unable to open the current dir");
 		exit(1);
 	}
 
@@ -52,8 +56,8 @@ int main(int argc, char **argv)
 		pass();
 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(fd)) {
+		err("can't restore cwd");
 		exit(1);
 	}
 	if (rmdir(dirname)) {
-- 
1.9.3



More information about the CRIU mailing list