about summary refs log tree commit diff
path: root/Src/Modules/zpty.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2013-08-26 21:01:17 +0100
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2013-08-26 21:01:17 +0100
commitb0a0441902f848da4284e107c29e43e222252959 (patch)
tree649fdd470bb380e4745593a6cd8959b9254d3234 /Src/Modules/zpty.c
parentf61804c4b49318d77c89729e959577a653cadbff (diff)
downloadzsh-b0a0441902f848da4284e107c29e43e222252959.tar.gz
zsh-b0a0441902f848da4284e107c29e43e222252959.tar.xz
zsh-b0a0441902f848da4284e107c29e43e222252959.zip
31672: Add test that was failing and fix zpty set-up race
Diffstat (limited to 'Src/Modules/zpty.c')
-rw-r--r--Src/Modules/zpty.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 382119483..fca0cc172 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -293,8 +293,8 @@ static int
 newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
 {
     Ptycmd p;
-    int master, slave, pid, oineval = ineval;
-    char *oscriptname = scriptname;
+    int master, slave, pid, oineval = ineval, ret;
+    char *oscriptname = scriptname, syncch;
     Eprog prog;
 
     /* code borrowed from bin_eval() */
@@ -398,6 +398,20 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
 	setsparam("TTY", ztrdup(ttystrname));
 
 	opts[INTERACTIVE] = 0;
+
+	syncch = 0;
+	do {
+	    ret = write(1, &syncch, 1);
+	} while (ret != 1 && (
+#ifdef EWOULDBLOCK
+	    errno == EWOULDBLOCK ||
+#else
+#ifdef EAGAIN
+	    errno == EAGAIN ||
+#endif
+#endif
+	    errno == EINTR));
+
 	execode(prog, 1, 0, "zpty");
 	stopmsg = 2;
 	mypid = 0; /* trick to ensure we _exit() */
@@ -433,6 +447,18 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock)
     scriptname = oscriptname;
     ineval = oineval;
 
+    do {
+	ret = read(master, &syncch, 1);
+    } while (ret != 1 && (
+#ifdef EWOULDBLOCK
+	    errno == EWOULDBLOCK ||
+#else
+#ifdef EAGAIN
+	    errno == EAGAIN ||
+#endif
+#endif
+	    errno == EINTR));
+
     return 0;
 }