[lxc-devel] [PATCH 1/2] Revert "utils: reimplement/fix mkdir_p()"

Stéphane Graber stgraber at ubuntu.com
Thu Apr 18 08:57:14 UTC 2013


On 04/18/2013 10:48 AM, Stéphane Graber wrote:
> On 04/18/2013 10:34 AM, Stéphane Graber wrote:
>> On 04/18/2013 10:32 AM, Stéphane Graber wrote:
>>> This reverts commit 8de4140644f01180f2fdab55b0ab0f13d1c761c6.
>>>
>>> This commit was preventing container startup on my machine, making them
>>> all fail with various "No such file or directory" errors.
>>>
>>> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
>>
>> Was directly applied to the staging branch as the issue was preventing
>> regular use of LXC.
> 
> Hmm, with the recent round of moderation on the list, it looks like I
> may have applied the wrong version of the patch.
> 
> There's two identically named patch on the ML but with different content.
> I'll test the second one and see if that solves my issues.
> 
> In the future, please include "v2" in the name of the second patch so
> that people trying to figure out what to apply to staging don't get
> confused ;)

Confirmed, the v2 seems fine here. Pushing that to staging.

> 
>>> ---
>>>  src/lxc/utils.c | 48 +++++++++++++++++++++++++++++++-----------------
>>>  1 file changed, 31 insertions(+), 17 deletions(-)
>>>
>>> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
>>> index 9794553..e07ca7b 100644
>>> --- a/src/lxc/utils.c
>>> +++ b/src/lxc/utils.c
>>> @@ -95,25 +95,39 @@ extern int get_u16(unsigned short *val, const char *arg, int base)
>>>  	return 0;
>>>  }
>>>  
>>> +static int is_all_slashes(char *path)
>>> +{
>>> +	while (*path && *path == '/')
>>> +		path++;
>>> +	if (*path)
>>> +		return 0;
>>> +	return 1;
>>> +}
>>> +
>>>  extern int mkdir_p(char *dir, mode_t mode)
>>>  {
>>> -	char *tmp = dir;
>>> -	char *orig = dir;
>>> -	char *makeme;
>>> -
>>> -	do {
>>> -		dir = tmp + strspn(tmp, "/");
>>> -		tmp = dir + strcspn(dir, "/");
>>> -		makeme = strndupa(orig, dir - orig);
>>> -		if (*makeme) {
>>> -			if (!access(makeme, F_OK))
>>> -				return 0;
>>> -			if (mkdir(makeme, mode)) {
>>> -				SYSERROR("failed to create directory '%s'\n", makeme);
>>> -				return -1;
>>> -			}
>>> -		}
>>> -	} while(tmp != dir);
>>> +	int ret;
>>> +	char *d;
>>> +
>>> +	if (is_all_slashes(dir))
>>> +		return 0;
>>> +
>>> +	d = strdup(dir);
>>> +	if (!d)
>>> +		return -1;
>>> +
>>> +	ret = mkdir_p(dirname(d), mode);
>>> +	free(d);
>>> +	if (ret)
>>> +		return -1;
>>> +
>>> +	if (!access(dir, F_OK))
>>> +		return 0;
>>> +
>>> +	if (mkdir(dir, mode)) {
>>> +		SYSERROR("failed to create directory '%s'\n", dir);
>>> +		return -1;
>>> +	}
>>>  
>>>  	return 0;
>>>  }
>>>


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130418/a59872f2/attachment.pgp>


More information about the lxc-devel mailing list