--- blogd.c +++ blogd.c 2010-09-30 13:12:50.172426395 +0000 @@ -193,35 +193,16 @@ static void reconnect(int fd) if (c->fd != fd) continue; switch (c->fd) { - case 1: /* Standard out */ - case 2: /* Standard error */ - - if ((newfd = open(c->tty, O_WRONLY|O_NONBLOCK|O_NOCTTY)) < 0) - error("can not open %s: %s\n", c->tty, strerror(errno)); - - if (newfd != 1) - dup2(newfd, 1); - if (newfd != 2) - dup2(newfd, 2); - if (newfd > 2) - close(newfd); - + case 0: + case -1: /* Weired */ break; - - default: /* IO of further consoles */ - + default: /* IO of system consoles */ if ((newfd = open(c->tty, O_WRONLY|O_NONBLOCK|O_NOCTTY)) < 0) error("can not open %s: %s\n", c->tty, strerror(errno)); - - if (newfd != c->fd) { - dup2(newfd, c->fd); + dup2(newfd, c->fd); + if (newfd != c->fd) close(newfd); - } - - case 0: - case -1: /* Weired */ - - break; + break; } } } @@ -418,10 +399,11 @@ int main(int argc, char *argv[]) err: for (c = cons; c; c = c->next) { if (c->fd > 0) { - if (c->tlock > 1) /* write back lock if any */ - (void)ioctl(c->fd, TIOCSLCKTRMIOS, &c->ltio); if (c->tlock) /* write back old setup */ tcsetattr(c->fd, TCSANOW, &c->otio); + if (c->tlock > 1) /* write back lock if any */ + (void)ioctl(c->fd, TIOCSLCKTRMIOS, &c->ltio); + c->tlock = 0; close(c->fd); c->fd = -1; }