[CRIU] [PATCH 4/5] crtools: chdir to work directory
Ruslan Kuprieiev
kupruser at gmail.com
Fri Nov 15 13:47:09 PST 2013
On 15.11.2013 21:43, Pavel Emelyanov wrote:
> On 11/16/2013 01:21 AM, Ruslan Kuprieiev wrote:
>> On 15.11.2013 21:08, Pavel Emelyanov wrote:
>>> On 11/16/2013 12:10 AM, Ruslan Kuprieiev wrote:
>>>> On 15.11.2013 19:43, Pavel Emelyanov wrote:
>>>>> On 11/15/2013 11:04 PM, Ruslan Kuprieiev wrote:
>>>>>> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
>>>>>> ---
>>>>>> crtools.c | 32 +++++++++++++++++++++-----------
>>>>>> 1 file changed, 21 insertions(+), 11 deletions(-)
>>>>>>
>>>>>> diff --git a/crtools.c b/crtools.c
>>>>>> index d8de2ef..a058b46 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,10 @@ 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;
>>>>>> - }
>>>>>> + imgs_dir = optarg;
>>>>>> break;
>>>>>> case 'W':
>>>>>> + work_dir = optarg;
>>>>>> break;
>>>>>> case 'o':
>>>>>> opts.output = optarg;
>>>>>> @@ -283,6 +282,9 @@ int main(int argc, char *argv[])
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> + if (work_dir == NULL)
>>>>>> + work_dir = imgs_dir;
>>>>>> +
>>>>>> log_set_loglevel(log_level);
>>>>>>
>>>>>> if (log_init(opts.output))
>>>>>> @@ -291,15 +293,23 @@ int main(int argc, char *argv[])
>>>>>> if (opts.img_parent)
>>>>>> pr_info("Will do snapshot from %s\n", opts.img_parent);
>>>>>>
>>>>>> - ret = open_image_dir(".");
>>>>>> - if (ret < 0) {
>>>>>> - pr_perror("Can't open current directory");
>>>>>> - return -1;
>>>>>> - }
>>>>>> -
>>>>>> if (optind >= argc)
>>>>>> goto usage;
>>>>>>
>>>>>> + /* We must not open imgs dir, if service is called */
>>>>>> + if (strcmp(argv[optind], "service")) {
>>>>> This is really ugly. Only one cmd string evaluation in code please.
>>>> I've been thinking on it a lot and all my other variants are a lot
>>>> bigger and uglier.
>>> Why not like this
>>>
>>>
>>> chdir(work_dir);
>>>
>>> if (cmd == service)
>>> return cr_service();
>>>
>>> open_images_dir();
>>>
>>> if (cmd == dump)
>>> return cr_dump();
>>> if (cmd == restore)
>>> return cr_restore();
>>>
>>> ?
>> How can i open images dir from work_dir, if i get relative imgs_dir path
>> and i can't use realpath?
> I see. Yes, that's the problem. OK, then let's do it this way for a while.
> I'll send more comments soon, I've found two more bugs.
Oh, ok=)
More information about the CRIU
mailing list