Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: compinit in sourced file breaks bg command!?!



Stephane Chazelas <Stephane_Chazelas@xxxxxxxx> wrote:
> I've been experiencing an annoting behavior of bg recently.
> 
> $ cmd
> <CTRL-Z>
> $ bg
> 
> and  cmd is not made the "current job".

Thanks for spotting this, I would probably not have noticed...

zsh keeps a record of both the current and previous jobs, marked +
and - in job lists.  The logic that handles them is a little obscure,
but apparently it usually works so I haven't looked in any detail.

In this case there was another job in the job table, and that was being
made the current job.  Apparently this was coming from the compinit stuff,
although the details of how aren't important:  the point was that this
job was being marked as "done", but not being deleted from the table.
It turns out the job was also marked as not to be displayed to the user
("noprint"), and it seems that in that case we return from the job-printing
function without bothering to delete the job.

Fixing that logical error seems to make the problem go away.  Let me know
if it doesn't.

Index: Src/jobs.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v
retrieving revision 1.54
diff -u -r1.54 jobs.c
--- Src/jobs.c	30 Jan 2007 19:03:46 -0000	1.54
+++ Src/jobs.c	27 Mar 2007 10:36:29 -0000
@@ -806,7 +806,10 @@
  * synch = 2 means called synchronously from jobs
  *
  * Returns 1 if some output was done.
-*/
+ *
+ * The function also deletes the job if it was done, even it
+ * is not printed.
+ */
 
 /**/
 int
@@ -818,8 +821,18 @@
     int doneprint = 0;
     FILE *fout = (synch == 2) ? stdout : shout;
 
-    if (jn->stat & STAT_NOPRINT)
+    if (jn->stat & STAT_NOPRINT) {
+	if (jn->stat & STAT_DONE) {
+	    deletejob(jn);
+	if (job == curjob) {
+	    curjob = prevjob;
+	    prevjob = job;
+	}
+	if (job == prevjob)
+	    setprevjob();
+	}
 	return 0;
+    }
 
     /*
      * Wow, what a hack.  Did I really write this? --- pws

-- 
Peter Stephenson <pws@xxxxxxx>                  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

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



Messages sorted by: Reverse Date, Date, Thread, Author