summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-11-06 14:26:52 -0600
committerMark Salyzyn2015-11-19 15:14:16 -0600
commit2d2e0a5c5eb0b0ea2fe1349da50e22228965faf9 (patch)
treeef9d05a98bc0eb3fe698089c0701e1db503ced29 /liblog/fake_log_device.c
parent9f903687011c195154b0c69c02e6aaa35c867242 (diff)
downloadplatform-system-core-2d2e0a5c5eb0b0ea2fe1349da50e22228965faf9.tar.gz
platform-system-core-2d2e0a5c5eb0b0ea2fe1349da50e22228965faf9.tar.xz
platform-system-core-2d2e0a5c5eb0b0ea2fe1349da50e22228965faf9.zip
liblog: resolve deadlocks
Although ever present, an increased regression introduced with commit b6bee33182cedea49199eb2252b3f3b442899c6d (liblog: logd: support logd.timestamp = monotonic). A signal handler can interrupt in locked context, if log is written in the signal handler, we are in deadlock. To reduce the contention and chances for this problem separate out timestamp lock from is loggable lock to reduce contention situations. Provide a best-guess response if lock would fail in timestamp path. Use a common lock() inline within each module, with a comment speaking to the issues surrounding calling a function that has a mutex within a signal handler. ToDo: Hold off signals temporarily in mainline, restart when unblock. Can not use pthread_sigmask(SIG_BLOCK,,) as it breaks AtCmd. Signed-off-by: Mark Salyzyn <salyzyn@google.com> Bug: 25563384 Change-Id: I47e2c87c988c3e359eb9eef129c6a3a08e9eedef
Diffstat (limited to 'liblog/fake_log_device.c')
-rw-r--r--liblog/fake_log_device.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 8a8ece250..cb80ee63c 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -99,6 +99,10 @@ static pthread_mutex_t fakeLogDeviceLock = PTHREAD_MUTEX_INITIALIZER;
99 99
100static void lock() 100static void lock()
101{ 101{
102 /*
103 * If we trigger a signal handler in the middle of locked activity and the
104 * signal handler logs a message, we could get into a deadlock state.
105 */
102 pthread_mutex_lock(&fakeLogDeviceLock); 106 pthread_mutex_lock(&fakeLogDeviceLock);
103} 107}
104 108
@@ -106,9 +110,12 @@ static void unlock()
106{ 110{
107 pthread_mutex_unlock(&fakeLogDeviceLock); 111 pthread_mutex_unlock(&fakeLogDeviceLock);
108} 112}
113
109#else // !defined(_WIN32) 114#else // !defined(_WIN32)
115
110#define lock() ((void)0) 116#define lock() ((void)0)
111#define unlock() ((void)0) 117#define unlock() ((void)0)
118
112#endif // !defined(_WIN32) 119#endif // !defined(_WIN32)
113 120
114 121