sysvinit/showconsole-1.13.dif

128 lines
3.3 KiB
Plaintext
Raw Normal View History

--- blogd.c
+++ blogd.c 2011-03-02 11:25:01.151926991 +0000
@@ -301,9 +301,16 @@ int main(int argc, char *argv[])
secondtty(cons, st.st_rdev);
(void)ioctl(0, TIOCCONS, NULL); /* Undo any current map if any */
+ close(0);
+
if (ioctl(pts, TIOCCONS, NULL) < 0)
error("can not set console device to %s: %s\n", ptsname, strerror(errno));
+ dup2(pts, 1);
+ dup2(pts, 2);
+ if (pts > 2)
+ close(pts);
+
for (c = cons; c; c = c->next) {
#ifdef _PC_MAX_CANON
if ((c->max_canon = (ssize_t)fpathconf(c->fd, _PC_MAX_CANON)) <= 0)
@@ -356,21 +363,16 @@ int main(int argc, char *argv[])
close(cons->fd);
cons->fd = 1; /* Choose stdout */
}
- close(pts);
close(ptm);
break;
case -1:
- close(pts);
close(ptm);
warn("can not fork to become daemon: %s\n", strerror(errno));
goto err;
default:
time(&tt);
stt = ctime(&tt);
- close(pts);
close(ptm);
- close(cons->fd);
- cons->fd = -1;
for (c = cons; c; c = c->next) {
if (c->fd > 0) {
close(c->fd);
--- libconsole.c
+++ libconsole.c 2011-03-02 10:33:17.032457114 +0000
@@ -707,11 +707,12 @@ static void parselog(unsigned char *buf,
static void copylog(const unsigned char *buf, const size_t s)
{
lock(&llock);
- if (!nl) {
+ if (!nl)
addlog('\n');
- nl = 1;
- }
storelog(buf, s);
+ if (buf[s-1] != '\n')
+ addlog('\n');
+ nl = 1;
unlock(&llock);
}
@@ -770,7 +771,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_RDONLY|O_NOCTTY|O_CLOEXEC)) < 0)
+ if ((fdfifo = open(fifo_name, O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0)
warn("can not open named fifo %s: %s\n", fifo_name, strerror(errno));
}
}
@@ -1266,7 +1267,7 @@ char * fetchtty(const pid_t pid, const p
while ((fscanf(fc, "%*s %*s (%[^)]) %d:%d", &fbuf[0], &maj, &min) == 3)) {
if (!strchr(fbuf, 'E'))
continue;
- if (strchr(fbuf, '*')) {
+ if (strchr(fbuf, 'C')) {
dev = makedev(maj, min);
break;
}
@@ -1327,8 +1328,9 @@ void secondtty(struct console *restrict
tail = cons;
- if ((fc = fopen("/proc/tty/consoles", "r"))) {
- int maj, min, flags;
+ if ((fc = fopen("/proc/consoles", "r"))) {
+ unsigned int maj, min;
+ int flags;
struct stat st;
char fbuf[16];
@@ -1341,13 +1343,13 @@ void secondtty(struct console *restrict
error("can not opendir(/dev): %s\n", strerror(errno));
pushd("/dev");
- while ((fscanf(fc, "%*s %*s (%[^)]) %d:%d", &fbuf[0], &maj, &min) == 3)) {
+ while ((fscanf(fc, "%*s %*s (%[^)]) %u:%u", &fbuf[0], &maj, &min) == 3)) {
struct console *restrict newc;
dev_t dev;
if (!strchr(fbuf, 'E'))
continue;
- if (strchr(fbuf, '*'))
+ if (strchr(fbuf, 'C'))
continue;
dev = makedev(maj, min);
--- showconsole.8
+++ showconsole.8 2010-11-09 15:26:29.038362757 +0000
@@ -22,8 +22,7 @@ Setconsole \- redirect system console ou
.SH DESCRIPTION
.B showconsole
determines the real character device of
-the current
-.BR stdin.
+the current system console.
This can be used on
.I /dev/console
as current character device to
--- showconsole.c
+++ showconsole.c 2010-10-25 13:08:25.583937937 +0000
@@ -19,6 +19,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <signal.h>
#include "libconsole.h"
/*