[CRIU] [PATCH 4/N] crtools: resolve work_dir and imgs_dir path to absolute

Ruslan Kuprieiev kupruser at gmail.com
Fri Nov 15 10:15:09 PST 2013


On 15.11.2013 17:46, Pavel Emelyanov wrote:
> On 11/15/2013 05:33 AM, Ruslan Kuprieiev wrote:
>> 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);
> NAK. Image dir should be passed into open_image_dir() as is.
>
>> +			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);
> Same for work dir -- we should chrdir into what user gave us, not
> to somehow converted path.

Why? Isn't it comfortable to use relative to cwd paths for work and 
images dirs?
We chdir into what user gave us, but we convert relative into full paths 
to not mess around with relative paths.

>
>> +			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);
> Huh? Page server needs image dir to work on.
>
>> +
>> +	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"
>>
>



More information about the CRIU mailing list