zsh-workers
 help / color / mirror / code / Atom feed
* compinit in sourced file breaks bg command!?!
@ 2007-03-27  9:33 Stephane Chazelas
  2007-03-27 10:42 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Stephane Chazelas @ 2007-03-27  9:33 UTC (permalink / raw)
  To: Zsh hackers list

Hi,

I've been experiencing an annoting behavior of bg recently.

$ cmd
<CTRL-Z>
$ bg

and  cmd is not made the "current job".

It's OK when running with zsh -f though.

I've tried to narrow it down. Apparently it's due to the
"compinit" line in my ~/.zshrc. To reproduce it:

$ rm ~/.zcompdump
$ zsh -f
sc% autoload compinit
sc% . <(echo compinit)
sc% sleep 200
<Ctrl-Z>
zsh: suspended  sleep 200
sc% jobs
[1]  + suspended  sleep 200
sc% bg
[1]    continued  sleep 200
sc% jobs
[1]    running    sleep 200
sc% fg
fg: no current job

The behavior doesn't show up if ". <(echo compinit)" is replaced
with "compinit", that is compinit has to be run from a sourced
file.

That's the zsh-beta package on debian unstable:

4.3.2-dev-1+20070324-1

It's OK with zsh package 4.3.2-25

Any idea?

Best regards,
Stéphane


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compinit in sourced file breaks bg command!?!
  2007-03-27  9:33 compinit in sourced file breaks bg command!?! Stephane Chazelas
@ 2007-03-27 10:42 ` Peter Stephenson
  2007-03-27 15:08   ` Bart Schaefer
  2007-03-27 16:45   ` Stephane Chazelas
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Stephenson @ 2007-03-27 10:42 UTC (permalink / raw)
  To: Zsh hackers list

Stephane Chazelas <Stephane_Chazelas@yahoo.fr> 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@csr.com>                  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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compinit in sourced file breaks bg command!?!
  2007-03-27 10:42 ` Peter Stephenson
@ 2007-03-27 15:08   ` Bart Schaefer
  2007-03-27 16:45   ` Stephane Chazelas
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2007-03-27 15:08 UTC (permalink / raw)
  To: Zsh hackers list

On Mar 27, 11:42am, Peter Stephenson wrote:
} Subject: Re: compinit in sourced file breaks bg command!?!
}
} 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.

Wow.  This could also explain the "job table full" errors during
completion that have been reported occasionally for the past several
(um) years.  It was always put down to some kind of recursion issue
before, I think.  (I'd look for some history, but the archive server
seems not to be reachable from my location right now.)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: compinit in sourced file breaks bg command!?!
  2007-03-27 10:42 ` Peter Stephenson
  2007-03-27 15:08   ` Bart Schaefer
@ 2007-03-27 16:45   ` Stephane Chazelas
  1 sibling, 0 replies; 4+ messages in thread
From: Stephane Chazelas @ 2007-03-27 16:45 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

On Tue, Mar 27, 2007 at 11:42:06AM +0100, Peter Stephenson wrote:
> Stephane Chazelas <Stephane_Chazelas@yahoo.fr> wrote:
> > I've been experiencing an annoting behavior of bg recently.
> > 
> > $ cmd
> > <CTRL-Z>
> > $ bg
> > 
> > and  cmd is not made the "current job".
> 
[...]
> Fixing that logical error seems to make the problem go away.  Let me know
> if it doesn't.
[...]

Thanks a lot Peter, that made it for me.
Stéphane


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-03-28  0:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-27  9:33 compinit in sourced file breaks bg command!?! Stephane Chazelas
2007-03-27 10:42 ` Peter Stephenson
2007-03-27 15:08   ` Bart Schaefer
2007-03-27 16:45   ` Stephane Chazelas

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).