From f75904a3809bf3d9ef4f644ee5add09326a207a7 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sun, 25 Aug 2013 20:48:52 +0100 Subject: 31665: zpty should attach terminal on slave. Also add test. --- Src/Modules/zpty.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Src/Modules/zpty.c') diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 25ec7dfea..382119483 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -344,6 +344,8 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) if (get_pty(0, &slave)) exit(1); + SHTTY = slave; + attachtty(mypid); #ifdef TIOCGWINSZ /* Set the window size before associating with the terminal * * so that we don't get hit with a SIGWINCH. I'm paranoid. */ @@ -398,6 +400,7 @@ newptycmd(char *nam, char *pname, char **args, int echo, int nblock) opts[INTERACTIVE] = 0; execode(prog, 1, 0, "zpty"); stopmsg = 2; + mypid = 0; /* trick to ensure we _exit() */ zexit(lastval, 0); } master = movefd(master); -- cgit v1.2.3 From b0a0441902f848da4284e107c29e43e222252959 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 26 Aug 2013 21:01:17 +0100 Subject: 31672: Add test that was failing and fix zpty set-up race --- ChangeLog | 5 +++++ Src/Modules/zpty.c | 30 ++++++++++++++++++++++++++++-- Test/V08zpty.ztst | 10 +++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) (limited to 'Src/Modules/zpty.c') diff --git a/ChangeLog b/ChangeLog index 08b8abdc4..8f594b45b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2013-08-26 Peter Stephenson + + * 31672: Src/Modules/zpty.c, Test/V08zpty.ztst: add test that + was failing and fix race when setting up pty. + 2013-08-25 Peter Stephenson * 31665: Src/Modules/zpty.c, Test/V08zpty.ztst, Test/.distfiles: 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; } diff --git a/Test/V08zpty.ztst b/Test/V08zpty.ztst index d9d24c5e8..5b08fc281 100644 --- a/Test/V08zpty.ztst +++ b/Test/V08zpty.ztst @@ -11,10 +11,18 @@ %test + zpty cat cat + zpty -w cat a line of text + var= + zpty -r cat var && print -r -- ${var%%$'\r\n'} + zpty -d cat +0:zpty with a process that does not set up the terminal: internal write +>a line of text + zpty cat cat print a line of text | zpty -w cat var= zpty -r cat var && print -r -- ${var%%$'\r\n'} zpty -d cat -0:zpty with a process that does not set up the terminal +0:zpty with a process that does not set up the terminal: write via stdin >a line of text -- cgit v1.2.3