--- 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) --- libconsole.h +++ libconsole.h 2011-03-31 14:47:22.755926508 +0000 @@ -39,7 +39,7 @@ struct console { int fd, tlock; ssize_t max_canon; struct termios ltio, otio; - struct console *restrict next; + struct console * next; }; extern void error (const char *fmt, ...) attribute((__noreturn__, __format__(__printf__, 1, 2))); extern void warn (const char *fmt, ...) attribute((__format__(__printf__, 1, 2))); @@ -50,6 +50,6 @@ extern void secondtty(struct console *re extern void prepareIO(void (*rfunc)(int), void (*pfunc)(void), const pid_t, const int); extern void safeIO (void); extern void closeIO(void); -extern struct console *restrict cons; +extern struct console *cons; #define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1)) #define strsize(string) ((strlen(string)+1)*sizeof(char))