- fix deadlock in blogd that happens on shutdown (bnc#730193730193)

OBS-URL: https://build.opensuse.org/package/show/Base:System/sysvinit?expand=0&rev=177
This commit is contained in:
Ludwig Nussel 2012-06-21 07:18:40 +00:00 committed by Git OBS Bridge
parent b7674fbaa6
commit 4c8716cf10
3 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,78 @@
From 05c3f60fe02370f4c8d15b996bcc8d6f3dc57e12 Mon Sep 17 00:00:00 2001
From: Ludwig Nussel <ludwig.nussel@suse.de>
Date: Thu, 21 Jun 2012 09:09:19 +0200
Subject: [PATCH] fix deadlock
writelog() must not call pthread_yield() with the lock held that the
main thread tries to get to cancel the writer thread. writelog()
on the other hand needs to empty the buffer always to make sure
poll() blocks again an doesn't cause a loop.
---
libconsole.c | 25 +++++++++++++++++--------
1 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/libconsole.c b/libconsole.c
index b962032..54b353a 100644
--- a/libconsole.c
+++ b/libconsole.c
@@ -429,21 +429,28 @@ xout:
static inline void writelog(void)
{
- if (!flog)
+ lock(&llock);
+ if (!flog) { /* log file closed, reset buffer */
+ resetlog();
+ unlock(&llock);
return;
+ }
clearerr(flog);
- lock(&llock);
while (avail > 0) {
size_t ret = (size_t)avail;
if (avail > TRANS_BUFFER_SIZE)
ret = TRANS_BUFFER_SIZE;
- if (!flog || nsigsys)
+ if (!flog || nsigsys) { /* log file closed, reset buffer */
+ resetlog();
break;
+ }
ret = fwrite(head, sizeof(unsigned char), ret, flog);
- if (!ret && ferror(flog))
+ if (!ret && ferror(flog)) { /* cannot write anymore, reset buffer */
+ resetlog();
break;
+ }
head += ret;
if (head >= tail) { /* empty, reset buffer */
@@ -498,8 +505,13 @@ static inline int poll(int msec, mutex_t *outer)
if (err == ETIMEDOUT || err == EBUSY)
ret = 0;
}
- } else
+#if 0
+ } else {
+ unlock(&ljoin);
pthread_yield();
+ lock(&ljoin);
+#endif
+ }
return ret;
}
@@ -772,9 +784,6 @@ static void *action(void *dummy attribute((unused)))
if (!poll(30, &ljoin))
continue;
- if (!flog)
- break;
-
writelog();
}
unlock(&ljoin);
--
1.7.7

View File

@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu Jun 21 07:16:05 UTC 2012 - lnussel@suse.de
- fix deadlock in blogd that happens on shutdown (bnc#730193730193)
-------------------------------------------------------------------
Wed May 23 10:45:13 UTC 2012 - werner@suse.de

View File

@ -16,6 +16,7 @@
#
Name: sysvinit
%define PDVER 2.0.2
%define KPVER 2.21
@ -59,6 +60,7 @@ Patch20: powerd-%{PDVER}.dif
Patch21: powerd-%{PDVER}-getaddrinfo.patch
Patch30: killproc-%{KPVER}.dif
Patch40: showconsole-%{SCVER}.dif
Patch41: showconsole-1.16-deadlock.diff
Patch50: startpar-%{START}.dif
Requires: mingetty
Requires: sysvinit-tools
@ -126,6 +128,7 @@ ln -t../%{name}-%{SIVER}dsf/doc/killproc README
popd
pushd ../showconsole-%{SCVER}
%patch40
%patch41 -p1
ln -t../%{name}-%{SIVER}dsf/doc/showconsole README
popd
pushd ../startpar-%{START}