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

Pavel Emelyanov xemul at parallels.com
Tue Aug 12 08:46:52 PDT 2014


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 :)

I withdraw my previous comments then.

> Tycho
> 
>>> +	if (setenv("CRTOOLS_IMAGE_DIR", image_dir, 1)) {
>>> +		pr_perror("Can't set CRTOOLS_IMAGE_DIR=%s", image_dir);
>>> +		return -1;
>>> +	}
>>> +
>>>  	list_for_each_entry(script, &opts.scripts, node) {
>>>  		if (script->path == SCRIPT_RPC_NOTIFY) {
>>>  			pr_debug("\tRPC\n");
>>>
>>
> .
> 



More information about the CRIU mailing list