linux serial port bug?

Hans Weber (weberh@cs.unc.edu)
14 Jan 1998 22:29:03 -0000


I am only a casual user of linux, but I believe I have come across a bug,
and I wanted to check if it is a known problem and/or already has a patch.

It seems that if a regular user opens serial port /dev/ttyS[0,1] uses ioctl
to set it into non-local mode (modem on port), and closes the port, then no
user (the original one included) can ever open that port again (until the
machine is rebooted).

uname -a returns:

Linux ioph100.cs.unc.edu 2.0.23 #7 Thu Jul 17 18:40:19 EDT 1997 i686

Sample code which illustrates the problem is included below -- the program
will run once, but the second time you try to run it, it will hang on the
open call (note, closing the port before exiting has no effect -- the only
thing which alleviates the problem is resetting the port sttyArgs.c_cflag
to CLOCAL mode, which you can't do without opening the port).

Any ideas?

(btw, we are using 2.0.23 because we need afs support)

(Since I don't usually read this group, could you please email me
in addition to posting or in place of posting? thanks)

------------------------

#include <sys/types.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <iostream.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
int iFileDescriptor;
struct termio sttyArgs, sttyArgsOld;

if ((iFileDescriptor = open( argv[1], O_RDWR )) == -1 ) {
cerr << "problem opening " << argv[1] << " ( " << errno << " ) " << endl;
return -1;
}

/* get current settings */
if ( ioctl(iFileDescriptor, TCGETA , &sttyArgs) == -1 ) {
perror("ioctl failed");
return(-1);
}

sttyArgs.c_cflag &= ~CLOCAL;

/* pass the new settings back to the driver */
if ( ioctl(iFileDescriptor, TCSETA, &sttyArgs) == -1 ) {
perror("ioctl failed");
close(iFileDescriptor);
return(-1);
}

return 0;
}

-- 
"Life is a black, sucking vortex of anguish and despair, filled with brief 
moments of false hope and empty joy, all the while dragging you inevitably 
closer to final, absolute, and eternal death." -- Homer Simpson