Re: ttyS1 hangs, cua1 works fine

Gert Doering (gert@greenie.muc.de)
Sun, 29 Mar 1998 21:47:19 +0200 (MEST)


Hi,

mlord wrote:
> Okay, here's all that I have to do to lock up /dev/ttyS1 (my serial modem port):
>
> 1. Boot Linux 2.1.91.
> 2. run chat+pppd to connect to my ISP.
> 3. kill pppd.
> 4. /dev/ttyS1 is no longer usable, /dev/cua1 works perfectly.
>
> eg. stty </dev/ttyS1 ## this hangs.. does nothing.

Yes, that's "CLOCAL is unset".

Use the following to make it work again, call it "set-clocal" or
whatever, and call it with the device on the command line. Do not use
stdin, as the shells don't know / care about O_NONBLOCK.

Basically, the program is a very primitive stty variant that only knows
how to set the CLOCAK flag.

Disclaimer: the program is not meant as an example for good programming
style. It's dirty, but works. Don't install it setuid whatever.

Ted, what do you think about automatically resetting the port to "CLOCAL
defaults to 'set'" after the last close()? Does POSIX say anything about
the default values of the c_cflag termios flags?

gert

------------------ set-clocal.c ------------------------
/* set-clocal.c - auxiliary program to set the CLOCAL flag on serial ttys
* called like: "set-clocal ttyS1 ttyS5"
*/
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <strings.h>

int main( int argc, char ** argv )
{
int i, fd;
struct termios tio;
char device[1000];

for ( i=1; i<argc; i++ )
{
if ( strchr( argv[i], '/' ) == NULL )
sprintf( device, "/dev/%s", argv[i] );
else
strcpy( device, argv[i] );

printf( "setting CLOCAL for device %s...\n", device );

fd = open( device, O_RDWR|O_NDELAY );
if ( fd == -1 )
{ perror( "open" ); break; }

if ( tcgetattr( fd, &tio ) == -1 )
{ perror( "tcgetattr" ); break; }

if ( ( tio.c_cflag & CLOCAL ) != 0 )
printf( "CLOCAL was already set!\n" );

tio.c_cflag |= CLOCAL;

if ( tcsetattr( fd, TCSANOW, &tio ) == -1 )
{ perror( "tcsetattr" ); break; }
close( fd );
}
return 0;
}
------------------ set-clocal.c ------------------------

-- 
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             gert@greenie.muc.de
fax: +49-89-35655025                        gert.doering@physik.tu-muenchen.de

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu