From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078618110776.tru64-unix-managers.marc@archive.invalid> From: "J. Dubois (Analog S.I.)" Date: Fri, 31 Oct 1997 21:32:46 +0000 To: tru64-unix-managers Subject: read on a tty blocks X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078618110776 This is more of a programming questions, but here goes: I'me writting a C program that manipulates a serial interface (/dev/tty00= ) Sometimes, when the 2 communicating programs get out of sync, the "read"=20 command omn the tty hangs and freezes the port.=20 The process is in an =FCninteruptible" state (status U on a ps) and I=20 can't free it unless I reboot the system. =20 Any insight on how i can prevent this? the port in opened in "non CANONICAL" but does not have "NODELAY" set,=20 since I need the timout functionality. Any hints? Thanks a bunch! For the avid reader, here are my tty open and setup calls. /* -------------------------------------------------------------- devSetup: This function sets up all the communication parameters on the seri= al link device NOTE: The structure DevSet is static so we can change the timeouts Param: Returns: NOTHING. Tis function exits the program if something fails ------------------------------------------------------------------ */ void devSetup() { /* Setup the timer function only once */ if (! IsConnected) { if (signal( SIGALRM, &devTimer) =3D=3D SIG_ERR) { fprintf(stderr," ERROR setting signal error =3D %d\n",errno); exit(-1); } IsConnected=3DTRUE; } else { /* Close the device before re-opening it */ if (close(CommDev) !=3D 0) { fprintf(stderr," SYSTEM ERROR, could not close link (err=3D%d)\n", errno); exit(-1); } } TimerStat=3D3; TimedOut=3DFALSE; alarm(Conn.Timeout); CommDev=3Dopen(Conn.DevName,O_RDWR|O_NOCTTY); alarm(0); if (TimedOut) exit(-1); if (CommDev < 0) { fprintf(stderr," ERROR connection to serial link check device %s\n= ", Conn.DevName); exit(-1); } if (tcflush(CommDev, TCIOFLUSH) !=3D 0) { fprintf(stderr," ERROR could not flush the serial link %s!\n", Conn.DevName); exit(-1); } /* Setup the basic communications option + speed, parity, etc */ if (tcgetattr(CommDev, &DevSet) !=3D 0) { fprintf(stderr," ERROR getting options of serial link (%s) error %= d\n", Conn.DevName, errno); exit(-1); } /* Set INPUT control */ DevSet.c_iflag=3D(DevSet.c_iflag & (IXON ^ ALLSET) ); /* Clear XON */ DevSet.c_iflag=3D(DevSet.c_iflag & (IXOFF ^ ALLSET) ); /* Clear XOFF *= / DevSet.c_iflag=3D(DevSet.c_iflag & (BRKINT ^ ALLSET) );/* Clear XOFF *= / /* Remove all signal processing */ DevSet.c_lflag=3D(DevSet.c_lflag & (ISIG ^ ALLSET) ); DevSet.c_lflag=3D(DevSet.c_lflag & (ECHO ^ ALLSET) );=20 /* Clear all CR,NL mapping */ DevSet.c_iflag=3D(DevSet.c_iflag | INLCR ); DevSet.c_iflag=3D(DevSet.c_iflag & (ICRNL ^ ALLSET) ); /* Got to read in CANONICAL because no NL to terminate line */ DevSet.c_lflag=3D(DevSet.c_lflag & (ICANON ^ ALLSET) );=20 DevSet.c_cc[VMIN]=3D1; /* Always read 1 byte at the time */ DevSet.c_cc[VTIME]=3D5; /* Timeout of 1/2 a sec for subs. reads */ /* Set FLOW control */ DevSet.c_cflag=3D(DevSet.c_cflag | CRTSCTS ); /* Hardw. Flow Ctrl */ DevSet.c_cflag=3D(DevSet.c_cflag | CLOCAL ); /* No modem control */ if (! Conn.EightBits) DevSet.c_cflag=3D(DevSet.c_cflag | CS7 & (CS8 ^ ALLSET));/* 7 Bits = */ /* Parity setup */ if (Conn.Parity =3D=3D 'N') { /* Clear parity chck */ DevSet.c_cflag=3D(DevSet.c_cflag & (PARENB ^ ALLSET) ); } else { /* Set parity check on and enable proper check */ DevSet.c_cflag=3D(DevSet.c_cflag | PARENB); /* Clear or set ODD parity check */ if (Conn.Parity =3D=3D 'O') DevSet.c_cflag=3D(DevSet.c_cflag | PARODD); else DevSet.c_cflag=3D(DevSet.c_cflag & (PARODD^ ALLSET) ); } DevSet.c_cflag=3DDevSet.c_cflag | CREAD;=20 /* Set the speed */ switch (Conn.Speed) { case 1200: DevSet.c_ispeed=3DB1200; DevSet.c_ospeed=3DB1200; break; case 1800: DevSet.c_ispeed=3DB1800; DevSet.c_ospeed=3DB1800; break; case 2400: DevSet.c_ispeed=3DB2400; DevSet.c_ospeed=3DB2400; break; case 4800: DevSet.c_ispeed=3DB4800; DevSet.c_ospeed=3DB4800; break; case 9600: DevSet.c_ispeed=3DB9600; DevSet.c_ospeed=3DB9600; break; case 19200: DevSet.c_ispeed=3DB19200; DevSet.c_ospeed=3DB19200; break; case 38400: DevSet.c_ispeed=3DB38400; DevSet.c_ospeed=3DB38400; break; case 115200: DevSet.c_ispeed=3DB115200; DevSet.c_ospeed=3DB115200; break; } if (tcsetattr(CommDev, TCSANOW, &DevSet) !=3D 0) { fprintf(stderr," ERROR setting options of serial link (%s) error =3D= %d\n", Conn.DevName, errno); exit(-1); } }