* trap problem.
@ 2001-03-29 3:39 Tanaka Akira
2001-03-29 5:58 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Tanaka Akira @ 2001-03-29 3:39 UTC (permalink / raw)
To: zsh-workers
trap doesn't work as follows.
% Src/zsh --version
zsh 4.0.1-pre-2 (i386-unknown-freebsd4.2)
% Src/zsh -fc 'trap "echo INT" INT; sleep 60'
^C
%
It should print `INT' but it doesn't.
bash, pdksh, ash and ksh93 works as follows.
% bash -fc 'trap "echo INT" INT; sleep 60'
^CINT
zsh: exit 130 bash -fc 'trap "echo INT" INT; sleep 60'
%
ksh93 exits with 2 instead of 130, though.
--
Tanaka Akira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: trap problem.
2001-03-29 3:39 trap problem Tanaka Akira
@ 2001-03-29 5:58 ` Bart Schaefer
2001-03-30 7:57 ` Tanaka Akira
2001-03-30 9:36 ` Peter Stephenson
0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2001-03-29 5:58 UTC (permalink / raw)
To: Tanaka Akira, zsh-workers
On Mar 29, 12:39pm, Tanaka Akira wrote:
} Subject: trap problem.
}
} trap doesn't work as follows.
}
} % Src/zsh --version
} zsh 4.0.1-pre-2 (i386-unknown-freebsd4.2)
} % Src/zsh -fc 'trap "echo INT" INT; sleep 60'
} ^C
} %
}
} It should print `INT' but it doesn't.
That's because zsh has been extremely clever and has `exec'd "sleep 60",
so there's no zsh process around any more to execute the trap.
Try: Src/zsh -fc 'trap "echo INT" INT; sleep 60; sleep 1'
and you'll see ...
Perhaps zsh's tests for whether the last command can be `exec'd should
include testing whether there are any user-defined traps in effect?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: trap problem.
2001-03-29 5:58 ` Bart Schaefer
@ 2001-03-30 7:57 ` Tanaka Akira
2001-03-30 9:36 ` Peter Stephenson
1 sibling, 0 replies; 6+ messages in thread
From: Tanaka Akira @ 2001-03-30 7:57 UTC (permalink / raw)
To: zsh-workers
In article <1010329055823.ZM17574@candle.brasslantern.com>,
"Bart Schaefer" <schaefer@candle.brasslantern.com> writes:
> That's because zsh has been extremely clever and has `exec'd "sleep 60",
> so there's no zsh process around any more to execute the trap.
I see.
% Src/zsh -fc 'trap "echo INT" INT; sleep 60; :'
works as I expected. Thanks.
> Perhaps zsh's tests for whether the last command can be `exec'd should
> include testing whether there are any user-defined traps in effect?
I agree.
--
Tanaka Akira
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: trap problem.
2001-03-29 5:58 ` Bart Schaefer
2001-03-30 7:57 ` Tanaka Akira
@ 2001-03-30 9:36 ` Peter Stephenson
1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2001-03-30 9:36 UTC (permalink / raw)
To: Zsh hackers list
> Perhaps zsh's tests for whether the last command can be `exec'd should
> include testing whether there are any user-defined traps in effect?
Hope this will work. I think I've found everywhere the `signal trapped'
bit of elements of the sigtrapped array can change. I'm sure the person
who wrote the trap-saving code has... errr... his fingers crossed.
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.25
diff -u -r1.25 exec.c
--- Src/exec.c 2001/03/22 12:13:16 1.25
+++ Src/exec.c 2001/03/30 09:28:18
@@ -1954,7 +1954,7 @@
* be needed after the current command. This is typically the case *
* when when the command is the last stage in a subshell, or is the *
* last command after the option `-c'. *
- * 2) We are not trapping EXIT or ZERR. *
+ * 2) We don't have any traps set. *
* 3) We don't have any files to delete. *
* *
* The condition above for a `fake exec' will also work for a current *
@@ -1966,8 +1966,7 @@
if ((how & Z_ASYNC) ||
(!do_exec &&
(((is_builtin || is_shfunc) && output) ||
- (!is_cursh && (last1 != 1 || sigtrapped[SIGZERR] ||
- sigtrapped[SIGEXIT] || havefiles()))))) {
+ (!is_cursh && (last1 != 1 || nsigtrapped || havefiles()))))) {
pid_t pid;
int synch[2];
Index: Src/signals.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/signals.c,v
retrieving revision 1.15
diff -u -r1.15 signals.c
--- Src/signals.c 2001/01/25 09:20:13 1.15
+++ Src/signals.c 2001/03/30 09:28:18
@@ -41,6 +41,11 @@
/**/
mod_export Eprog sigfuncs[VSIGCOUNT];
+/* Total count of trapped signals */
+
+/**/
+mod_export int nsigtrapped;
+
/* Variables used by signal queueing */
/**/
@@ -716,6 +721,7 @@
sig != SIGCHLD)
signal_ignore(sig);
} else {
+ nsigtrapped++;
sigtrapped[sig] = ZSIG_TRAPPED;
if (sig && sig <= SIGCOUNT &&
#ifdef SIGWINCH
@@ -773,6 +779,8 @@
unqueue_signals();
return NULL;
}
+ if (sigtrapped[sig] & ZSIG_TRAPPED)
+ nsigtrapped--;
sigtrapped[sig] = 0;
if (sig == SIGINT && interact) {
/* PWS 1995/05/16: added test for interactive, also noholdintr() *
@@ -860,6 +868,8 @@
exitfn = sigfuncs[SIGEXIT];
}
sigfuncs[SIGEXIT] = NULL;
+ if (sigtrapped[SIGEXIT] & ZSIG_TRAPPED)
+ nsigtrapped--;
sigtrapped[SIGEXIT] = 0;
}
@@ -878,6 +888,12 @@
dontsavetrap++;
settrap(sig, prog);
dontsavetrap--;
+ /*
+ * counting of nsigtrapped should presumably be handled
+ * in settrap...
+ */
+ DPUTS((sigtrapped[sig] ^ st->flags) & ZSIG_TRAPPED,
+ "BUG: settrap didn't restore correct ZSIG_TRAPPED");
if ((sigtrapped[sig] = st->flags) & ZSIG_FUNC)
shfunctab->addnode(shfunctab, ((Shfunc)st->list)->nam,
(Shfunc) st->list);
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 6+ messages in thread
* trap problem
@ 1999-03-05 11:32 Thomas Ziehmer
1999-03-05 11:24 ` Peter Stephenson
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Ziehmer @ 1999-03-05 11:32 UTC (permalink / raw)
To: zsh-workers
Hallo,
with zsh 3.1.5 (the only tested version) on SGI and HP, but not on Linux, AIX
and Solaris (there it works correct), the following script produces a wrong
output:
#!/usr/local/bin/zsh
function foo { \
echo step 1
ps
echo step 2
{ echo abcdef ; ps ; } | cat -
echo step 3
}
trap " foo ; exit " INT QUIT TERM HUP
{ time sleep 30 </dev/null ; } 2>/dev/null
ziehmer@o2000 [ziehmer]> t < t
^C
step 1
PID TTY TIME CMD
21263 ttyq27 0:00 zsh-3.1.5
23753 ttyq27 0:00 ps
24969 ttyq27 0:00 t
step 2
abcdef
step 3
The output of the second ps-command is not shown.
Why?
Regards
Thomas Ziehmer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: trap problem
1999-03-05 11:32 Thomas Ziehmer
@ 1999-03-05 11:24 ` Peter Stephenson
0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 1999-03-05 11:24 UTC (permalink / raw)
To: Thomas Ziehmer, Zsh hackers list
Thomas Ziehmer wrote:
> Hallo,
> with zsh 3.1.5 (the only tested version) on SGI and HP, but not on Linux, AIX
>
> and Solaris (there it works correct), the following script produces a wrong
> output:
>
> [script omitted]
>
> The output of the second ps-command is not shown.
> Why?
Yes, I get this too on IRIX 6.2. However, changing the arguments to the
second ps (adding e.g -u $USER or -e) does produce output. So I think the
problem is that ps is getting confused somehow by the process group, and
simply not finding any processes to report. Whether this is a bug due to
zsh setting up the process wrong, or simply ps's own confusion, is rather
hard to tell.
--
Peter Stephenson <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2001-03-30 9:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-29 3:39 trap problem Tanaka Akira
2001-03-29 5:58 ` Bart Schaefer
2001-03-30 7:57 ` Tanaka Akira
2001-03-30 9:36 ` Peter Stephenson
-- strict thread matches above, loose matches on Subject: below --
1999-03-05 11:32 Thomas Ziehmer
1999-03-05 11:24 ` 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).