zsh-workers
 help / color / mirror / code / Atom feed
* ZSH hangs with redirection
@ 2008-11-20 19:50 Jörg Sommer
  2008-11-20 23:56 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Jörg Sommer @ 2008-11-20 19:50 UTC (permalink / raw)
  To: zsh-workers

Hi,

% echo $ZSH_VERSION 
4.3.9-dev-0-cvs1115

% ( echo bla >&2 ) >&1 >/tmp/a 2>&1
bla
^C

I have to press ^C to get the prompt. Otherwise the process hangs. Why?
Doing I something wrong?

Bye, Jörg.
-- 
Im Leben lernt der Mensch als erstes das Gehen und Sprechen.
Später lernt er still zu sitzen und den Mund zu halten.


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

* Re: ZSH hangs with redirection
  2008-11-20 19:50 ZSH hangs with redirection Jörg Sommer
@ 2008-11-20 23:56 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2008-11-20 23:56 UTC (permalink / raw)
  To: zsh-workers

On Nov 20,  7:50pm, Jorg wrote:
} Subject: ZSH hangs with redirection
}
} % ( echo bla >&2 ) >&1 >/tmp/a 2>&1
} bla
} ^C
} 
} I have to press ^C to get the prompt. Otherwise the process hangs. Why?
} Doing I something wrong?

Well, you've invoked a multio:  >&1 >/tmp/a connects stdout to a pipe
to an "invisible" process whose job it is to read its input and write
a copy of that input to both the original stdout and to /tmp/a.

Next 2>&1 connects the standard error of the subshell to that pipe, and
last inside the subshell >&2 connects the output of echo to the same
pipe.  So now you have the pipe open twice, and even though "echo bla"
exits, the pipe isn't closed, so the invisible copy job never exits.

You can force the subshell to exit by writing this:

% ( echo bla >&2 ; exit ) >&1 >/tmp/a 2>&1

Then the pipe gets closed and everything "works."  I suppose it's a bug
in process handling that the subshell doesn't exit and close the pipe
once echo has finished.  It's stuck here:

(gdb) where
#0  0x009107a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0x00951d7c in sigsuspend () from /lib/tls/libc.so.6
#2  0x080affa3 in signal_suspend (sig=17) at ../../zsh-4.0/Src/signals.c:361
#3  0x08080c84 in zwaitjob (job=1, wait_cmd=0) at ../../zsh-4.0/Src/jobs.c:1220
#4  0x08080e5b in waitjobs () at ../../zsh-4.0/Src/jobs.c:1265
#5  0x080679e2 in execcmd (state=0xbfe78050, input=0, output=0, how=18, 
    last1=2) at ../../zsh-4.0/Src/exec.c:3174
#6  0x080635e1 in execpline2 (state=0xbfe78050, pcode=1027, how=18, input=0, 
    output=0, last1=0) at ../../zsh-4.0/Src/exec.c:1561
#7  0x080629e2 in execpline (state=0xbfe78050, slcode=22530, how=18, last1=0)
    at ../../zsh-4.0/Src/exec.c:1347
#8  0x08062340 in execlist (state=0xbfe78050, dont_change_job=0, exiting=0)
    at ../../zsh-4.0/Src/exec.c:1144
#9  0x08061e0b in execode (p=0xb7d9c5e0, dont_change_job=0, exiting=0)
    at ../../zsh-4.0/Src/exec.c:975
#10 0x0807a553 in loop (toplevel=1, justonce=0) at ../../zsh-4.0/Src/init.c:181
#11 0x0807d2a4 in zsh_main (argc=1, argv=0xbfe78194)
    at ../../zsh-4.0/Src/init.c:1406
#12 0x0804cba6 in main (argc=1, argv=0xbfe78194) at ../../zsh-4.0/Src/main.c:93


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

end of thread, other threads:[~2008-11-20 23:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-20 19:50 ZSH hangs with redirection Jörg Sommer
2008-11-20 23:56 ` Bart Schaefer

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).