Dr. Werner Fink 2011-08-01 14:48:33 +00:00 committed by Git OBS Bridge
parent 6f10c9a5f0
commit 1c1ff2bd95
2 changed files with 127 additions and 3 deletions

View File

@ -170,8 +170,123 @@
.SH FILES
.TP
.I /dev/console
--- libblogger.c
+++ libblogger.c 2011-08-01 14:32:47.599926864 +0000
@@ -15,6 +15,7 @@
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -40,9 +41,58 @@
#define ESNS "skipped" /* Skipped */
#define ESNU "unused" /* Unused */
+static struct sigaction saved_sigpipe;
+static volatile sig_atomic_t broken = 0;
static int fdfifo = -1;
static char * fifo_name = _PATH_BLOG_FIFO;
+static void sigpipe(int sig __attribute__((__unused__)))
+{
+ broken++;
+}
+
+static void set_signal(int sig, struct sigaction *old, sighandler_t handler)
+{
+ do {
+ if (sigaction(sig, NULL, old) == 0)
+ break;
+ } while (errno == EINTR);
+
+ if (old && old->sa_handler != handler) {
+ struct sigaction new;
+ sigset_t sigset;
+
+ new.sa_handler = handler;
+ sigemptyset(&new.sa_mask);
+ new.sa_flags = SA_RESTART;
+ do {
+ if (sigaction(sig, &new, NULL) == 0)
+ break;
+ } while (errno == EINTR);
+
+ sigemptyset(&sigset);
+ sigaddset(&sigset, sig);
+ sigprocmask(SIG_UNBLOCK, &sigset, NULL);
+ }
+}
+
+static void reset_signal(int sig, struct sigaction *old)
+{
+ struct sigaction cur;
+
+ do {
+ if (sigaction(sig, NULL, &cur) == 0)
+ break;
+ } while (errno == EINTR);
+
+ if (old && old->sa_handler == cur.sa_handler) {
+ do {
+ if (sigaction(sig, old, NULL) == 0)
+ break;
+ } while (errno == EINTR);
+ }
+}
+
static int bootlog_init(const int lvl __attribute__((__unused__)))
{
int ret = -1;
@@ -57,6 +107,8 @@ static int bootlog_init(const int lvl __
if ((fdfifo = open(fifo_name, O_WRONLY|O_NONBLOCK|O_NOCTTY|O_CLOEXEC)) < 0)
goto out;
+ set_signal(SIGPIPE, &saved_sigpipe, sigpipe);
+
ret = 0;
out:
return ret;
@@ -66,6 +118,9 @@ void closeblog()
{
if (fdfifo < 0)
goto out;
+
+ reset_signal(SIGPIPE, &saved_sigpipe);
+
(void)close(fdfifo);
out:
return;
@@ -77,6 +132,7 @@ int bootlog(const int lvl, const char *f
int ret = -1;
char * head = ESNN;
char buf[4096];
+ sigset_t blockpipe, oldpipe;
if (fdfifo < 0 && bootlog_init(lvl) < 0)
goto out;
@@ -106,6 +162,9 @@ int bootlog(const int lvl, const char *f
break;
}
+ sigprocmask(SIG_BLOCK, &blockpipe, &oldpipe);
+ if (broken)
+ goto pipe;
if (head) {
const struct tm *local;
struct timeval now;
@@ -124,6 +183,8 @@ int bootlog(const int lvl, const char *f
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
write(fdfifo, buf, strlen(buf));
+pipe:
+ sigprocmask(SIG_SETMASK, &oldpipe, NULL);
out:
return ret;
}
--- libconsole.c
+++ libconsole.c 2011-04-20 11:13:46.815926166 +0000
+++ libconsole.c 2011-08-01 14:00:51.311926463 +0000
@@ -59,6 +59,27 @@
#include "listing.h"
@ -345,11 +460,13 @@
clearerr(flog);
lock(&llock);
while (avail > 0) {
@@ -412,7 +440,7 @@ static inline void writelog(void)
@@ -411,8 +439,8 @@ static inline void writelog(void)
if (avail > TRANS_BUFFER_SIZE)
ret = TRANS_BUFFER_SIZE;
if (!flog)
- if (!flog)
- goto xout;;
+ if (!flog || nsigsys)
+ break;
ret = fwrite(head, sizeof(unsigned char), ret, flog);
if (!ret && ferror(flog))

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Aug 1 14:25:56 UTC 2011 - werner@suse.de
- libblogger: check for SIGPIPE and block SIGPIPE during write, this
also does help startpar not to die on SIGPIPE (bnc#679671)
- blogd: add a further check for nsigsys in writelog() (bnc#679671)
-------------------------------------------------------------------
Wed Jul 27 13:11:31 UTC 2011 - werner@suse.de