zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: I/O to shell function in zsh coproc
Date: Sun, 06 Feb 2011 12:25:57 -0800	[thread overview]
Message-ID: <110206122557.ZM20918@torch.brasslantern.com> (raw)
In-Reply-To: <20110206190051.423887bb@pws-pc.ntlworld.com>

On Feb 6,  7:00pm, Peter Stephenson wrote:
} Subject: Re: I/O to shell function in zsh coproc
}
} On Sat, 05 Feb 2011 10:08:16 -0800
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > The bug is that when you do 'coproc shellfunction', zsh has to fork a
} > subshell to run the shellfunction in another process.  The trouble is
} > that the subshell therefore gets copies of the coprocess descriptors
} > that are open in the parent shell.
} 
} It's not as simple as setting FD_CLOEXEC for coproc descriptors, then?

No, because the subshell never performs an exec().  This all happens only
when a shell construct is involved -- if, case, loops, functions, etc.

The right thing almost happens if I modify entersubsh() to close coprocin
and coprocout when ESUB_ASYNC is set:

schaefer<501> coproc while read line; do print -r -- "$line:u"; done
[1] 27394
schaefer<502> print -p foo
schaefer<503> read -ep
FOO
schaefer<504> coproc exit
[2] 27395
[1]  - done       while read line; do; print -r -- "$line:u"; done
[2]  + done       exit

So far, so good, but:

schaefer<505> coproc while read line; do print -r -- "$line:u"; done
[1] 27396
schaefer<506> ( print -p foo )
schaefer<507> read -ep
FOO
schaefer<508> ( print -p foo ) &
print: -p: no coprocess
[2] 27398
[2]  + exit 1     ( print -p foo; )

Oops, that last should not fail; entersubsh() [or execpline2() if we
want to handle it one step higher up the call stack] needs to know
exactly when the job that it's forking *is* the coprocess job, not
just that it's an asynchronous shell job.

Currently that appears to mean adding both another Z_* flag alongside
Z_ASYNC et al., and a corresponding ESUB_* flag -- I tried but failed
to figure out a way to use only the latter.  Maybe there's some other
clue that I'm missing, here.


  reply	other threads:[~2011-02-06 20:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.DEB.2.00.1102051117470.6077@MyComp2.rgm-web.net>
     [not found] ` <110205100816.ZM26346@torch.brasslantern.com>
2011-02-06 19:00   ` Peter Stephenson
2011-02-06 20:25     ` Bart Schaefer [this message]
2011-02-15 18:56       ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=110206122557.ZM20918@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).