summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-11-16 13:00:41 -0600
committerMark Salyzyn2015-11-16 13:00:41 -0600
commitc2e7d4965f86dbe90cece6d25e91d934a698d195 (patch)
treecb111a72734a1b9e496a0a94765a568eb4eb00a6 /liblog/fake_log_device.c
parent7a2a3071921b11d7e476862e7f9cbe72be43d0f7 (diff)
downloadplatform-system-core-c2e7d4965f86dbe90cece6d25e91d934a698d195.tar.gz
platform-system-core-c2e7d4965f86dbe90cece6d25e91d934a698d195.tar.xz
platform-system-core-c2e7d4965f86dbe90cece6d25e91d934a698d195.zip
Revert "liblog: resolve deadlocks"
This reverts commit 7a2a3071921b11d7e476862e7f9cbe72be43d0f7. Bug: 25693940 Change-Id: I9a7c926289e972f80c03c92e33535e1dedaa7381
Diffstat (limited to 'liblog/fake_log_device.c')
-rw-r--r--liblog/fake_log_device.c41
1 files changed, 11 insertions, 30 deletions
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index fcdb6c928..8a8ece250 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -24,7 +24,6 @@
24#include <ctype.h> 24#include <ctype.h>
25#include <errno.h> 25#include <errno.h>
26#include <fcntl.h> 26#include <fcntl.h>
27#include <signal.h>
28#include <stdlib.h> 27#include <stdlib.h>
29#include <string.h> 28#include <string.h>
30 29
@@ -98,33 +97,18 @@ typedef struct LogState {
98 */ 97 */
99static pthread_mutex_t fakeLogDeviceLock = PTHREAD_MUTEX_INITIALIZER; 98static pthread_mutex_t fakeLogDeviceLock = PTHREAD_MUTEX_INITIALIZER;
100 99
101static void lock(sigset_t *sigflags) 100static void lock()
102{ 101{
103 /*
104 * If we trigger a signal handler in the middle of locked activity and the
105 * signal handler logs a message, we could get into a deadlock state.
106 */
107 sigset_t all;
108
109 sigfillset(&all);
110 pthread_sigmask(SIG_BLOCK, &all, sigflags);
111 pthread_mutex_lock(&fakeLogDeviceLock); 102 pthread_mutex_lock(&fakeLogDeviceLock);
112} 103}
113 104
114static void unlock(sigset_t *sigflags) 105static void unlock()
115{ 106{
116 pthread_mutex_unlock(&fakeLogDeviceLock); 107 pthread_mutex_unlock(&fakeLogDeviceLock);
117 pthread_sigmask(SIG_UNBLOCK, sigflags, NULL);
118} 108}
119
120#define DECLARE_SIGSET(name) sigset_t name
121
122#else // !defined(_WIN32) 109#else // !defined(_WIN32)
123 110#define lock() ((void)0)
124#define lock(sigflags) ((void)0) 111#define unlock() ((void)0)
125#define unlock(sigflags) ((void)0)
126#define DECLARE_SIGSET(name)
127
128#endif // !defined(_WIN32) 112#endif // !defined(_WIN32)
129 113
130 114
@@ -170,9 +154,8 @@ static LogState *fdToLogState(int fd)
170static void deleteFakeFd(int fd) 154static void deleteFakeFd(int fd)
171{ 155{
172 LogState *ls; 156 LogState *ls;
173 DECLARE_SIGSET(sigflags);
174 157
175 lock(&sigflags); 158 lock();
176 159
177 ls = fdToLogState(fd); 160 ls = fdToLogState(fd);
178 if (ls != NULL) { 161 if (ls != NULL) {
@@ -181,7 +164,7 @@ static void deleteFakeFd(int fd)
181 free(ls); 164 free(ls);
182 } 165 }
183 166
184 unlock(&sigflags); 167 unlock();
185} 168}
186 169
187/* 170/*
@@ -565,13 +548,12 @@ static void showLog(LogState *state,
565static ssize_t logWritev(int fd, const struct iovec* vector, int count) 548static ssize_t logWritev(int fd, const struct iovec* vector, int count)
566{ 549{
567 LogState* state; 550 LogState* state;
568 DECLARE_SIGSET(sigflags);
569 551
570 /* Make sure that no-one frees the LogState while we're using it. 552 /* Make sure that no-one frees the LogState while we're using it.
571 * Also guarantees that only one thread is in showLog() at a given 553 * Also guarantees that only one thread is in showLog() at a given
572 * time (if it matters). 554 * time (if it matters).
573 */ 555 */
574 lock(&sigflags); 556 lock();
575 557
576 state = fdToLogState(fd); 558 state = fdToLogState(fd);
577 if (state == NULL) { 559 if (state == NULL) {
@@ -616,10 +598,10 @@ static ssize_t logWritev(int fd, const struct iovec* vector, int count)
616 } 598 }
617 599
618bail: 600bail:
619 unlock(&sigflags); 601 unlock();
620 return vector[0].iov_len + vector[1].iov_len + vector[2].iov_len; 602 return vector[0].iov_len + vector[1].iov_len + vector[2].iov_len;
621error: 603error:
622 unlock(&sigflags); 604 unlock();
623 return -1; 605 return -1;
624} 606}
625 607
@@ -639,9 +621,8 @@ static int logOpen(const char* pathName, int flags __unused)
639{ 621{
640 LogState *logState; 622 LogState *logState;
641 int fd = -1; 623 int fd = -1;
642 DECLARE_SIGSET(sigflags);
643 624
644 lock(&sigflags); 625 lock();
645 626
646 logState = createLogState(); 627 logState = createLogState();
647 if (logState != NULL) { 628 if (logState != NULL) {
@@ -651,7 +632,7 @@ static int logOpen(const char* pathName, int flags __unused)
651 errno = ENFILE; 632 errno = ENFILE;
652 } 633 }
653 634
654 unlock(&sigflags); 635 unlock();
655 636
656 return fd; 637 return fd;
657} 638}