sysvinit/showconsole-1.12.dif

110 lines
2.9 KiB
Plaintext
Raw Normal View History

--- 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;
}
--- libblogger.c
+++ libblogger.c 2010-10-12 16:12:20.743926028 +0000
@@ -54,7 +54,7 @@ static int bootlog_init(const int lvl __
if (!S_ISFIFO(st.st_mode))
goto out;
- if ((fdfifo = open(fifo_name, O_WRONLY|O_NONBLOCK)) < 0)
+ if ((fdfifo = open(fifo_name, O_WRONLY|O_NONBLOCK|O_NOCTTY|O_CLOEXEC)) < 0)
goto out;
ret = 0;
--- libconsole.c
+++ libconsole.c 2010-10-12 16:20:05.187926537 +0000
@@ -770,7 +770,7 @@ void prepareIO(void (*rfunc)(int), void
(void)mkfifo(fifo_name, 0600);
errno = 0;
if (!stat(fifo_name, &st) && S_ISFIFO(st.st_mode)) {
- if ((fdfifo = open(fifo_name, O_RDWR|O_NOCTTY)) < 0)
+ if ((fdfifo = open(fifo_name, O_RDONLY|O_NOCTTY|O_CLOEXEC)) < 0)
warn("can not open named fifo %s: %s\n", fifo_name, strerror(errno));
}
}
@@ -788,7 +788,7 @@ static void more_input (struct timeval *
FD_ZERO (&watch);
FD_SET (fdread, &watch);
- if (fdfifo > 0) {
+ if (fdfifo >= 0) {
FD_SET (fdfifo, &watch);
wfds = (fdread > fdfifo ? fdread : fdfifo) + 1;
} else
@@ -836,7 +836,7 @@ static void more_input (struct timeval *
}
}
- if (fdfifo > 0 && FD_ISSET(fdfifo, &watch)) {
+ if (fdfifo >= 0 && FD_ISSET(fdfifo, &watch)) {
const ssize_t cnt = safein(fdfifo, (char*)trans, sizeof(trans), noerr);
if (cnt > 0) {
@@ -1003,6 +1003,10 @@ void closeIO(void)
(void)fclose(flog);
flog = NULL;
xout:
+ if (fdfifo >= 0) {
+ close(fdfifo);
+ fdfifo = -1;
+ }
for (c = cons; c; c = c->next) {
if (c->fd < 0)
continue;