[CRIU] [PATCH] crtools: chdir after initiating log

Ruslan Kuprieiev kupruser at gmail.com
Sun Nov 10 18:30:32 PST 2013


Lets change dir to images_dir after initiating log.
So, if logfile path isn't absolute, it will be open at cwd.
Currently, if -o is before -D, work dir will be cwd, and if -o is after -D, work dir will be at -D. So, if you wan't log/pidfile to be created at some dir that isn't cwd, you should use absolute paths for both pidfile and logfile.


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 crtools.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/crtools.c b/crtools.c
index 60fd2e8..1a4ed9e 100644
--- a/crtools.c
+++ b/crtools.c
@@ -79,6 +79,7 @@ int main(int argc, char *argv[])
 	int opt, idx;
 	int log_inited = 0;
 	int log_level = 0;
+	char *images_dir = ".";
 
 	BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
 
@@ -163,11 +164,7 @@ int main(int argc, char *argv[])
 			opts.restore_detach = true;
 			break;
 		case 'D':
-			if (chdir(optarg)) {
-				pr_perror("Can't change directory to %s",
-						optarg);
-				return -1;
-			}
+			images_dir = optarg;
 			break;
 		case 'o':
 			opts.output = optarg;
@@ -292,6 +289,11 @@ int main(int argc, char *argv[])
 			return ret;
 	}
 
+	if (chdir(images_dir)) {
+		pr_perror("Can't change directory to %s", images_dir);
+		return -1;
+	}
+
 	if (opts.img_parent)
 		pr_info("Will do snapshot from %s\n", opts.img_parent);
 
-- 
1.8.1.2



More information about the CRIU mailing list