| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Server Runtime logging code. | 8 * NaCl Server Runtime logging code. |
| 9 */ | 9 */ |
| 10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * If set, check detail_level without grabbing a mutex. This makes | 24 * If set, check detail_level without grabbing a mutex. This makes |
| 25 * logging much cheaper, but implies that the verbosity level should | 25 * logging much cheaper, but implies that the verbosity level should |
| 26 * only be changed prior to going multithreaded. | 26 * only be changed prior to going multithreaded. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "native_client/src/shared/gio/gio.h" | 29 #include "native_client/src/shared/gio/gio.h" |
| 30 #include "native_client/src/shared/platform/nacl_exit.h" | 30 #include "native_client/src/shared/platform/nacl_exit.h" |
| 31 #include "native_client/src/shared/platform/nacl_log.h" | 31 #include "native_client/src/shared/platform/nacl_log.h" |
| 32 #include "native_client/src/shared/platform/nacl_log_intern.h" | 32 #include "native_client/src/shared/platform/nacl_log_intern.h" |
| 33 #include "native_client/src/shared/platform/nacl_sync.h" | 33 #include "native_client/src/shared/platform/nacl_sync.h" |
| 34 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 34 #include "native_client/src/shared/platform/nacl_threads.h" | 35 #include "native_client/src/shared/platform/nacl_threads.h" |
| 35 #include "native_client/src/shared/platform/nacl_timestamp.h" | 36 #include "native_client/src/shared/platform/nacl_timestamp.h" |
| 36 | 37 |
| 37 /* | 38 /* |
| 38 * All logging is protected by this mutex. | 39 * All logging is protected by this mutex. |
| 39 */ | 40 */ |
| 40 static struct NaClMutex log_mu; | 41 static struct NaClMutex log_mu; |
| 41 static int tag_output = 0; | 42 static int tag_output = 0; |
| 42 static int abort_on_unlock = 0; | 43 static int abort_on_unlock = 0; |
| 43 | 44 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 log_iob = NaClLogDupFileIo(stderr); | 165 log_iob = NaClLogDupFileIo(stderr); |
| 165 } else { | 166 } else { |
| 166 log_iob = NaClLogFileIoBufferFromFile(log_file); | 167 log_iob = NaClLogFileIoBufferFromFile(log_file); |
| 167 } | 168 } |
| 168 return NaClLogGioFromFileIoBuffer(log_iob); | 169 return NaClLogGioFromFileIoBuffer(log_iob); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void NaClLogModuleInitExtended(int initial_verbosity, | 172 void NaClLogModuleInitExtended(int initial_verbosity, |
| 172 struct Gio *log_gio) { | 173 struct Gio *log_gio) { |
| 173 | 174 |
| 174 NaClMutexCtor(&log_mu); | 175 NaClXMutexCtor(&log_mu); |
| 175 NaClLogSetVerbosity(initial_verbosity); | 176 NaClLogSetVerbosity(initial_verbosity); |
| 176 NaClLogSetGio(log_gio); | 177 NaClLogSetGio(log_gio); |
| 177 } | 178 } |
| 178 | 179 |
| 179 void NaClLogModuleInit(void) { | 180 void NaClLogModuleInit(void) { |
| 180 NaClLogModuleInitExtended(NaClLogDefaultLogVerbosity(), | 181 NaClLogModuleInitExtended(NaClLogDefaultLogVerbosity(), |
| 181 NaClLogDefaultLogGio()); | 182 NaClLogDefaultLogGio()); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void NaClLogModuleFini(void) { | 185 void NaClLogModuleFini(void) { |
| 185 NaClMutexDtor(&log_mu); | 186 NaClMutexDtor(&log_mu); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void NaClLogTagNext_mu(void) { | 189 void NaClLogTagNext_mu(void) { |
| 189 tag_output = 1; | 190 tag_output = 1; |
| 190 } | 191 } |
| 191 | 192 |
| 192 void NaClLogLock(void) { | 193 void NaClLogLock(void) { |
| 193 NaClMutexLock(&log_mu); | 194 NaClXMutexLock(&log_mu); |
| 194 NaClLogTagNext_mu(); | 195 NaClLogTagNext_mu(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 void NaClLogUnlock(void) { | 198 void NaClLogUnlock(void) { |
| 198 if (abort_on_unlock) { | 199 if (abort_on_unlock) { |
| 199 /* | 200 /* |
| 200 * include an easy-to-recognize output for the fuzzer to recognize | 201 * include an easy-to-recognize output for the fuzzer to recognize |
| 201 */ | 202 */ |
| 202 NaClLog_mu(LOG_ERROR, "LOG_FATAL abort exit\n"); | 203 NaClLog_mu(LOG_ERROR, "LOG_FATAL abort exit\n"); |
| 203 #ifdef __COVERITY__ | 204 #ifdef __COVERITY__ |
| 204 NaClAbort(); /* help coverity figure out that this is the default */ | 205 NaClAbort(); /* help coverity figure out that this is the default */ |
| 205 #else | 206 #else |
| 206 (*gNaClLogAbortBehavior)(); | 207 (*gNaClLogAbortBehavior)(); |
| 207 #endif | 208 #endif |
| 208 } | 209 } |
| 209 NaClMutexUnlock(&log_mu); | 210 NaClXMutexUnlock(&log_mu); |
| 210 } | 211 } |
| 211 | 212 |
| 212 static INLINE struct Gio *NaClLogGetGio_mu() { | 213 static INLINE struct Gio *NaClLogGetGio_mu() { |
| 213 if (NULL == log_stream) { | 214 if (NULL == log_stream) { |
| 214 (void) GioFileRefCtor(&log_file_stream, NaClLogDupFileIo(stderr)); | 215 (void) GioFileRefCtor(&log_file_stream, NaClLogDupFileIo(stderr)); |
| 215 log_stream = (struct Gio *) &log_file_stream; | 216 log_stream = (struct Gio *) &log_file_stream; |
| 216 } | 217 } |
| 217 return log_stream; | 218 return log_stream; |
| 218 } | 219 } |
| 219 | 220 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 #if NON_THREAD_SAFE_DETAIL_CHECK | 394 #if NON_THREAD_SAFE_DETAIL_CHECK |
| 394 if (detail_level > verbosity) { | 395 if (detail_level > verbosity) { |
| 395 return; | 396 return; |
| 396 } | 397 } |
| 397 #endif | 398 #endif |
| 398 | 399 |
| 399 va_start(ap, fmt); | 400 va_start(ap, fmt); |
| 400 NaClLogV_mu(detail_level, fmt, ap); | 401 NaClLogV_mu(detail_level, fmt, ap); |
| 401 va_end(ap); | 402 va_end(ap); |
| 402 } | 403 } |
| OLD | NEW |