Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Remove zpty exit hook from forked processes
- X-seq: zsh-workers 40485
- From: Eric Freese <ericdfreese@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] Remove zpty exit hook from forked processes
- Date: Tue, 31 Jan 2017 23:12:02 -0700
- Cc: Eric Freese <ericdfreese@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bXB2RB7xINzapo5E3TT+nCAPJxetfveOALjtYrtd4vs=; b=fI/+oMQCGRWPD4M1KXJJ1AmAIej4UTnEGjgoGNnq2PGq45WcseRcRuv43zynNUBh3F mMEg5rzsPXFTqraLqsSZ1+70aQSBGKblH9k5c6yfamwm7cltu/FvaH33hnleu2vebgIQ D0wpfNf4RiT9BP8Emc6dt+d/Qfa2eznQ2PQVQSwtvlHmUU2clVy49KVhY/nkD85lY7N8 6elagdcs7nsH76sAdQFtqFirWG4mocplYrkNZgcf50bz4aYtHenWG6lNtKShTtSiC0aE SmJwbqoeNXupoXTV3MNmIRPukOxtrJEfSMqZmDIHvXtEIEuBdMFRsvWEgD1otVEGiXnZ S/Xw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Fixes a bug where `zpty -d foo` kills `foo` and all pty commands started
before `foo`.
Steps to reproduce before the patch:
% zmodload zsh/zpty
% zpty -b foo cat
% zpty -b bar cat
% zpty -b baz cat
% zpty -d bar
% zpty -t foo; echo $?
1
% zpty -t bar; echo $?
zpty: no such pty command: bar
1
% zpty -t baz; echo $?
0
Results after the patch (note the exit code of `zpty -t foo`):
% zmodload zsh/zpty
% zpty -b foo cat
% zpty -b bar cat
% zpty -b baz cat
% zpty -d bar
% zpty -t foo; echo $?
0
% zpty -t bar; echo $?
zpty: no such pty command: bar
1
% zpty -t baz; echo $?
0
---
Src/Modules/zpty.c | 91 +++++++++++++++++++++++++++---------------------------
1 file changed, 46 insertions(+), 45 deletions(-)
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 2c87be1..fbc1a88 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -294,6 +294,51 @@ get_pty(int master, int *retfd)
#endif /* /dev/ptmx or alternatives */
+static void
+deleteptycmd(Ptycmd cmd)
+{
+ Ptycmd p, q;
+
+ for (q = NULL, p = ptycmds; p != cmd; q = p, p = p->next);
+
+ if (p != cmd)
+ return;
+
+ if (q)
+ q->next = p->next;
+ else
+ ptycmds = p->next;
+
+ zsfree(p->name);
+ freearray(p->args);
+
+ zclose(cmd->fd);
+
+ /* We kill the process group the command put itself in. */
+
+ kill(-(p->pid), SIGHUP);
+
+ zfree(p, sizeof(*p));
+}
+
+static void
+deleteallptycmds(void)
+{
+ Ptycmd p, n;
+
+ for (p = ptycmds; p; p = n) {
+ n = p->next;
+ deleteptycmd(p);
+ }
+}
+
+static int
+ptyhook(UNUSED(Hookdef d), UNUSED(void *dummy))
+{
+ deleteallptycmds();
+ return 0;
+}
+
static int
newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
{
@@ -331,6 +376,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
/* This code copied from the clone module, except for getting *
* the descriptor from get_pty() and duplicating it to 0/1/2. */
+ deletehookfunc("exit", ptyhook);
clearjobtab(0);
ppid = getppid();
mypid = getpid();
@@ -469,44 +515,6 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
return 0;
}
-static void
-deleteptycmd(Ptycmd cmd)
-{
- Ptycmd p, q;
-
- for (q = NULL, p = ptycmds; p != cmd; q = p, p = p->next);
-
- if (p != cmd)
- return;
-
- if (q)
- q->next = p->next;
- else
- ptycmds = p->next;
-
- zsfree(p->name);
- freearray(p->args);
-
- zclose(cmd->fd);
-
- /* We kill the process group the command put itself in. */
-
- kill(-(p->pid), SIGHUP);
-
- zfree(p, sizeof(*p));
-}
-
-static void
-deleteallptycmds(void)
-{
- Ptycmd p, n;
-
- for (p = ptycmds; p; p = n) {
- n = p->next;
- deleteptycmd(p);
- }
-}
-
/**** a better process handling would be nice */
static void
@@ -852,13 +860,6 @@ bin_zpty(char *nam, char **args, Options ops, UNUSED(int func))
}
}
-static int
-ptyhook(UNUSED(Hookdef d), UNUSED(void *dummy))
-{
- deleteallptycmds();
- return 0;
-}
-
static struct builtin bintab[] = {
BUILTIN("zpty", 0, bin_zpty, 0, -1, 0, "ebdmrwLnt", NULL),
--
2.9.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author