mkdir_p: account for '//foo/bar'

As Richard reported, dirname('//') returns //.  But mkdir_p only stops
when called with '/', resulting in infinite recursion when given a
pathname '//foo/bar'.

Reported-by: richard -rw- weinberger <richard.weinberger@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
fix spacing

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
quiet gcc 4.4.7 warning about saveptr use before initialization

The recent change to use strtok_r causes a build warning with this older
gcc version, so initialize saveptr to NULL to quiet the compiler and
unbreak the build. There was no warning with gcc 4.7.2 that I
originally tested with.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
init: unnest interrupt_handler

There is no need to use nested functions voodoo.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
init: Fix whitespace damage

While we are here, fix the whitespace damage.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
start: Detect early failure of the new child

If the process in the new namespace dies very early
we have currently no chance to detect this.
The parent process will just die due to SIGPIPE
if it write to the fd used for synchronisation and
nobody will notice the real cause of the problem.

Install a SIGCHLD handler to detect the death.
Later when the child does execve() to the init within
the new namespace the handler will be disabled automatically.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
utils: reimplement/fix mkdir_p()

Reimplement mkdir_p() such that it:
 ...handles relativ paths correctly. (currently it crashes)
 ...does not rely on dirname().
 ...is not recursive.
 ...is shorter. ;-)

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Revert "utils: reimplement/fix mkdir_p()"

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@ubuntu.com>
Revert "start: Detect early failure of the new child"

This reverts commit 5a5c35c3a01afec515e688c8366e6f893985518d.

This commit was preventing startup of containers using lxc hooks and
shutdown of all other containers, requiring the use of a good old
kill -9 to get rid of lxc-start after a container shutdown.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
utils: reimplement/fix mkdir_p() (v2)

Reimplement mkdir_p() such that it:
 ...handles relativ paths correctly. (currently it crashes)
 ...does not rely on dirname().
 ...is not recursive.
 ...is shorter. ;-)

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
python: Lots of fixes in C extension

Fixes a lot of issues found by a code review done by Barry Warsaw.

Those include:
 - Wrong signature for getters
 - Various memory leaks
 - Various optimizations
 - More consistent return values
 - Proper exception handling

Reported-by: Barry Warsaw <barry@ubuntu.com>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>