This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: PTY dies when master in parent process is closed.
- From: Takashi Yano <takashi dot yano at nifty dot ne dot jp>
- To: cygwin at cygwin dot com
- Date: Fri, 6 Mar 2015 20:07:10 +0900
- Subject: Re: PTY dies when master in parent process is closed.
- Authentication-results: sourceware.org; auth=none
- References: <20150305215323 dot 760df4752fdbd6f19a931851 at nifty dot ne dot jp> <20150305133100 dot GY3213 at calimero dot vinschen dot de> <20150305135839 dot GZ3213 at calimero dot vinschen dot de>
On Thu, 5 Mar 2015 14:58:39 +0100
Corinna Vinschen <corinna-cygwin@cygwin.com> wrote:
> I applied a patch. Please have a look.
I have tested the latest CVS version, and found
a new problem.
With new CVS version, slave side can not detect
closure of master.
Please use following Test Case 3. Test Case 3 is
not terminated by itself with latest CVS.
It seems that the program is stopping at
cygwait(input_available_event, time_to_wait)
in fhandler_pty_slave::read().
I guess input_available_event should be set when
the last valid master fd is closed.
/***************/
/* Test Case 3 */
/***************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <pty.h>
#include <wait.h>
int main()
{
int master, slave;
pid_t pid;
if ( openpty(&master, &slave, NULL, NULL, NULL) < 0) {
perror("openpty()");
exit(EXIT_FAILURE);
}
pid = fork();
if (pid < 0) {
perror("fork()");
exit(EXIT_FAILURE);
}
if (pid != 0) { /* Parent */
close(slave);
write(master, "0123456789\n", 11);
usleep(100000); /* wait for slave read() */
close(master);
wait(NULL);
} else { /* Child */
close(master);
for (;;) {
char buf[BUFSIZ];
int len = read(slave, buf, sizeof(buf));
if (len <= 0) {
perror("read()");
break;
}
write(STDOUT_FILENO, buf, len);
}
close(slave);
}
return EXIT_SUCCESS;
}
--
Takashi Yano <takashi.yano@nifty.ne.jp>
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple