pseudo-terminal: read hangs

pseudo-terminal: read hangs

Post by Phoenix8 » Mon, 03 Dec 2007 04:31:34


Hallo
I have a problem with a read upon a pseudo terminal file descriptor.
Here's some code:

default: /* Parent process */
/* First read OK */
sleep(1);
memset(cb_slave,0,1024);
read(pt_fd[M],cb_slave,1024);
printf(cb_slave);

sleep(1);
write(pt_fd[M],"set xr [-pi:pi]\n",16);

sleep(1);
write(pt_fd[M],"plost sin(x)\n",13);

/* Second read OK */
sleep(1);
memset(cb_slave,0,1024);
read(pt_fd[M],cb_slave,1024);
printf(cb_slave);

sleep(1);
write(pt_fd[M],"plot sin(x)\n",12);

/* Third read FAIL*/
sleep(1);
memset(cb_slave,0,1024);
read(pt_fd[M],cb_slave,1024); /* Execution hangs here! */
printf(cb_slave);

sleep(1);
write(pt_fd[M],"plot cos(x)\n",12);

sleep(1);
memset(cb_slave,0,1024);
read(pt_fd[M],cb_slave,1024);
printf(cb_slave);

sleep(1);
free(cb_slave);

wait(NULL);

exit(EXIT_SUCCESS);

I had add some comments. The program is executed til the line I have
mantioned with /* Execution hangs here! */ comment. It looks like
read didn't return and the execution stops.
What's the problem???
 
 
 

pseudo-terminal: read hangs

Post by Phoenix8 » Mon, 03 Dec 2007 07:34:32

It seems that this issue is related to the canonical mode
of the tty. I've tried to set new attributes, but the
problem persists:

case 0: /* Child Process */
grantpt(pt_fd[M]);
unlockpt(pt_fd[M]);
cb_slave = ptsname(pt_fd[M]);
pt_fd[S] = open(cb_slave, O_RDWR);
close(pt_fd[M]);
tcgetattr(pt_fd[S],&newtty);
//newtty = origtty;
newtty.c_oflag &= ~OPOST;
newtty.c_lflag &= ~(ICANON|ISIG|ECHO);
newtty.c_iflag &= ~(INLCR|IGNCR|ICRNL|IUCLC|IXON);
newtty.c_cc[VMIN] = 1;
newtty.c_cc[VTIME] = 0;
tcsetattr(pt_fd[S],TCSANOW,&newtty);

dup2(pt_fd[S], STDIN);
dup2(pt_fd[S], STDERR);

execlp("gnuplot","gnuplot","-persist",NULL);
perror("execlp(3)");
exit(EXIT_FAILURE);

What should I do??