[CRIU] [PATCH 4/N] crtools: resolve work_dir and imgs_dir path to absolute
Ruslan Kuprieiev
kupruser at gmail.com
Thu Nov 14 17:33:52 PST 2013
Lets resolve paths to not depend on current location.
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
crtools.c | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/crtools.c b/crtools.c
index d8de2ef..7eb9501 100644
--- a/crtools.c
+++ b/crtools.c
@@ -78,6 +78,8 @@ int main(int argc, char *argv[])
int ret = -1;
int opt, idx;
int log_level = 0;
+ char *imgs_dir = ".";
+ char *work_dir = NULL;
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
@@ -163,13 +165,20 @@ 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);
+ imgs_dir = xmalloc(PATH_MAX);
+ imgs_dir = realpath(optarg, imgs_dir);
+ if (!imgs_dir) {
+ pr_perror("Bad images directory path");
return -1;
}
break;
case 'W':
+ work_dir = xmalloc(PATH_MAX);
+ work_dir = realpath(optarg, work_dir);
+ if (!work_dir) {
+ pr_perror("Bad work directory path");
+ return -1;
+ }
break;
case 'o':
opts.output = optarg;
@@ -283,23 +292,37 @@ int main(int argc, char *argv[])
}
}
+ if (!work_dir)
+ work_dir = imgs_dir;
+
+ if (chdir(work_dir)) {
+ pr_perror("Can't change directory to %s", work_dir);
+ return -1;
+ }
+
log_set_loglevel(log_level);
if (log_init(opts.output))
return -1;
+ if (optind >= argc)
+ goto usage;
+
+ if (!strcmp(argv[optind], "page-server"))
+ return cr_page_server(opts.restore_detach);
+
+ if (!strcmp(argv[optind], "service"))
+ return cr_service(opts.restore_detach);
+
if (opts.img_parent)
pr_info("Will do snapshot from %s\n", opts.img_parent);
- ret = open_image_dir(".");
+ ret = open_image_dir(imgs_dir);
if (ret < 0) {
- pr_perror("Can't open current directory");
+ pr_perror("Can't open images directory");
return -1;
}
- if (optind >= argc)
- goto usage;
-
if (!strcmp(argv[optind], "dump")) {
if (!tree_id)
goto opt_pid_missing;
@@ -343,12 +366,6 @@ int main(int argc, char *argv[])
return cr_exec(pid, argv + optind + 1);
}
- if (!strcmp(argv[optind], "page-server"))
- return cr_page_server(opts.restore_detach);
-
- if (!strcmp(argv[optind], "service"))
- return cr_service(opts.restore_detach);
-
pr_msg("Unknown command \"%s\"\n", argv[optind]);
usage:
pr_msg("\n"
--
1.8.1.2
More information about the CRIU
mailing list