... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Wed Mar 31 16:27:18 EEST 2010 (edwin) |
|
2 |
+------------------------------------- |
|
3 |
+ * shared/output.c: fix race condition in IDSESSION mode (bb #1838). |
|
4 |
+ |
|
1 | 5 |
Wed Mar 31 15:36:23 2010 +0300 (edwin) |
2 | 6 |
-------------------------------------- |
3 | 7 |
* unit_tests/check_common.sh: Fix print of test log when unit test fails (bb #1838). |
... | ... |
@@ -60,6 +60,7 @@ |
60 | 60 |
#ifdef CL_THREAD_SAFE |
61 | 61 |
#include <pthread.h> |
62 | 62 |
pthread_mutex_t logg_mutex = PTHREAD_MUTEX_INITIALIZER; |
63 |
+pthread_mutex_t mdprintf_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
63 | 64 |
#endif |
64 | 65 |
|
65 | 66 |
#ifdef C_LINUX |
... | ... |
@@ -129,7 +130,6 @@ int mdprintf(int desc, const char *str, ...) |
129 | 129 |
int bytes, todo, ret=0; |
130 | 130 |
size_t len; |
131 | 131 |
|
132 |
- |
|
133 | 132 |
ARGLEN(args, str, len); |
134 | 133 |
if(len <= sizeof(buffer)) { |
135 | 134 |
len = sizeof(buffer); |
... | ... |
@@ -157,12 +157,21 @@ int mdprintf(int desc, const char *str, ...) |
157 | 157 |
bytes = len - 1; |
158 | 158 |
|
159 | 159 |
todo = bytes; |
160 |
+#ifdef CL_THREAD_SAFE |
|
161 |
+ /* make sure we don't mix sends from multiple threads, |
|
162 |
+ * important for IDSESSION */ |
|
163 |
+ pthread_mutex_lock(&mdprintf_mutex); |
|
164 |
+#endif |
|
160 | 165 |
while (todo > 0) { |
161 | 166 |
ret = send(desc, buff, bytes, 0); |
162 | 167 |
if (ret < 0) { |
163 | 168 |
struct timeval tv; |
164 | 169 |
if (errno != EWOULDBLOCK) |
165 | 170 |
break; |
171 |
+ /* didn't send anything yet */ |
|
172 |
+#ifdef CL_THREAD_SAFE |
|
173 |
+ pthread_mutex_unlock(&mdprintf_mutex); |
|
174 |
+#endif |
|
166 | 175 |
tv.tv_sec = 0; |
167 | 176 |
tv.tv_usec = mprintf_send_timeout*1000; |
168 | 177 |
do { |
... | ... |
@@ -171,6 +180,9 @@ int mdprintf(int desc, const char *str, ...) |
171 | 171 |
FD_SET(desc, &wfds); |
172 | 172 |
ret = select(desc+1, NULL, &wfds, NULL, &tv); |
173 | 173 |
} while (ret < 0 && errno == EINTR); |
174 |
+#ifdef CL_THREAD_SAFE |
|
175 |
+ pthread_mutex_lock(&mdprintf_mutex); |
|
176 |
+#endif |
|
174 | 177 |
if (!ret) { |
175 | 178 |
/* timed out */ |
176 | 179 |
ret = -1; |
... | ... |
@@ -181,6 +193,9 @@ int mdprintf(int desc, const char *str, ...) |
181 | 181 |
buff += ret; |
182 | 182 |
} |
183 | 183 |
} |
184 |
+#ifdef CL_THREAD_SAFE |
|
185 |
+ pthread_mutex_unlock(&mdprintf_mutex); |
|
186 |
+#endif |
|
184 | 187 |
|
185 | 188 |
if(len > sizeof(buffer)) |
186 | 189 |
free(abuffer); |