[CRIU] [PATCH] scripts: set CRIU_IMAGE_DIR when running scripts

Pavel Emelyanov xemul at parallels.com
Tue Aug 12 10:00:32 PDT 2014


On 08/12/2014 07:50 PM, Tycho Andersen wrote:
> On Tue, Aug 12, 2014 at 07:46:52PM +0400, Pavel Emelyanov wrote:
>> On 08/12/2014 07:07 PM, Tycho Andersen wrote:
>>> Hi Pavel,
>>>
>>> On Tue, Aug 12, 2014 at 06:31:45PM +0400, Pavel Emelyanov wrote:
>>>> On 08/12/2014 06:22 PM, Tycho Andersen wrote:
>>>>> When doing a restore for LXC, we store some other metadata (which bridge a veth
>>>>> was on) in the image directory so that the restore script can correctly unlock
>>>>> a network device and attach it to the right interface. This patch is needed so
>>>>> that the script can find this metadata.
>>>>>
>>>>> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
>>>>> ---
>>>>>  util.c | 7 +++++++
>>>>>  1 file changed, 7 insertions(+)
>>>>>
>>>>> diff --git a/util.c b/util.c
>>>>> index a180ea5..4ff8768 100644
>>>>> --- a/util.c
>>>>> +++ b/util.c
>>>>> @@ -460,6 +460,7 @@ int run_scripts(char *action)
>>>>>  {
>>>>>  	struct script *script;
>>>>>  	int ret = 0;
>>>>> +	char image_dir[PATH_MAX];
>>>>
>>>> Odd enough, but we have a magic constant PSFDS that says "how much 
>>>> would the path to /proc/self/fd/%d occupy on the stack" :)
>>>>
>>>>>  
>>>>>  	pr_debug("Running %s scripts\n", action);
>>>>>  
>>>>> @@ -468,6 +469,12 @@ int run_scripts(char *action)
>>>>>  		return -1;
>>>>>  	}
>>>>>  
>>>>> +	sprintf(image_dir, "/proc/%ld/fd/%d", (long) getpid(), get_service_fd(IMG_FD_OFF));
>>>>
>>>> Maybe /proc/self/fd/%d would be nicer? This would allow using the
>>>> PSFDS above :)
>>>
>>> I this, but it seems that the fds are declared O_CLOEXEC or something?
>>> It doesn't look like open_image_dir does that, though, so I'm not sure
>>> what is going on. They weren't available in the script, in any case.
>>
>> Ah, no. It's me being stupid. The path you push into script will be used
>> by this script, so open("/proc/self/fd/100") in script will open script's
>> fd, not criu's one :)
> 
> Right, but presumably system() is implemented via fork(), which would
> inherit the fds? I guess maybe not, since it doesn't work :)

Image dir is the service fd which is O_CLOEXEC. So this explains everything.

Thanks,
Pavel



More information about the CRIU mailing list