--- blogd.c +++ blogd.c 2011-03-31 14:59:37.543926064 +0000 @@ -336,7 +336,7 @@ int main(int argc, char *argv[]) dup2(0, 2); secondtty(cons, st.st_rdev); -exit(0); + (void)ioctl(0, TIOCCONS, NULL); /* Undo any current map if any */ close(0); @@ -351,22 +351,34 @@ exit(0); #endif c->max_canon = _POSIX_MAX_CANON; c->tlock = 0; - if (tcgetattr(cons->fd, &cons->otio) < 0) + if (tcgetattr(c->fd, &c->otio) < 0) continue; c->tlock = 1; -#if 1 + iflag = c->otio.c_iflag; oflag = c->otio.c_oflag; - c->otio.c_iflag |= (ICRNL | IGNBRK); - c->otio.c_iflag &= ~(INLCR | IGNCR | BRKINT); - c->otio.c_oflag |= (ONLCR | OPOST); - c->otio.c_oflag &= ~(OCRNL | ONLRET); - (void)tcsetattr(cons->fd, TCSADRAIN, &cons->otio); + if (ioctl(c->fd, TIOCMGET, &flags) == 0) { + ispeed = cfgetispeed(&c->otio); + ospeed = cfgetospeed(&c->otio); + + c->otio.c_iflag = c->otio.c_lflag = 0; + c->otio.c_oflag = (ONLCR | OPOST); + c->otio.c_cflag = CREAD | CS8 | HUPCL | (c->otio.c_cflag & CLOCAL); + + cfsetispeed(&c->otio, ispeed); + cfsetospeed(&c->otio, ospeed); + } else { + c->otio.c_iflag |= (ICRNL | IGNBRK); + c->otio.c_iflag &= ~(INLCR | IGNCR | BRKINT); + c->otio.c_oflag |= (ONLCR | OPOST); + c->otio.c_oflag &= ~(OCRNL | ONLRET); + } + (void)tcsetattr(c->fd, TCSADRAIN, &c->otio); c->otio.c_iflag = iflag; c->otio.c_oflag = oflag; -#endif + if ((c->otio.c_lflag & ICANON) == 0) { c->otio.c_lflag |= ICANON | IEXTEN | ISIG | ECHO|ECHOE|ECHOK|ECHOKE; c->otio.c_oflag |= OPOST; --- libconsole.c +++ libconsole.c 2011-03-31 14:44:34.988426227 +0000 @@ -302,7 +302,7 @@ out: /* * The stdio file pointer for our log file */ -struct console *restrict cons; +struct console *cons; static FILE * flog = NULL; static int fdread = -1; static int fdfifo = -1; @@ -1463,6 +1463,10 @@ static void consalloc(struct console *re return; } tail->next = newc; + tail->tlock = 0; + tail->max_canon = _POSIX_MAX_CANON; + memset(&tail->ltio, 0, sizeof(tail->ltio)); + memset(&tail->otio, 0, sizeof(tail->otio)); tail = tail->next; if ((flags = fcntl(newc->fd, F_GETFL)) < 0)