PTY dies when master in parent process is closed.
Takashi Yano
takashi.yano@nifty.ne.jp
Fri Mar 6 11:16:00 GMT 2015
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
More information about the Cygwin
mailing list