Changeset 1998
- Timestamp:
- 06/24/08 05:57:49 (7 months ago)
- Files:
-
- branches/0.8/libwzd-core/wzd_log.c (modified) (7 diffs)
- branches/0.8/libwzd-core/wzd_site.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.8/libwzd-core/wzd_log.c
r1601 r1998 61 61 #include "wzd_misc.h" 62 62 #include "wzd_user.h" 63 #include "wzd_mutex.h" 63 64 64 65 #include "wzd_debug.h" … … 67 68 68 69 static struct memory_log_t _static_log; 70 71 static wzd_mutex_t * _static_log_mutex = NULL; 72 static int _static_log_enabled = 0; /* 0 = disabled */ 69 73 70 74 static void _buffer_push(const char *); … … 81 85 int i; 82 86 87 _static_log_mutex = wzd_mutex_create(0); /* argument is unused */ 88 if (_static_log_mutex) { 89 _static_log.size = 100; /* last 100 messages */ 90 _static_log.data = malloc(_static_log.size * sizeof(char *)); 91 if (_static_log.data) { 92 memset(_static_log.data, 0, _static_log.size * sizeof(char *)); 93 _static_log_enabled = 1; 94 } 95 } 96 83 97 for (i=0; i<MAX_LOG_CHANNELS; i++) { 84 98 _log_channels[i].fd = -1; 85 99 _log_channels[i].syslog = 0; 86 100 } 87 88 _static_log.size = 100; /* last 100 messages */89 _static_log.data = malloc(_static_log.size * sizeof(char*));90 memset(_static_log.data,0,_static_log.size * sizeof(char*));91 101 92 102 return 0; … … 118 128 { 119 129 int i,j,fd; 130 131 _static_log_enabled = 0; 132 wzd_mutex_lock(_static_log_mutex); 120 133 121 134 for (i=0; i<MAX_LOG_CHANNELS; i++) … … 131 144 } 132 145 133 for (i=0; i<_static_log.size; i++) { 134 free(_static_log.data[i]); 135 } 136 free(_static_log.data); 137 _static_log.size = 0; 146 if (_static_log_enabled) { 147 for (i=0; i<_static_log.size; i++) { 148 if (_static_log.data[i]) 149 free(_static_log.data[i]); 150 } 151 free(_static_log.data); 152 _static_log.size = 0; 153 } 154 155 wzd_mutex_destroy(_static_log_mutex); 156 _static_log_mutex = NULL; 138 157 } 139 158 … … 234 253 write(_log_channels[level].fd, buffer, strlen(buffer)); 235 254 } 236 237 _buffer_push(buffer); 255 256 if (_static_log_enabled) { 257 if (!wzd_mutex_lock(_static_log_mutex)) { 258 _buffer_push(buffer); 259 wzd_mutex_unlock(_static_log_mutex); 260 } 261 } 238 262 239 263 #ifndef _WIN32 … … 511 535 struct memory_log_t * get_log_buffer(void) 512 536 { 513 return (&_static_log); 514 } 515 537 if (_static_log_enabled) 538 return (&_static_log); 539 return NULL; 540 } 541 branches/0.8/libwzd-core/wzd_site.c
r1905 r1998 1561 1561 { 1562 1562 int i; 1563 struct memory_log_t * log = get_log_buffer();1564 wzd_string_t * buffer = str_allocate();1563 struct memory_log_t * log; 1564 wzd_string_t * buffer; 1565 1565 int lines_to_show = 10; 1566 1566 int offset = 0; 1567 1567 char *ptr; 1568 1568 unsigned long ul; 1569 1570 log = get_log_buffer(); 1571 if (!log) { 1572 send_message_with_args(501, context, "Static log buffer not enabled"); 1573 return -1; 1574 } 1575 buffer = str_allocate(); 1569 1576 1570 1577 /* check if we have an argument (the number of lines to display) */
