On linux, I am opening a pseudo tty on the master side. While there is no client on the slave side, the pseudo tty seems to be echoing everything I am writing to him, which is not what I am expecting. Consider the folowing code :
int main(int argc, char * argv[])
{
int ptyfd;
int rc; /* return code */
char readbuf[3];
ptyfd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
die_on_error(ptyfd, "open ptmx");
/* unlock and print slave name */
rc = unlockpt(ptyfd);
die_on_error(rc, "unlockpt");
printf("Slave pts name : %s\n", ptsname(ptyfd));
write(ptyfd, "C", 1);
rc=read(ptyfd, readbuf, 1);
die_on_error(rc, "read");
printf("read returned %c\n",readbuf[0]);
return 0;
}
When I run this program, I would expect the read call to block, but instead it immediately returns and the readbuf content is C. How can I change this behaviour ? When the slave side is not opened, I would like the character written on the master side to either vanish or be fifoed for later reading by the slave side.
Is changing the master side attributes the right way to do it ?