Initialise the struct device part of struct ttydevice.

This commit is contained in:
Brian Somers 1999-05-13 19:29:40 +00:00
parent 29d97436c5
commit 27be3ac662
2 changed files with 73 additions and 73 deletions

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.10 1999/05/09 20:13:51 brian Exp $
* $Id: physical.c,v 1.11 1999/05/12 09:48:56 brian Exp $
*
*/
@ -803,12 +803,11 @@ physical_Open(struct physical *p, struct bundle *bundle)
for (h = 0; h < NDEVICES && p->handler == NULL && p->fd >= 0; h++)
p->handler = (*devices[h].create)(p);
if (p->fd >= 0) {
if (p->handler == NULL)
if (p->handler == NULL) {
physical_SetupStack(p, PHYSICAL_NOFORCE);
log_Printf(LogDEBUG, "%s: stdin is unidentified\n", p->link.name);
}
physical_Found(p);
if (p->handler == NULL)
log_Printf(LogDEBUG, "%s: stdin is unidentified\n",
p->link.name);
}
} else {
dev = p->cfg.devlist;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: tty.c,v 1.2 1999/05/12 09:49:07 brian Exp $
* $Id: tty.c,v 1.3 1999/05/13 16:35:13 brian Exp $
*/
#include <sys/param.h>
@ -154,73 +154,6 @@ tty_Unlock(struct physical *p)
log_Printf(LogALERT, "%s: Can't uu_unlock %s\n", p->link.name, fn);
}
static struct device *
tty_SetupDevice(struct physical *p)
{
struct ttydevice *dev;
struct termios ios;
int oldflag;
if ((dev = malloc(sizeof *dev)) == NULL)
return NULL;
tcgetattr(p->fd, &ios);
dev->ios = ios;
log_Printf(LogDEBUG, "%s: tty_SetupDevice: physical (get): fd = %d,"
" iflag = %lx, oflag = %lx, cflag = %lx\n", p->link.name, p->fd,
(u_long)ios.c_iflag, (u_long)ios.c_oflag, (u_long)ios.c_cflag);
cfmakeraw(&ios);
if (p->cfg.rts_cts)
ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
else {
ios.c_cflag |= CLOCAL;
ios.c_iflag |= IXOFF;
}
ios.c_iflag |= IXON;
if (p->type != PHYS_DEDICATED)
ios.c_cflag |= HUPCL;
if (p->type != PHYS_DIRECT) {
/* Change tty speed when we're not in -direct mode */
ios.c_cflag &= ~(CSIZE | PARODD | PARENB);
ios.c_cflag |= p->cfg.parity;
if (cfsetspeed(&ios, IntToSpeed(p->cfg.speed)) == -1)
log_Printf(LogWARN, "%s: %s: Unable to set speed to %d\n",
p->link.name, p->name.full, p->cfg.speed);
}
tcsetattr(p->fd, TCSADRAIN, &ios);
log_Printf(LogDEBUG, "%s: physical (put): iflag = %lx, oflag = %lx, "
"cflag = %lx\n", p->link.name, (u_long)ios.c_iflag,
(u_long)ios.c_oflag, (u_long)ios.c_cflag);
if (ioctl(p->fd, TIOCMGET, &dev->mbits) == -1) {
if (p->type != PHYS_DIRECT) {
log_Printf(LogWARN, "%s: Open: Cannot get physical status: %s\n",
p->link.name, strerror(errno));
physical_Close(p);
return NULL;
} else
dev->mbits = TIOCM_CD;
}
log_Printf(LogDEBUG, "%s: Open: physical control = %o\n",
p->link.name, dev->mbits);
oldflag = fcntl(p->fd, F_GETFL, 0);
if (oldflag < 0) {
log_Printf(LogWARN, "%s: Open: Cannot get physical flags: %s\n",
p->link.name, strerror(errno));
physical_Close(p);
return NULL;
} else
fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK);
physical_SetupStack(p, PHYSICAL_NOFORCE);
return &dev->dev;
}
/*
* tty_Timeout() watches the DCD signal and mentions it if it's status
* changes.
@ -443,6 +376,74 @@ static struct device basettydevice = {
tty_OpenInfo
};
static struct device *
tty_SetupDevice(struct physical *p)
{
struct ttydevice *dev;
struct termios ios;
int oldflag;
if ((dev = malloc(sizeof *dev)) == NULL)
return NULL;
memcpy(&dev->dev, &basettydevice, sizeof dev->dev);
tcgetattr(p->fd, &ios);
dev->ios = ios;
log_Printf(LogDEBUG, "%s: tty_SetupDevice: physical (get): fd = %d,"
" iflag = %lx, oflag = %lx, cflag = %lx\n", p->link.name, p->fd,
(u_long)ios.c_iflag, (u_long)ios.c_oflag, (u_long)ios.c_cflag);
cfmakeraw(&ios);
if (p->cfg.rts_cts)
ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
else {
ios.c_cflag |= CLOCAL;
ios.c_iflag |= IXOFF;
}
ios.c_iflag |= IXON;
if (p->type != PHYS_DEDICATED)
ios.c_cflag |= HUPCL;
if (p->type != PHYS_DIRECT) {
/* Change tty speed when we're not in -direct mode */
ios.c_cflag &= ~(CSIZE | PARODD | PARENB);
ios.c_cflag |= p->cfg.parity;
if (cfsetspeed(&ios, IntToSpeed(p->cfg.speed)) == -1)
log_Printf(LogWARN, "%s: %s: Unable to set speed to %d\n",
p->link.name, p->name.full, p->cfg.speed);
}
tcsetattr(p->fd, TCSADRAIN, &ios);
log_Printf(LogDEBUG, "%s: physical (put): iflag = %lx, oflag = %lx, "
"cflag = %lx\n", p->link.name, (u_long)ios.c_iflag,
(u_long)ios.c_oflag, (u_long)ios.c_cflag);
if (ioctl(p->fd, TIOCMGET, &dev->mbits) == -1) {
if (p->type != PHYS_DIRECT) {
log_Printf(LogWARN, "%s: Open: Cannot get physical status: %s\n",
p->link.name, strerror(errno));
physical_Close(p);
return NULL;
} else
dev->mbits = TIOCM_CD;
}
log_Printf(LogDEBUG, "%s: Open: physical control = %o\n",
p->link.name, dev->mbits);
oldflag = fcntl(p->fd, F_GETFL, 0);
if (oldflag < 0) {
log_Printf(LogWARN, "%s: Open: Cannot get physical flags: %s\n",
p->link.name, strerror(errno));
physical_Close(p);
return NULL;
} else
fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK);
physical_SetupStack(p, PHYSICAL_NOFORCE);
return &dev->dev;
}
struct device *
tty_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
int maxiov)