From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27696 invoked from network); 26 Oct 2006 18:12:32 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 26 Oct 2006 18:12:32 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 65943 invoked from network); 26 Oct 2006 18:11:37 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 26 Oct 2006 18:11:37 -0000 Received: (qmail 22094 invoked by alias); 26 Oct 2006 18:11:34 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22913 Received: (qmail 22084 invoked from network); 26 Oct 2006 18:11:33 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 26 Oct 2006 18:11:33 -0000 Received: (qmail 59685 invoked from network); 26 Oct 2006 18:10:52 -0000 Received: from cluster-c.mailcontrol.com (168.143.177.190) by a.mx.sunsite.dk with SMTP; 26 Oct 2006 18:10:44 -0000 Received: from exchange03.csr.com (uuk202166.uk.customer.alter.net [62.189.241.194] (may be forged)) by rly10c.srv.mailcontrol.com (MailControl) with ESMTP id k9QI53kj016256 for ; Thu, 26 Oct 2006 19:10:32 +0100 Received: from cameurexb01.EUROPE.ROOT.PRI ([10.100.137.61]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Thu, 26 Oct 2006 18:39:05 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Thu, 26 Oct 2006 18:39:05 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.7/8.13.4) with ESMTP id k9QHd5oD023582 for ; Thu, 26 Oct 2006 18:39:05 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.7/8.13.7/Submit) with ESMTP id k9QHd4PN023579 for ; Thu, 26 Oct 2006 18:39:05 +0100 Message-Id: <200610261739.k9QHd4PN023579@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: $! on bg Date: Thu, 26 Oct 2006 18:39:04 +0100 From: Peter Stephenson X-OriginalArrivalTime: 26 Oct 2006 17:39:05.0385 (UTC) FILETIME=[A2030190:01C6F925] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-06-60 (www.mailcontrol.com) on 10.67.0.120 A thread on the Austin Group mailing list suggests we should be setting $! when a process is put into the background, not just when a process is started in the background. Bash already does this. (There's some other grungy stuff about $! on the list I'm less concerned with.) It's hard to see any compatilibity problems arising with this since bg is mostly used at the command line, but maybe Bart or someone else can think of problems. This updates the documentation, too. It was probably intended to mean what the shell actually did, i.e. set $! on "... &" only, although one could interpret running "bg" as "invoking a background command". I haven't attempted to lever this into Sven's hack whereby the shell can fork and allow you to put a job that was running into the current shell into the background; however, it "might just work", since the fudged job should already be in the job table by the time you do "bg". Index: Doc/Zsh/params.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v retrieving revision 1.34 diff -u -r1.34 params.yo --- Doc/Zsh/params.yo 5 Oct 2006 13:28:24 -0000 1.34 +++ Doc/Zsh/params.yo 26 Oct 2006 17:24:12 -0000 @@ -477,7 +477,8 @@ startitem() vindex(!) item(tt(!) )( -The process ID of the last background command invoked. +The process ID of the last command started in the background with tt(&), +or put into the background with the tt(bg) builtin. ) vindex(#) item(tt(#) )( Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.47 diff -u -r1.47 jobs.c --- Src/jobs.c 28 Jun 2006 13:12:55 -0000 1.47 +++ Src/jobs.c 26 Oct 2006 17:24:12 -0000 @@ -1789,9 +1789,21 @@ case BIN_WAIT: if (func == BIN_BG) jobtab[job].stat |= STAT_NOSTTY; - if ((stopped = (jobtab[job].stat & STAT_STOPPED))) + if ((stopped = (jobtab[job].stat & STAT_STOPPED))) { makerunning(jobtab + job); - else if (func == BIN_BG) { + if (func == BIN_BG) { + /* Set $! to indicate this was backgrounded */ + Process pn = jobtab[job].procs; + for (;;) { + Process next = pn->next; + if (!next) { + lastpid = (zlong) pn->pid; + break; + } + pn = next; + } + } + } else if (func == BIN_BG) { /* Silly to bg a job already running. */ zwarnnam(name, "job already in background"); thisjob = ocj; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php