Ticket #44: lighty-spread.patch
| File lighty-spread.patch, 3.7 kB (added by joe@…, 14 months ago) |
|---|
-
mod_accesslog.c
27 27 # include <syslog.h> 28 28 #endif 29 29 30 #include <sp.h> 31 30 32 typedef struct { 31 33 char key; 32 34 enum { … … 124 126 size_t size; 125 127 } format_fields; 126 128 129 mailbox spread_mailbox; 130 char groups[MAX_GROUP_NAME]; 131 127 132 typedef struct { 128 133 buffer *access_logfile; 129 134 buffer *format; 130 135 unsigned short use_syslog; 131 136 137 buffer *spread_location; 138 buffer *spread_group; 132 139 140 133 141 int log_access_fd; 134 142 time_t last_generated_accesslog_ts; 135 143 time_t *last_generated_accesslog_ts_ptr; … … 148 156 plugin_config conf; 149 157 } plugin_data; 150 158 159 void connect_to_spread(const char* location) 160 { 161 SP_disconnect(spread_mailbox); 162 SP_connect(location, 0, 0, 0, &spread_mailbox, groups); 163 } 164 165 void disconnect_from_spread() 166 { 167 SP_disconnect(spread_mailbox); 168 } 169 151 170 INIT_FUNC(mod_accesslog_init) { 152 171 plugin_data *p; 153 172 … … 370 389 buffer_free(s->access_logbuffer); 371 390 buffer_free(s->format); 372 391 buffer_free(s->access_logfile); 392 buffer_free(s->spread_location); 393 buffer_free(s->spread_group); 373 394 374 395 if (s->parsed_format) { 375 396 size_t j; … … 400 421 { "accesslog.filename", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, 401 422 { "accesslog.use-syslog", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, 402 423 { "accesslog.format", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, 424 { "accesslog.spread_location", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, 425 { "accesslog.spread_group", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, 403 426 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 404 427 }; 405 428 … … 412 435 413 436 s = calloc(1, sizeof(plugin_config)); 414 437 s->access_logfile = buffer_init(); 438 s->spread_location = buffer_init(); 439 s->spread_group = buffer_init(); 415 440 s->format = buffer_init(); 416 441 s->access_logbuffer = buffer_init(); 417 442 s->ts_accesslog_str = buffer_init(); … … 423 448 cv[0].destination = s->access_logfile; 424 449 cv[1].destination = &(s->use_syslog); 425 450 cv[2].destination = s->format; 451 cv[3].destination = s->spread_location; 452 cv[4].destination = s->spread_group; 426 453 454 455 connect_to_spread(s->spread_location->ptr); 456 427 457 p->config_storage[i] = s; 428 458 429 459 if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { … … 595 625 plugin_config *s = p->config_storage[0]; 596 626 597 627 PATCH(access_logfile); 628 PATCH(spread_location); 629 PATCH(spread_group); 598 630 PATCH(format); 599 631 PATCH(log_access_fd); 600 632 PATCH(last_generated_accesslog_ts_ptr); … … 663 695 664 696 /* cache the generated timestamp */ 665 697 if (srv->cur_ts != *(p->conf.last_generated_accesslog_ts_ptr)) { 666 struct tm tm;667 698 #if defined(HAVE_STRUCT_TM_GMTOFF) 668 699 long scd, hrs, min; 669 700 #endif … … 671 702 buffer_prepare_copy(p->conf.ts_accesslog_str, 255); 672 703 #if defined(HAVE_STRUCT_TM_GMTOFF) 673 704 # ifdef HAVE_LOCALTIME_R 705 struct tm tm; 674 706 localtime_r(&(srv->cur_ts), &tm); 675 707 strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", &tm); 676 708 # else … … 838 870 } 839 871 840 872 BUFFER_APPEND_STRING_CONST(b, "\n"); 873 int result = 0; 874 if (p->conf.spread_location->used > 0) 875 { 876 result = SP_multicast(spread_mailbox, RELIABLE_MESS, p->conf.spread_group->ptr, 1, b->used - 1, b->ptr); 877 if (result < 0) 878 { 879 connect_to_spread(p->conf.spread_location->ptr); 880 } 881 } 841 882 842 883 if (p->conf.use_syslog || /* syslog doesn't cache */ 843 884 (p->conf.access_logfile->used && p->conf.access_logfile->ptr[0] == '|') || /* pipes don't cache */

