From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH 0/15] Add preliminary support for Linux containers Date: Wed, 08 Jul 2015 23:59:52 +0200 Message-ID: <87vbduia3r.fsf@gnu.org> References: <87lhetcudk.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> <87h9pgl0s5.fsf@gnu.org> <87oajmlsv1.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCxNm-0003Q1-Uu for guix-devel@gnu.org; Wed, 08 Jul 2015 17:59:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCxNk-0007oh-6v for guix-devel@gnu.org; Wed, 08 Jul 2015 17:59:58 -0400 In-Reply-To: (David Thompson's message of "Wed, 8 Jul 2015 09:00:33 -0400") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: "Thompson, David" Cc: guix-devel "Thompson, David" skribis: > On Wed, Jul 8, 2015 at 8:46 AM, Ludovic Court=C3=A8s wrote: >> "Thompson, David" skribis: >> >>> On Tue, Jul 7, 2015 at 6:28 AM, Ludovic Court=C3=A8s wro= te: >> >> [...] >> >>>>> (lambda () >>>>> (sethostname "guix-0.8.3")) >>>> >>>> Surprisingly, calling =E2=80=98getpid=E2=80=99 in the thunk returns th= e PID of the >>>> parent (I was expecting it to return 1.) Not sure why that is the >>>> case. I=E2=80=99m still amazed that this works as non-root, BTW. >>> >>> The first process created inside the PID namespace gets the honor of >>> being PID 1, not the process created with the 'clone' call. >>> >>> For more information, see: https://lwn.net/Articles/532748/ >> >> To me, the thunk above is just like =E2=80=98childFunc=E2=80=99 in >> =E2=80=93i.e., it=E2=80=99s the proced= ure that =E2=80=98clone=E2=80=99 >> calls in the first child process of the new PID name space. >> >> What am I missing? > > It's non-intuitive because PID namespaces are given special treatment. > The cloned process is like PID 1 in the sense that if you fork, the > new process is PID 2. However, if you call 'getpid' in the cloned > process, it returns the PID in the context of the parent PID > namespace, and you are expecting PID 1. > > In that example from LWN, 'childFunc' calls 'execvp', and *that* new > process becomes PID 1 (and 'getpid' agrees). This is the usual > pattern I see in all container implementations: The process that > calls clone sets up the environment and then execs the real init > system. > > Is it more clear now? Yes, indeed. The weird part is that =E2=80=98exec=E2=80=99 does not create= a new process, so it=E2=80=99s not supposed to change the return value of =E2=80= =98getpid=E2=80=99. But I guess it=E2=80=99s just an artifact of the whole name space hack. ;-) Thanks! Ludo=E2=80=99.