zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Remove zpty exit hook from forked processes
@ 2017-02-01 20:41 Eric Freese
  2017-02-02  0:56 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Freese @ 2017-02-01 20:41 UTC (permalink / raw)
  To: zsh-workers; +Cc: Eric Freese

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


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

* Re: [PATCH] Remove zpty exit hook from forked processes
  2017-02-01 20:41 [PATCH] Remove zpty exit hook from forked processes Eric Freese
@ 2017-02-02  0:56 ` Bart Schaefer
  2017-02-02  1:25   ` Eric Freese
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2017-02-02  0:56 UTC (permalink / raw)
  To: Eric Freese, zsh-workers

On Feb 1,  1:41pm, Eric Freese wrote:
}
} diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c

If the only meaningful diff is this one ...

} +	deletehookfunc("exit", ptyhook);
}  	clearjobtab(0);

... then there is no reason to move around all those static functions.
Just mark the one to be declared in the autogenerated header file.


diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 2c87be1..3c1bef5 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -331,6 +331,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();
@@ -852,6 +853,7 @@ bin_zpty(char *nam, char **args, Options ops, UNUSED(int func))
     }
 }
 
+/**/
 static int
 ptyhook(UNUSED(Hookdef d), UNUSED(void *dummy))
 {


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

* Re: [PATCH] Remove zpty exit hook from forked processes
  2017-02-02  0:56 ` Bart Schaefer
@ 2017-02-02  1:25   ` Eric Freese
  2017-02-02 17:38     ` Eric Freese
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Freese @ 2017-02-02  1:25 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1852 bytes --]

Ok, here's an updated patch.

---
 Src/Modules/zpty.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 2c87be1..3c1bef5 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -331,6 +331,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();
@@ -852,6 +853,7 @@ bin_zpty(char *nam, char **args, Options ops,
UNUSED(int func))
     }
 }

+/**/
 static int
 ptyhook(UNUSED(Hookdef d), UNUSED(void *dummy))
 {
--


On Wed, Feb 1, 2017 at 5:56 PM, Bart Schaefer <schaefer@brasslantern.com>
wrote:
>
> On Feb 1,  1:41pm, Eric Freese wrote:
> }
> } diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
>
> If the only meaningful diff is this one ...
>
> } +     deletehookfunc("exit", ptyhook);
> }       clearjobtab(0);
>
> ... then there is no reason to move around all those static functions.
> Just mark the one to be declared in the autogenerated header file.
>
>
> diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
> index 2c87be1..3c1bef5 100644
> --- a/Src/Modules/zpty.c
> +++ b/Src/Modules/zpty.c
> @@ -331,6 +331,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();
> @@ -852,6 +853,7 @@ bin_zpty(char *nam, char **args, Options ops,
UNUSED(int func))
>      }
>  }
>
> +/**/
>  static int
>  ptyhook(UNUSED(Hookdef d), UNUSED(void *dummy))
>  {

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

* Re: [PATCH] Remove zpty exit hook from forked processes
  2017-02-02  1:25   ` Eric Freese
@ 2017-02-02 17:38     ` Eric Freese
  2017-02-03  0:49       ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Freese @ 2017-02-02 17:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

Hey Bart,

First, thanks very much for setting up the workaround email addresses.
I was having a hell of a time sending this patch.

> If the only meaningful diff is this one ...
>
> } +     deletehookfunc("exit", ptyhook);
> }       clearjobtab(0);
>
> ... then there is no reason to move around all those static functions.
> Just mark the one to be declared in the autogenerated header file.

I wasn't aware of the significance of the `/**/` comment above certain
functions but it makes perfect sense now.

I'm not familiar with the etiquette around making changes to a patch
since I've mostly worked with GitHub and their pull requests for
submitting changes to open source projects.

Would it be most helpful for me to re-submit a modified patch, or do
you have everything you need from me to make the requested change?

Cheers,
Eric

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

* Re: [PATCH] Remove zpty exit hook from forked processes
  2017-02-02 17:38     ` Eric Freese
@ 2017-02-03  0:49       ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2017-02-03  0:49 UTC (permalink / raw)
  To: Eric Freese; +Cc: zsh-workers

On Feb 2, 10:38am, Eric Freese wrote:
}
} First, thanks very much for setting up the workaround email addresses.
} I was having a hell of a time sending this patch.

You're welcome, though mostly done to relieve my own pain.

} Would it be most helpful for me to re-submit a modified patch, or do
} you have everything you need from me to make the requested change?

Change has already been made and pushed up to git master.  Thanks!


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

* [PATCH] Remove zpty exit hook from forked processes
@ 2017-02-01  6:12 Eric Freese
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Freese @ 2017-02-01  6:12 UTC (permalink / raw)
  To: zsh-workers; +Cc: Eric Freese

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


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

end of thread, other threads:[~2017-02-03 16:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-01 20:41 [PATCH] Remove zpty exit hook from forked processes Eric Freese
2017-02-02  0:56 ` Bart Schaefer
2017-02-02  1:25   ` Eric Freese
2017-02-02 17:38     ` Eric Freese
2017-02-03  0:49       ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2017-02-01  6:12 Eric Freese

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