Subject: Getting a real pid 1 init in a container
From: Grzegorz Nosek <grzegorz.nosek@gmail.com>
Date: Mon, 19 Mar 2012 19:08:54 +0100

Hi,

Continuing my quest to run Ubuntu 12.04 under Linux-VServer (so far only 
on kernels I have on hand, probably considered ancient around these parts).

Can anybody please explain to me what is the semantics of the fakeinit 
vserver flag? I changed /sbin/init to the following script to see what's 
going on:

#!/bin/sh

echo $$
exec /sbin/init.real

With initstyle=plain and various combinations of fakeinit and PID 
namespaces I'm getting:

fakeinit, no pidns:

pid is 1 and upstart (init.real) apparently starts successfully but does 
not receive SIGCHLD when a process inside the container dies, thus 
breaking start/stop/restart tools (and waitpid(-1) returns -ESRCH). I 
did not instrument the real init to see if the SIGCHLD goes there instead.

!fakeinit, no pidns:

init starts with a high pid (like it was run on the host) and becomes 
telinit, so the container does not start at all. The page at 
http://linux-vserver.org/Upstart_issues#Notes_for_older_kernels suggests 
this is an issue for 2.6.22 but I'm testing this on 2.6.27 and 2.6.35. 
Also, I'm not sure how exactly is the result of getpid() cached over 
exec() but I'll just accept it at face value.

!fakeinit, with pidns:

init starts with pid 2, fails to work just like above due to pid != 1

fakeinit, with pidns:

exactly as above, pid 2, doesn't work either

Having a quick look at the kernel and util-vserver code, I see some 
correlation between vx_set_reaper(), which I apparently want to call, 
and the fakeinit flag, looking like it wants to prevent it. Will give it 
a closer look tomorrow, but in the meantime, any comments about the 
fakeinit flag (and its relation to setting the reaper process) are 
greatly appreciated.

Best regards,
  Grzegorz Nosek