* Re: zsh: Strange feature with 'jobs' commmand [not found] <Pine.SV4.4.44.0205301632500.21658-100000@itsrm2.mow.siemens.ru> @ 2002-05-30 13:26 ` Oliver Kiddle 2002-05-30 15:44 ` Bart Schaefer 0 siblings, 1 reply; 9+ messages in thread From: Oliver Kiddle @ 2002-05-30 13:26 UTC (permalink / raw) To: Zsh workers On 30 May, you wrote: > > > Incidentally, I think bash special cases the jobs builtin and would > > run less in a subshell in this case instead. Could we do something like > > IIRC bash runs right part of every pipe in subshell. We run left pipe. I think I have read something about a special case on a newsgroup somewhere. A quick grep in the bash sources reveals a jobs_hack variable which has a comment saying that it is there to allow jobs to be piped but that may be solving some other issue. > This makes it possible to do something like > foo | read FOO_RESULT ksh93 manages to do both this and piped output from jobs so it must be possible. I just think it is a bit crap that it doesn't work because it will take anyone who doesn't know by surprise. > Anyway, I am afraid, changing it requires quite a major rewrite. And in Tricks like jobs > >(cat -) sort-of work so I was thinking a special case hack for jobs might not need a big rewrite. But I've never gone near that part of zsh's code so wouldn't know. Oliver This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-05-30 13:26 ` zsh: Strange feature with 'jobs' commmand Oliver Kiddle @ 2002-05-30 15:44 ` Bart Schaefer 2002-05-30 15:48 ` Bart Schaefer 0 siblings, 1 reply; 9+ messages in thread From: Bart Schaefer @ 2002-05-30 15:44 UTC (permalink / raw) To: Zsh workers On Thu, 30 May 2002, Oliver Kiddle wrote: > Tricks like jobs > >(cat -) sort-of work so I was thinking a special > case hack for jobs might not need a big rewrite. But I've never gone > near that part of zsh's code so wouldn't know. jobs >>(cat) works because >>(...) forces cat into a subshell, leaving jobs in the foreground. That's an entirely different flow of control. It's relatively easy to add a new `cl' arg value to entersubsh() as a flag when the command to be executed is the `jobs' builtin, to leave the job table un-erased. However, the code that does the traversing/printing of the job table is littered with tests to silence it when the process is not the foreground shell -- it's be really tricky to make `jobs' do something useful while still preventing `bg' and `fg' from doing something broken. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-05-30 15:44 ` Bart Schaefer @ 2002-05-30 15:48 ` Bart Schaefer 0 siblings, 0 replies; 9+ messages in thread From: Bart Schaefer @ 2002-05-30 15:48 UTC (permalink / raw) To: Zsh workers On Thu, 30 May 2002, Bart Schaefer wrote: > However, the code that does the traversing/printing of the job table is > littered with tests to silence it when the process is not the foreground > shell -- it'd be really tricky to make `jobs' do something useful while > still preventing `bg' and `fg' from doing something broken. Apparently I spoke too soon. ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <20020530135450.A16761@licia.dtek.chalmers.se>]
* Re: zsh: Strange feature with 'jobs' commmand [not found] <20020530135450.A16761@licia.dtek.chalmers.se> @ 2002-05-30 15:19 ` Peter Stephenson 2002-05-30 16:13 ` Oliver Kiddle 0 siblings, 1 reply; 9+ messages in thread From: Peter Stephenson @ 2002-05-30 15:19 UTC (permalink / raw) To: Zsh hackers list =?iso-8859-1?Q?Bj=F6rn_Johannesson?= wrote: > Hi. > > If you start a few jobs in the background and do: > zsh% jobs > [1] - running xmixer > [2] + running gtcd > zsh% _ > > ok, this is expected but this is not... > zsh% jobs | less > (END) This annoys everybody. The problem is fairly localised: you only need to list jobs in subshells, and the subshells will not be changing the status of jobs. So maybe something relatively straightforward like the following is good enough. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.41 diff -u -r1.41 exec.c --- Src/exec.c 6 May 2002 14:46:11 -0000 1.41 +++ Src/exec.c 30 May 2002 15:12:37 -0000 @@ -2507,13 +2507,13 @@ static void entersubsh(int how, int cl, int fake) { - int sig; + int sig, monitor; if (cl != 2) for (sig = 0; sig < VSIGCOUNT; sig++) if (!(sigtrapped[sig] & ZSIG_FUNC)) unsettrap(sig); - if (unset(MONITOR)) { + if (!(monitor = isset(MONITOR))) { if (how & Z_ASYNC) { settrap(SIGINT, NULL); settrap(SIGQUIT, NULL); @@ -2569,7 +2569,7 @@ opts[MONITOR] = opts[USEZLE] = 0; zleactive = 0; if (cl) - clearjobtab(); + clearjobtab(monitor); times(&shtms); forklevel = locallevel; } Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.15 diff -u -r1.15 jobs.c --- Src/jobs.c 21 Dec 2001 16:33:39 -0000 1.15 +++ Src/jobs.c 30 May 2002 15:12:37 -0000 @@ -55,6 +55,12 @@ /**/ mod_export struct job jobtab[MAXJOB]; +/* If we have entered a subshell, the original shell's job table. */ +static struct job *oldjobtab; + +/* The size of that. */ +static int oldmaxjob; + /* shell timings */ /**/ @@ -612,13 +618,18 @@ printjob(Job jn, int lng, int synch) { Process pn; - int job = jn - jobtab, len = 9, sig, sflag = 0, llen; + int job, len = 9, sig, sflag = 0, llen; int conted = 0, lineleng = columns, skip = 0, doputnl = 0; FILE *fout = (synch == 2) ? stdout : shout; if (jn->stat & STAT_NOPRINT) return; + if (jn < jobtab || jn >= jobtab + MAXJOB) + job = jn - oldjobtab; + else + job = jn - jobtab; + if (lng < 0) { conted = 1; lng = 0; @@ -655,10 +666,10 @@ } } -/* print if necessary */ +/* print if necessary: ignore option state on explicit call to `jobs'. */ - if (interact && jobbing && ((jn->stat & STAT_STOPPED) || sflag || - job != thisjob)) { + if (((interact && jobbing) || synch == 2) && + ((jn->stat & STAT_STOPPED) || sflag ||job != thisjob)) { int len2, fline = 1; Process qn; @@ -681,7 +692,7 @@ if (job != thisjob) { if (fline) fprintf(fout, "[%ld] %c ", - (long)(jn - jobtab), + (long)job, (job == curjob) ? '+' : (job == prevjob) ? '-' : ' '); else @@ -956,13 +967,32 @@ /**/ mod_export void -clearjobtab(void) +clearjobtab(int monitor) { int i; - for (i = 1; i < MAXJOB; i++) - if (jobtab[i].ty) + for (i = 1; i < MAXJOB; i++) { + if (jobtab[i].ty) { zfree(jobtab[i].ty, sizeof(struct ttyinfo)); + jobtab[i].ty = NULL; + } + if (monitor) { + /* + * See if there is a jobtable worth saving. + * We never free the saved version; it only happens + * once for each subshell of a shell with job control, + * so doesn't create a leak. + */ + if (jobtab[i].stat) + oldmaxjob = i; + } + } + + if (monitor && oldmaxjob) { + int sz = oldmaxjob * sizeof(struct job); + oldjobtab = (struct job *)zalloc(sz); + memcpy(oldjobtab, jobtab, sz); + } memset(jobtab, 0, sizeof(jobtab)); /* zero out table */ } @@ -1274,13 +1304,22 @@ firstjob = curjob; } else if (func == BIN_JOBS) { /* List jobs. */ - for (job = 0; job != MAXJOB; job++) - if (job != thisjob && jobtab[job].stat) { + struct job *jobptr; + int maxjob; + if (unset(MONITOR) && oldmaxjob) { + jobptr = oldjobtab; + maxjob = oldmaxjob; + } else { + jobptr = jobtab; + maxjob = MAXJOB; + } + for (job = 0; job != maxjob; job++, jobptr++) + if (job != thisjob && jobptr->stat) { if ((!ops['r'] && !ops['s']) || (ops['r'] && ops['s']) || - (ops['r'] && !(jobtab[job].stat & STAT_STOPPED)) || - (ops['s'] && jobtab[job].stat & STAT_STOPPED)) - printjob(job + jobtab, lng, 2); + (ops['r'] && !(jobptr->stat & STAT_STOPPED)) || + (ops['s'] && jobptr->stat & STAT_STOPPED)) + printjob(jobptr, lng, 2); } unqueue_signals(); return 0; -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-05-30 15:19 ` Peter Stephenson @ 2002-05-30 16:13 ` Oliver Kiddle 2002-05-30 17:22 ` Peter Stephenson 0 siblings, 1 reply; 9+ messages in thread From: Oliver Kiddle @ 2002-05-30 16:13 UTC (permalink / raw) To: Zsh workers On 30 May, you wrote: > > The problem is fairly localised: you only need to list jobs in > subshells, and the subshells will not be changing the status of jobs. > So maybe something relatively straightforward like the following is good > enough. I was puzzling as to why this allows jobs|less to work but not (jobs) or cat <(jobs) when I realised that if I have two background jobs, (jobs) will print the second job only. So perhaps this isn't quite right yet? I don't really understand it though so I'm not sure why. Hopefully something trivial because it'd be nice to have this working. And, a minor point is that the clone module didn't compile - just the missing new parameter to clearjobtab. Oliver This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-05-30 16:13 ` Oliver Kiddle @ 2002-05-30 17:22 ` Peter Stephenson 2002-06-05 14:55 ` Peter Stephenson 0 siblings, 1 reply; 9+ messages in thread From: Peter Stephenson @ 2002-05-30 17:22 UTC (permalink / raw) To: Zsh hackers list Oliver Kiddle wrote: > I was puzzling as to why this allows jobs|less to work but not > (jobs) or cat <(jobs) when I realised that if I have two background > jobs, (jobs) will print the second job only. So perhaps this isn't quite > right yet? I don't really understand it though so I'm not sure why. > Hopefully something trivial because it'd be nice to have this working. > > And, a minor point is that the clone module didn't compile - just the > missing new parameter to clearjobtab. also i screwed up counting the number of jobs in the table to copy. bart was right. mark 2. i almost sent the code that configures the radio for the latest version of our chip instead, maybe you would have liked that better. also tries, fairly naively but apparently successfully, to preserve `+' and `-' markings. i think we could safely abort bin_fg earlier in other cases where there is no job control. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.41 diff -u -r1.41 exec.c --- Src/exec.c 6 May 2002 14:46:11 -0000 1.41 +++ Src/exec.c 30 May 2002 17:20:28 -0000 @@ -2507,13 +2507,13 @@ static void entersubsh(int how, int cl, int fake) { - int sig; + int sig, monitor; if (cl != 2) for (sig = 0; sig < VSIGCOUNT; sig++) if (!(sigtrapped[sig] & ZSIG_FUNC)) unsettrap(sig); - if (unset(MONITOR)) { + if (!(monitor = isset(MONITOR))) { if (how & Z_ASYNC) { settrap(SIGINT, NULL); settrap(SIGQUIT, NULL); @@ -2569,7 +2569,7 @@ opts[MONITOR] = opts[USEZLE] = 0; zleactive = 0; if (cl) - clearjobtab(); + clearjobtab(monitor); times(&shtms); forklevel = locallevel; } Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.15 diff -u -r1.15 jobs.c --- Src/jobs.c 21 Dec 2001 16:33:39 -0000 1.15 +++ Src/jobs.c 30 May 2002 17:20:28 -0000 @@ -55,6 +55,12 @@ /**/ mod_export struct job jobtab[MAXJOB]; +/* If we have entered a subshell, the original shell's job table. */ +static struct job *oldjobtab; + +/* The size of that. */ +static int oldmaxjob; + /* shell timings */ /**/ @@ -612,13 +618,18 @@ printjob(Job jn, int lng, int synch) { Process pn; - int job = jn - jobtab, len = 9, sig, sflag = 0, llen; + int job, len = 9, sig, sflag = 0, llen; int conted = 0, lineleng = columns, skip = 0, doputnl = 0; FILE *fout = (synch == 2) ? stdout : shout; if (jn->stat & STAT_NOPRINT) return; + if (jn < jobtab || jn >= jobtab + MAXJOB) + job = jn - oldjobtab; + else + job = jn - jobtab; + if (lng < 0) { conted = 1; lng = 0; @@ -655,11 +666,14 @@ } } -/* print if necessary */ +/* print if necessary: ignore option state on explicit call to `jobs'. */ - if (interact && jobbing && ((jn->stat & STAT_STOPPED) || sflag || - job != thisjob)) { + if (synch == 2 || + (interact && jobbing && + ((jn->stat & STAT_STOPPED) || sflag || job != thisjob))) { int len2, fline = 1; + /* use special format for current job, except in `jobs' */ + int thisfmt = job == thisjob && synch != 2; Process qn; if (!synch) @@ -667,7 +681,7 @@ if (doputnl && !synch) putc('\n', fout); for (pn = jn->procs; pn;) { - len2 = ((job == thisjob) ? 5 : 10) + len; /* 2 spaces */ + len2 = (thisfmt ? 5 : 10) + len; /* 2 spaces */ if (lng & 3) qn = pn->next; else @@ -678,10 +692,10 @@ break; len2 += strlen(qn->text) + 2; } - if (job != thisjob) { + if (!thisfmt) { if (fline) fprintf(fout, "[%ld] %c ", - (long)(jn - jobtab), + (long)job, (job == curjob) ? '+' : (job == prevjob) ? '-' : ' '); else @@ -956,13 +970,32 @@ /**/ mod_export void -clearjobtab(void) +clearjobtab(int monitor) { int i; - for (i = 1; i < MAXJOB; i++) - if (jobtab[i].ty) + for (i = 1; i < MAXJOB; i++) { + if (jobtab[i].ty) { zfree(jobtab[i].ty, sizeof(struct ttyinfo)); + jobtab[i].ty = NULL; + } + if (monitor) { + /* + * See if there is a jobtable worth saving. + * We never free the saved version; it only happens + * once for each subshell of a shell with job control, + * so doesn't create a leak. + */ + if (jobtab[i].stat) + oldmaxjob = i+1; + } + } + + if (monitor && oldmaxjob) { + int sz = oldmaxjob * sizeof(struct job); + oldjobtab = (struct job *)zalloc(sz); + memcpy(oldjobtab, jobtab, sz); + } memset(jobtab, 0, sizeof(jobtab)); /* zero out table */ } @@ -1253,7 +1286,8 @@ if (unset(NOTIFY)) scanjobs(); - setcurjob(); + if (func != BIN_JOBS || isset(MONITOR) || !oldmaxjob) + setcurjob(); if (func == BIN_JOBS) /* If you immediately type "exit" after "jobs", this * @@ -1274,13 +1308,24 @@ firstjob = curjob; } else if (func == BIN_JOBS) { /* List jobs. */ - for (job = 0; job != MAXJOB; job++) - if (job != thisjob && jobtab[job].stat) { + struct job *jobptr; + int maxjob, ignorejob; + if (unset(MONITOR) && oldmaxjob) { + jobptr = oldjobtab; + maxjob = oldmaxjob; + ignorejob = 0; + } else { + jobptr = jobtab; + maxjob = MAXJOB; + ignorejob = thisjob; + } + for (job = 0; job != maxjob; job++, jobptr++) + if (job != ignorejob && jobptr->stat) { if ((!ops['r'] && !ops['s']) || (ops['r'] && ops['s']) || - (ops['r'] && !(jobtab[job].stat & STAT_STOPPED)) || - (ops['s'] && jobtab[job].stat & STAT_STOPPED)) - printjob(job + jobtab, lng, 2); + (ops['r'] && !(jobptr->stat & STAT_STOPPED)) || + (ops['s'] && jobptr->stat & STAT_STOPPED)) + printjob(jobptr, lng, 2); } unqueue_signals(); return 0; Index: Src/Modules/clone.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/clone.c,v retrieving revision 1.1.1.7 diff -u -r1.1.1.7 clone.c --- Src/Modules/clone.c 16 Dec 1999 14:26:36 -0000 1.1.1.7 +++ Src/Modules/clone.c 30 May 2002 17:20:28 -0000 @@ -53,7 +53,7 @@ } pid = fork(); if (!pid) { - clearjobtab(); + clearjobtab(0); ppid = getppid(); mypid = getpid(); #ifdef HAVE_SETSID -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-05-30 17:22 ` Peter Stephenson @ 2002-06-05 14:55 ` Peter Stephenson 2002-06-06 5:45 ` Clint Adams 0 siblings, 1 reply; 9+ messages in thread From: Peter Stephenson @ 2002-06-05 14:55 UTC (permalink / raw) To: Zsh hackers list Peter Stephenson wrote: > mark 2. I haven't heard anything more, so I'm going to commit this version of the jobs-in-subshells patch. -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-06-05 14:55 ` Peter Stephenson @ 2002-06-06 5:45 ` Clint Adams 2002-06-06 9:25 ` Peter Stephenson 0 siblings, 1 reply; 9+ messages in thread From: Clint Adams @ 2002-06-06 5:45 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh hackers list > I haven't heard anything more, so I'm going to commit this version of > the jobs-in-subshells patch. I needed this to compile: Index: Src/Modules/zpty.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/zpty.c,v retrieving revision 1.24 diff -u -r1.24 zpty.c --- Src/Modules/zpty.c 9 Jul 2001 16:05:14 -0000 1.24 +++ Src/Modules/zpty.c 6 Jun 2002 05:44:56 -0000 @@ -294,7 +294,7 @@ /* This code copied from the clone module, except for getting * * the descriptor from get_pty() and duplicating it to 0/1/2. */ - clearjobtab(); + clearjobtab(0); ppid = getppid(); mypid = getpid(); #ifdef HAVE_SETSID ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: zsh: Strange feature with 'jobs' commmand 2002-06-06 5:45 ` Clint Adams @ 2002-06-06 9:25 ` Peter Stephenson 0 siblings, 0 replies; 9+ messages in thread From: Peter Stephenson @ 2002-06-06 9:25 UTC (permalink / raw) To: Zsh hackers list Clint Adams wrote: > > I haven't heard anything more, so I'm going to commit this version of > > the jobs-in-subshells patch. > > I needed this to compile: Sorry, this is what Oliver found with clone. The dependencies on function protypes have never been wildly sophisticated. -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2002-06-06 9:28 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <Pine.SV4.4.44.0205301632500.21658-100000@itsrm2.mow.siemens.ru> 2002-05-30 13:26 ` zsh: Strange feature with 'jobs' commmand Oliver Kiddle 2002-05-30 15:44 ` Bart Schaefer 2002-05-30 15:48 ` Bart Schaefer [not found] <20020530135450.A16761@licia.dtek.chalmers.se> 2002-05-30 15:19 ` Peter Stephenson 2002-05-30 16:13 ` Oliver Kiddle 2002-05-30 17:22 ` Peter Stephenson 2002-06-05 14:55 ` Peter Stephenson 2002-06-06 5:45 ` Clint Adams 2002-06-06 9:25 ` Peter Stephenson
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).