From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25986 invoked by alias); 17 Dec 2014 22:52:22 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34000 Received: (qmail 28151 invoked from network); 17 Dec 2014 22:52:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=jeLIB8AUO+m61XTzR1m+S4RnzBMcms3KCI63lxXEclQ=; b=Og0+2ae+9dUUGWAKAuDwCTqYvknXsXzy49fm3bbxXzWClXqfR5NSTX/xUdi8edvV4B 7hCUq1Dp+dOSwfwm2ml3ajU0/0dbhmROx3+9piY3D0XeGg1+dCLAVKPdrvnrJfzUjs0X asU7jKTNvYnQvX+aIJpdIMpfwm8CHZl5SlRWGJeCOCVmpqClbmJ66CX06WiqcY8YqSMV fGAz0DoUBqkYx9GFlH984kEsTmZx4g4qr13plKulwZuj9X1G4yotR9tuICTK8Aqb4qZw 9/qMl1P/IiXMC0UUzidpTzFMRrSqWM72/3G2C70BSYK7x2ok3R15c/7Mj+QJwkWxbxn+ Ud0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=jeLIB8AUO+m61XTzR1m+S4RnzBMcms3KCI63lxXEclQ=; b=YSRTfydBOlRvGr/wIYqLi0fp6EvWBL3QBrgydMku2x48DGMgY44466wxjXcWaunw15 tkN9PnbPI4owo36isu+899QiKnKzrFx962zKobECDBqjO6wru92FkwMvxSqiGhPx6KE3 iBGR9jMf3FCh47PUKlXKo2p79S7Q3h2rJ4oxNTpsKDjpjkwGpYyVZTg+BB3GivtTgrEA Putx/Hhr1D81DWySjfQuzDCy/dkrGv+UI9Rk9/ziziIAa0i74F5LzArtflBLiZcIE17b nWUIFScvJKcKYdRXkhwU8hzZOapMvVBrqwDYsJxLbeiQL/eXEFDvcxLnyD638nLBqMu2 AfwA== X-Gm-Message-State: ALoCoQkEazTFFjFMyT+b4FzISbjdCk/sB9Qg6qzKKialvtpuHyaMNpZS/g3nRZ7M6zQnlRdDN8SI MIME-Version: 1.0 X-Received: by 10.60.103.172 with SMTP id fx12mr10294013oeb.81.1418856734998; Wed, 17 Dec 2014 14:52:14 -0800 (PST) In-Reply-To: <141217085435.ZM545@torch.brasslantern.com> References: <141216222752.ZM19425@torch.brasslantern.com> <141217085435.ZM545@torch.brasslantern.com> Date: Wed, 17 Dec 2014 14:52:14 -0800 Message-ID: Subject: Re: Bug in interaction with pid namespaces From: Chirantan Ekbote To: Bart Schaefer Cc: zsh-workers@zsh.org Content-Type: text/plain; charset=UTF-8 On Wed, Dec 17, 2014 at 8:54 AM, Bart Schaefer wrote: > On Dec 16, 11:50pm, Chirantan Ekbote wrote: > } > } We're not trying to use zsh as a replacement for init. I first noticed > } this issue because the chrome os build system recently switched to > } using pid namespaces in the build chroot. [...] In the actual workflow > } where this is an issue for me, the pid is somewhere in the 240 to 270 > } range and zsh is only meant to behave like a regular shell. > > OK, so the issue is that zsh is started as a (possibly indirect) child > of whatever was given "leadership" of the namespace, but at the time > zsh starts GETPGRP() == 0. > > That sounds like a bug in one of the ancestor processes, then, because > shouldn't whatever *that* is, have become a group leader, or assigned > the process group to the fork() pid before execve() of zsh? > It quite possibly is a bug in the ancestor process. I've also brought this up with our build team and I think they may make the change you suggest. > > } So the problem is that on exit zsh gives a warning: > } > } zsh: can't set tty pgrp: no such process > } > } which I thought was due to the call to setpgrp() but is actually in > } the call to attachtty(). > > Aha. That means that one of > > tcsetpgrp(SHTTY, pgrp) > or > arg = &pgrp > ioctl(SHTTY, TIOCSPGRP, &arg) > > is returning -1 and errno == ESRCH. Which makes sense if pgrp == 0. > > But that also means that zsh is being invoked as an interactive shell, > because attachtty() is a no-op otherwise. I can't imagine why the > chrome os build would need to run an interactive shell. > I won't bore you with the details of the build process because they would bore you. The short version is to start working on chrome os we run a command (cros_sdk) that downloads updates, sets up the environment, mounts various directories inside a chroot, and at the end runs exec chroot "${chroot_dir}" sudo -u ${username} -i It is at this point that zsh is launched (since it is my login shell) and from there, I can run commands to build different components or an entire image of chrome os. > However, I suggest the following. The mypgrp = origpgrp assignment is > questionable because the pgrp won't actually have been changed, but it > may help elsewhere in tests that mypgrp != GETPGRP(). Shell exit is > not the only place where release_pgrp() is called. > > diff --git a/Src/jobs.c b/Src/jobs.c > index 8c4254a..c6e1bce 100644 > --- a/Src/jobs.c > +++ b/Src/jobs.c > @@ -2779,8 +2779,11 @@ void > release_pgrp(void) > { > if (origpgrp != mypgrp) { > - attachtty(origpgrp); > - setpgrp(0, origpgrp); > + /* in linux pid namespaces, origpgrp may never have been set */ > + if (origpgrp) { > + attachtty(origpgrp); > + setpgrp(0, origpgrp); > + } > mypgrp = origpgrp; > } > } This works for me. Thanks very much for your help :-)