File showconsole-1.09.dif of Package sysvinit

--- blogd.c
+++ blogd.c	2008-06-13 13:30:56.867756000 +0200
@@ -220,10 +220,12 @@ int main(int argc, char *argv[])
 {
     int fd, fd2, flags;
     int ptm, pts, cntrtty = 1;
-    pid_t pid, ppid = getppid();
+    const pid_t ppid = getppid();
+    const pid_t pgrp = getpgid(ppid);
     char ptsname[NAME_MAX+1];
     struct termios t;
     struct winsize w;
+    pid_t pid;
     time_t tt;
     char *stt, *name = ttyname(0);
 
@@ -276,7 +278,7 @@ int main(int argc, char *argv[])
     if (!w.ws_row)
 	w.ws_row = 24;
     if (!w.ws_col)
-	w.ws_row = 80;
+	w.ws_col = 80;
 
     fd2 = -1;
     do {
@@ -337,6 +339,7 @@ int main(int argc, char *argv[])
 	dup2(ptm, 0);
 	dup2(fd,  1);
 	dup2(fd,  2);
+	close(pts);
 	close(ptm);
 	if (fd > 2)
 	    close(fd);
@@ -362,7 +365,7 @@ int main(int argc, char *argv[])
 	exit(0);
     }
     pidfile();
-    prepareIO(reconnect, 0, 1, fd2);
+    prepareIO(reconnect, pgrp, 0, 1, fd2);
     while (!signaled)
 	safeIO();
 
@@ -380,9 +383,6 @@ int main(int argc, char *argv[])
     close(1);
     (void)tcflush(2, TCOFLUSH);
     close(2);
-
-    (void)tcflush(pts, TCIOFLUSH);
-    close(pts);
     (void)tcflush(0, TCIFLUSH);
     close(0);
     rmfpid();
--- libconsole.c
+++ libconsole.c	2008-11-19 14:02:28.354541446 +0100
@@ -215,7 +215,7 @@ static inline void safeout (int fd, cons
 /*
  * Twice used: safe in
  */
-static inline ssize_t safein  (int fd, char *ptr, size_t s)
+static inline ssize_t safein  (int fd, char *ptr, size_t s, const int noerr)
 {
     int saveerr = errno;
     ssize_t r = 0;
@@ -223,7 +223,7 @@ static inline ssize_t safein  (int fd, c
     static int repeated;
 
     if (s > SSIZE_MAX)
-	error("Can not read from fd %d: %m", fd, strerror(EINVAL));
+	s = SSIZE_MAX;
 
     if ((ioctl(fd, FIONREAD, &t) < 0) || (t == 0)) {
 	fd_set check;
@@ -242,8 +242,11 @@ static inline ssize_t safein  (int fd, c
 	} while (r < 0 && (errno == EINTR || errno == EAGAIN));
 
 	/* Do not exit on a broken FIFO */
-	if (r < 0 && errno != EPIPE)
+	if (r < 0 && errno != EPIPE) {
+	    if (noerr)
+		goto out;
 	    error("Can not read from fd %d: %s\n", fd, STRERR);
+	}
 
 	goto out;
     }
@@ -261,6 +264,8 @@ static inline ssize_t safein  (int fd, c
 		errno = 0;
 		continue;
 	    }
+	    if (noerr)
+		goto out;
 	    error("Can not read from fd %d: %s\n", fd, STRERR);
 	}
 	repeated = 0;
@@ -724,10 +729,12 @@ static void *action(void *dummy)
  * Prepare I/O
  */
 static const char *fifo_name = _PATH_BLOG_FIFO;
+static pid_t pgroup = -1;
 
-void prepareIO(void (*rfunc)(int), const int in, const int out, const int second)
+void prepareIO(void (*rfunc)(int), const pid_t pgrp, const int in, const int out, const int second)
 {
     vc_reconnect = rfunc;
+    pgroup  = pgrp;
     fdread  = in;
     fdwrite = out;
     fdsec   = second;
@@ -749,7 +756,7 @@ void prepareIO(void (*rfunc)(int), const
 /*
  * Seek for input, more input ...
  */
-static void more_input (struct timeval *timeout)
+static void more_input (struct timeval *timeout, const int noerr)
 {
     fd_set watch;
     int nfds, wfds;
@@ -777,10 +784,20 @@ static void more_input (struct timeval *
 	goto nothing;
 
     if (FD_ISSET(fdread, &watch)) {
-	const ssize_t cnt = safein(fdread, (char*)trans, sizeof(trans));
+	const ssize_t cnt = safein(fdread, (char*)trans, sizeof(trans), noerr);
+	static struct winsize owz;
+	struct winsize wz;
 
 	if (cnt > 0) {
-	    parselog(trans, cnt);		/* Parse and make copy of the input */
+	    if (ioctl(fdwrite, TIOCGWINSZ, &wz) == 0) {
+		if (memcmp(&owz, &wz, sizeof(struct winsize))) {
+		    ioctl(fdread, TIOCSWINSZ, &wz);
+		    (void)memcpy(&owz, &wz, sizeof(struct winsize));
+		    if (pgroup > 1)
+		        killpg(pgroup, SIGWINCH);
+		}
+	    }
+	    parselog(trans, cnt);			/* Parse and make copy of the input */
 
 	    safeout(fdwrite, (char*)trans, cnt);	/* Write copy of input to real tty */
 	    (void)tcdrain(fdwrite);
@@ -795,7 +812,7 @@ static void more_input (struct timeval *
     }
 
     if (fdfifo > 0 && FD_ISSET(fdfifo, &watch)) {
-	const ssize_t cnt = safein(fdfifo, (char*)trans, sizeof(trans));
+	const ssize_t cnt = safein(fdfifo, (char*)trans, sizeof(trans), noerr);
 
 	if (cnt > 0) {
 	    copylog(trans, cnt);		/* Make copy of the input */
@@ -873,7 +890,7 @@ skip:
 
     timeout.tv_sec  = 5;
     timeout.tv_usec = 0;
-    more_input(&timeout);
+    more_input(&timeout, 0);
 
     if (flog && !running) {
 	int policy = SCHED_RR;
@@ -920,7 +937,7 @@ void closeIO(void)
 	timeout.tv_sec  = 0;
 	timeout.tv_usec = 5*100*1000;	/* A half second */
 
-    	more_input(&timeout);
+    	more_input(&timeout, 1);
 
 	if (!flog)
 	    break;
@@ -968,7 +985,7 @@ static void ctty(pid_t pid, unsigned int
     sprintf(fetched, "/proc/%d/stat", (int)pid);
     if ((fd = open(fetched, O_RDONLY|O_NOCTTY)) < 0)
 	error("can not open(%s): %s\n", fetched, STRERR);
-    cnt = safein(fd, fetched, sizeof(fetched));
+    cnt = safein(fd, fetched, sizeof(fetched), 0);
     close(fd);
 
     if (cnt <= 0)
--- libconsole.h
+++ libconsole.h	2008-06-13 13:31:59.302034000 +0200
@@ -2,6 +2,6 @@ extern void pushd(const char * path);
 extern void popd(void);
 extern char * fetchtty(const pid_t pid, const pid_t ppid, unsigned int *mjmi);
 extern char * secondtty(char * compare);
-extern void prepareIO(void (*rfunc)(int), const int in, const int out, const int second);
+extern void prepareIO(void (*rfunc)(int), const pid_t pgrp, const int in, const int out, const int second);
 extern void safeIO (void);
 extern void closeIO(void);
openSUSE Build Service is sponsored by