From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4215 invoked by alias); 16 Dec 2014 23:07:32 -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: 33982 Received: (qmail 9448 invoked from network); 16 Dec 2014 23:07:30 -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:date:message-id:subject:from:to:content-type; bh=wrYqQi/s74IwXTbwNQUG/O+qdWVSH51/x/+tVcJ71bc=; b=oZY9ObWTADyti9oyO1erKleVUe28PSti0FtyUJPn6Nun9mNMyyh5ucMBK1uYysRrD2 1RTeLDO3uDT7RciasXe5tDF4atdVtbksH82IQbNr8l7LuJuAibPLBjEhN0GkEr6eoDfl z+1oH0H8uwS2yvbh4Bi1QoEoSSTLSNZmA8l9DguK2Xp68q9L4XZOCQlPoc72XIIYihSG 9UVCEVOby13I5MUQtHsOyGr+MeDs+Hik//FTK5W8nd5tuqaRNDjUCkXA10vOqujB2awL OmJ+5eUqVRx91BU8H58gRXH/s2cYWisTniZ3luj0dJcYkPEHvSoTNPXQEVbEcvHLrDEB d6Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=wrYqQi/s74IwXTbwNQUG/O+qdWVSH51/x/+tVcJ71bc=; b=SSzlEMIFw4grq05psASsuqBW7+a6CpTqIuPfWHpBwJP//ZkooIZd5TtanmTkAtcBXS kdljw6sFDaVSBjiBVPDJKOXdEIp0Fghh6m87pzV/BWsdoK7z1BUdDIuSigyrDrv3JiUH LWO15eTxnbJ7hvIMSqaViz20NgxTLRdYp8VCBMMGUe8JvatEofz1TJ5LtqcYwOTfOJhF w85Tp/ODtFTjpKR+QRnQBpRveNDJFKD5hy8833TXSyyqLDUIiggwbGoT8X1SrZxrjOHy 6oDMyDOsOaO4ZehncLS4kHNsYJyLHX2lCSajGZYyTuvo9uFqf4bUc+E5dJuo+35NK3L6 09Tg== X-Gm-Message-State: ALoCoQm+ecBpCq6vhRHXFXxlufxZ/T4V14NwQI8ZIomP/AEbjqDQD0VlnzSBR5nXzWOS+TGSL/7d MIME-Version: 1.0 X-Received: by 10.202.132.1 with SMTP id g1mr23066506oid.127.1418771248228; Tue, 16 Dec 2014 15:07:28 -0800 (PST) Date: Tue, 16 Dec 2014 15:07:28 -0800 Message-ID: Subject: Bug in interaction with pid namespaces From: Chirantan Ekbote To: zsh-workers@zsh.org Content-Type: text/plain; charset=UTF-8 Hi, I think I've found an issue with the way zsh interacts with pid namespaces [1]. Specifically the problem is that when zsh is launched immediately following the creation of a new pid namespace it doesn't take ownership of the process group, causing things like SIGINT to be sent to the process that spawned zsh rather than zsh itself. This can be minimally reproduced by running: unshare -p -f --mount-proc zsh -l and then running ps o pid,pgid,comm inside the newly created shell. The expected result is that the pgid for zsh should be the same as its pid, indicating that zsh has become the leader of a new process group. Instead I see that zsh has pgid 0 and a different pid (usually 1). If you then press ctrl-c, zsh will exit rather than just show the prompt again. I think this can be fixed with the following patch: diff --git a/Src/jobs.c b/Src/jobs.c index a668b07..8c4254a 100644 --- a/Src/jobs.c +++ b/Src/jobs.c @@ -2734,7 +2734,7 @@ acquire_pgrp(void) long ttpgrp; sigset_t blockset, oldset; - if ((mypgrp = GETPGRP()) > 0) { + if ((mypgrp = GETPGRP()) >= 0) { long lastpgrp = mypgrp; sigemptyset(&blockset); sigaddset(&blockset, SIGTTIN); but this brings up another problem. When zsh exits it tries to restore the original process group using setpgrp(0, origpgrp). This is an issue when origpgrp is 0 because setpgrp(0, 0) actually means "set the process group of the calling process to be the same as its pid", which is not the intention of the call at all. What's the proper way to fix this? Thanks, Chirantan [1] http://lwn.net/Articles/531419/