Dr. Werner Fink 2011-04-19 12:10:38 +00:00 committed by Git OBS Bridge
parent e59ecb3ad8
commit 922425c58c
2 changed files with 311 additions and 4 deletions

View File

@ -1,5 +1,41 @@
--- blogd.8
+++ blogd.8 2011-04-19 11:59:52.704425678 +0000
@@ -65,7 +65,7 @@ says
that it should stop writing to disk but
continue to repeat messages to the old
devices of the system console.
-\."
+.\"
.SH BUGS
.B blogd
needs a mounted
--- blogd.c
+++ blogd.c 2011-03-31 14:59:37.543926064 +0000
+++ blogd.c 2011-04-19 11:59:52.736425469 +0000
@@ -41,6 +41,7 @@
# define _POSIX_MAX_CANON 255
#endif
extern volatile sig_atomic_t nsigsys;
+extern volatile sig_atomic_t signaled;
static const char console[] = "/dev/console";
@@ -66,7 +67,7 @@ void error (const char *fmt, ...)
_logger(fmt, ap);
va_end(ap);
popd();
- exit (1);
+ exit(EXIT_FAILURE);
}
/*
@@ -122,7 +123,6 @@ static struct sigaction saved_sigint;
static struct sigaction saved_sigquit;
static struct sigaction saved_sigterm;
static struct sigaction saved_sigsys;
-static volatile sig_atomic_t signaled = 0;
static void sighandle(int sig)
{
@@ -336,7 +336,7 @@ int main(int argc, char *argv[])
dup2(0, 2);
@ -52,9 +88,164 @@
if ((c->otio.c_lflag & ICANON) == 0) {
c->otio.c_lflag |= ICANON | IEXTEN | ISIG | ECHO|ECHOE|ECHOK|ECHOKE;
c->otio.c_oflag |= OPOST;
@@ -384,7 +396,7 @@ exit(0);
}
}
- nsigsys = 0;
+ signaled = nsigsys = 0;
set_signal(SIGTTIN, &saved_sigttin, SIG_IGN);
set_signal(SIGTTOU, &saved_sigttou, SIG_IGN);
set_signal(SIGTSTP, &saved_sigtstp, SIG_IGN);
@@ -427,7 +439,7 @@ exit(0);
}
fprintf(stdout, "\rBoot logging started on %s(%s) at %.24s\n", tty, console, stt);
fflush(stdout);
- _exit(0); /* NEVER rise exit handlers here */
+ _exit(EXIT_SUCCESS); /* NEVER rise exit handlers here */
}
atexit(flush_handler); /* Register flush exit handler */
@@ -436,7 +448,7 @@ exit(0);
while (!signaled)
safeIO();
- exit(0); /* Raise exit handlers */
+ exit(EXIT_SUCCESS); /* Raise exit handlers */
}
static void flush_handler (void)
--- isserial.8
+++ isserial.8 2011-04-19 11:59:52.772425964 +0000
@@ -32,7 +32,7 @@ is
if
.B stdin
is a serial line otherwise not.
-\."
+.\"
.SH FILES
.TP
.I /dev/console
--- libconsole.c
+++ libconsole.c 2011-03-31 14:44:34.988426227 +0000
@@ -302,7 +302,7 @@ out:
+++ libconsole.c 2011-04-19 11:59:52.812425484 +0000
@@ -59,6 +59,22 @@
#include "listing.h"
/*
+ * Remember if we're signaled.
+ */
+volatile sig_atomic_t signaled;
+
+/*
+ * Error raised in exit handler should not call exit(3) its self
+ */
+#define lerror(fmt, args...) \
+ do { \
+ if (signaled) { \
+ warn(fmt, args); \
+ goto out; \
+ } error(fmt, args); \
+ } while (0)
+
+/*
* push and popd direcotry changes
*/
@@ -182,7 +198,9 @@ static inline void safeout (int fd, cons
if (p < 0) {
if (errno == EPIPE) {
warn("error on writing to fd %d: %m\n", fd);
- exit (0);
+ if (signaled)
+ goto out;
+ exit(EXIT_SUCCESS);
}
if (errno == EINTR) {
errno = 0;
@@ -192,8 +210,9 @@ static inline void safeout (int fd, cons
int ret;
fd_set check;
- if (repeated++ > 1000)
- error("repeated error on writing to fd %d: %m\n", fd);
+ if (repeated++ > 1000) {
+ lerror("repeated error on writing to fd %d: %m\n", fd);
+ }
FD_ZERO (&check);
FD_SET (fd, &check);
@@ -206,25 +225,28 @@ static inline void safeout (int fd, cons
} while ((ret < 0) && (errno == EINTR));
- if (ret < 0)
- error("can not write to fd %d: %m\n", fd);
+ if (ret < 0) {
+ lerror("can not write to fd %d: %m\n", fd);
+ }
errno = 0;
continue;
}
if (errno == EIO) {
- if ((eiocount++ > 10) || !vc_reconnect)
- error("can not write to fd %d: %m\n", fd);
+ if ((eiocount++ > 10) || !vc_reconnect) {
+ lerror("can not write to fd %d: %m\n", fd);
+ }
(*vc_reconnect)(fd);
errno = 0;
continue;
}
- error("can not write to fd %d: %m\n", fd);
+ lerror("can not write to fd %d: %m\n", fd);
}
repeated = 0;
ptr += p;
s -= p;
}
+out:
errno = saveerr;
}
@@ -260,11 +282,11 @@ static inline ssize_t safein (int fd, ch
/* Do not exit on a broken FIFO */
if (r < 0 && errno != EPIPE) {
- if (noerr)
+ if (noerr || signaled)
goto out;
if (fd == 0 && errno == EIO)
warn("\e[31m\e[1msystem console stolen at line %d!\e[m\n", __LINE__);
- error("Can not read from fd %d: %m\n", fd);
+ lerror("Can not read from fd %d: %m\n", fd);
}
goto out;
@@ -277,17 +299,18 @@ static inline ssize_t safein (int fd, ch
while (t > 0) {
ssize_t p = read (fd, ptr, t);
if (p < 0) {
- if (repeated++ > 1000)
- error("Repeated error on reading from fd %d: %m\n", fd);
+ if (repeated++ > 1000) {
+ lerror("Repeated error on reading from fd %d: %m\n", fd);
+ }
if (errno == EINTR || errno == EAGAIN) {
errno = 0;
continue;
}
- if (noerr)
+ if (noerr || signaled)
goto out;
if (fd == 0 && errno == EIO)
warn("\e[31m\e[1msystem console stolen at line %d!\e[m\n", __LINE__);
- error("Can not read from fd %d: %m\n", fd);
+ lerror("Can not read from fd %d: %m\n", fd);
}
repeated = 0;
ptr += p;
@@ -302,7 +325,7 @@ out:
/*
* The stdio file pointer for our log file
*/
@ -63,7 +254,97 @@
static FILE * flog = NULL;
static int fdread = -1;
static int fdfifo = -1;
@@ -1463,6 +1463,10 @@ static void consalloc(struct console *re
@@ -310,7 +333,7 @@ static int fdfifo = -1;
/*
* Signal control for writing on log file
*/
-volatile sig_atomic_t nsigsys = 0;
+volatile sig_atomic_t nsigsys;
static volatile sig_atomic_t nsigio = -1;
static sigset_t save_oldset;
@@ -402,7 +425,7 @@ xout:
static inline void writelog(void)
{
if (!flog)
- goto xout;
+ return;
clearerr(flog);
lock(&llock);
while (avail > 0) {
@@ -412,7 +435,7 @@ static inline void writelog(void)
ret = TRANS_BUFFER_SIZE;
if (!flog)
- goto xout;;
+ break;
ret = fwrite(head, sizeof(unsigned char), ret, flog);
if (!ret && ferror(flog))
break;
@@ -429,12 +452,10 @@ static inline void writelog(void)
}
}
unlock(&llock);
- if (!flog)
- goto xout;;
- fflush(flog);
- fdatasync(fileno(flog));
-xout:
- return;
+ if (flog) {
+ fflush(flog);
+ fdatasync(fileno(flog));
+ }
}
static inline void flushlog(void)
@@ -808,7 +829,7 @@ static void more_input (struct timeval *
if (nfds < 0) {
timeout->tv_sec = 0;
timeout->tv_usec = 0;
- if (errno != EINTR)
+ if (errno != EINTR && !signaled)
error ("select(): %m\n");
goto nothing;
}
@@ -998,20 +1019,14 @@ void closeIO(void)
pthread_cancel(lthread);
}
- if (!flog)
- goto xout;
-
- writelog();
-
- if (!nl)
- fputc('\n', flog);
-
- if (!flog)
- goto xout;
-
- (void)fclose(flog);
+ if (flog) {
+ writelog();
+ if (!nl)
+ fputc('\n', flog);
+ (void)fclose(flog);
+ }
flog = NULL;
-xout:
+
if (fdfifo >= 0) {
close(fdfifo);
fdfifo = -1;
@@ -1101,7 +1116,7 @@ static dev_t fallback(const pid_t pid, c
printf("|%u|%u|", tty, ttypgrp); /* stdout to pipe synchronize ... */
- exit(0);
+ exit(EXIT_SUCCESS);
} break;
case -1:
error("can not execute: %m\n");
@@ -1463,6 +1478,10 @@ static void consalloc(struct console *re
return;
}
tail->next = newc;
@ -93,3 +374,23 @@
+extern struct console *cons;
#define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1))
#define strsize(string) ((strlen(string)+1)*sizeof(char))
--- showconsole.8
+++ showconsole.8 2011-04-19 11:59:52.844425538 +0000
@@ -41,7 +41,7 @@ Without any argument or the option
the
.B setconsole
undo any redirection.
-\."
+.\"
.SH OPTIONS
.TP
.B \-n
@@ -50,7 +50,7 @@ the device file name. This can be used
kernel for the major and minor device numbers of a not
existing device file in
.IR /dev .
-\."
+.\"
.SH BUGS
.B showconsole
needs a mounted

View File

@ -1,3 +1,9 @@
------------------------------------------------------------------
Tue Apr 19 14:08:04 CEST 2011 - werner@suse.de
- Avoid possible races which can be happen if blogd sees a signal
and will exit then (related to bnc#642289)
------------------------------------------------------------------
Fri Apr 15 16:47:43 CEST 2011 - werner@suse.de