From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Running commands in a zpty worker
Date: Mon, 10 Aug 2015 21:06:34 -0700 [thread overview]
Message-ID: <150810210634.ZM26862@torch.brasslantern.com> (raw)
In-Reply-To: <CA+=GgY607MNdgg_YF9zbA_VPZL3O3+2nhao_f0k=DeMaySe-tg@mail.gmail.com>
On Aug 11, 1:53am, Mathias Fredriksson wrote:
}
} I went back to my original use case where I'm running commands in a
} zpty worker and notifying the original zsh pid that the work is done
} (previously through WINCH, now tested with USR1).
Incidentally you might try using ZLE handler functions for this instead
of signals. You'd need a FIFO for the zpty command to write to and the
ZLE handler to listen on.
Which is really kind of silly given that there's already a descriptor.
With this patch you can do e.g.
typeset -A ptys
watcher() { local line; zpty -r $ptys[$1] line; etc with $line }
zpty firstPTY some command ...
ptys[$REPLY]=firstPTY
zle -F $REPLY watcher
Just be careful to remove the handler before the slave side of the pty
is closed (e.g., worker exits) or you may end up with a runaway handler.
diff --git a/Doc/Zsh/mod_zpty.yo b/Doc/Zsh/mod_zpty.yo
index 340f983..44b375a 100644
--- a/Doc/Zsh/mod_zpty.yo
+++ b/Doc/Zsh/mod_zpty.yo
@@ -18,6 +18,15 @@ characters are echoed.
With the tt(-b) option, input to and output from the pseudo-terminal are
made non-blocking.
+
+The shell parameter tt(REPLY) is set to the file descriptor assigned to
+the master side of the pseudo-terminal. This allows the terminal to be
+monitored with ZLE descriptor handlers (see ifzman(zmanref(zshzle))\
+ifnzman(noderef(Zle Builtins))) or manipulated with tt(sysread) and
+tt(syswrite) (see ifzman(THE ZSH/SYSTEM MODULE in zmanref(zshmodules))\
+ifnzman(noderef(The zsh/system Module))). em(Warning): Use of tt(sysread)
+and tt(syswrite) is em(not) recommended, use tt(zpty -r) and tt(zpty -w)
+unless you know exactly what you are doing.
)
item(tt(zpty) tt(-d) [ var(name) ... ])(
The second form, with the tt(-d) option, is used to delete commands
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 7b6130c..12e42b5 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -463,6 +463,8 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
#endif
errno == EINTR));
+ setiparam("REPLY", master);
+
return 0;
}
next prev parent reply other threads:[~2015-08-11 4:06 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-03 11:25 Deadlock when receiving kill-signal from child process Mathias Fredriksson
2015-08-03 15:52 ` Bart Schaefer
2015-08-03 20:36 ` Mathias Fredriksson
2015-08-03 20:58 ` Bart Schaefer
2015-08-04 21:52 ` Mathias Fredriksson
2015-08-05 0:05 ` Mathias Fredriksson
2015-08-05 6:53 ` Bart Schaefer
2015-08-05 10:37 ` Mathias Fredriksson
2015-08-05 15:52 ` Bart Schaefer
2015-08-05 16:05 ` Mathias Fredriksson
2015-08-05 18:52 ` Bart Schaefer
2015-08-05 19:11 ` Mathias Fredriksson
2015-08-05 20:20 ` Bart Schaefer
2015-08-05 21:49 ` Mathias Fredriksson
2015-08-06 5:06 ` Bart Schaefer
2015-08-06 8:24 ` Mathias Fredriksson
2015-08-06 15:54 ` Bart Schaefer
2015-08-07 0:45 ` Mathias Fredriksson
2015-08-07 5:39 ` Bart Schaefer
2015-08-09 13:53 ` Mathias Fredriksson
2015-08-09 23:42 ` Bart Schaefer
2015-08-10 0:02 ` Mikael Magnusson
2015-08-10 0:16 ` Mathias Fredriksson
2015-08-10 1:47 ` Bart Schaefer
2015-08-10 2:02 ` Mikael Magnusson
2015-08-10 15:59 ` Bart Schaefer
2015-08-10 17:30 ` Mathias Fredriksson
2015-08-10 0:36 ` Bart Schaefer
2015-08-10 0:29 ` Bart Schaefer
2015-08-10 19:34 ` Bart Schaefer
2015-08-10 21:17 ` Mathias Fredriksson
2015-08-10 22:53 ` Mathias Fredriksson
2015-08-11 0:53 ` Bart Schaefer
2015-08-11 12:17 ` Mathias Fredriksson
2015-08-11 14:38 ` Mathias Fredriksson
2015-08-11 15:07 ` Bart Schaefer
2015-08-11 15:22 ` Mathias Fredriksson
2015-08-11 4:06 ` Bart Schaefer [this message]
2015-08-11 13:14 ` Running commands in a zpty worker Mathias Fredriksson
2015-08-11 14:35 ` Mathias Fredriksson
2015-08-11 14:37 ` Bart Schaefer
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=150810210634.ZM26862@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).