Ticket #44: lighty-spread.patch

File lighty-spread.patch, 3.7 kB (added by joe@…, 14 months ago)

A crappy patch for spread access logging.

  • mod_accesslog.c

     
    2727# include <syslog.h> 
    2828#endif 
    2929 
     30#include <sp.h> 
     31 
    3032typedef struct { 
    3133        char key; 
    3234        enum { 
     
    124126        size_t size; 
    125127} format_fields; 
    126128 
     129mailbox spread_mailbox; 
     130char groups[MAX_GROUP_NAME]; 
     131 
    127132typedef struct { 
    128133        buffer *access_logfile; 
    129134        buffer *format; 
    130135        unsigned short use_syslog; 
    131136 
     137  buffer *spread_location; 
     138  buffer *spread_group; 
    132139 
     140 
    133141        int    log_access_fd; 
    134142        time_t last_generated_accesslog_ts; 
    135143        time_t *last_generated_accesslog_ts_ptr; 
     
    148156        plugin_config conf; 
    149157} plugin_data; 
    150158 
     159void connect_to_spread(const char* location) 
     160{ 
     161  SP_disconnect(spread_mailbox); 
     162  SP_connect(location, 0, 0, 0, &spread_mailbox, groups); 
     163} 
     164 
     165void disconnect_from_spread() 
     166{ 
     167  SP_disconnect(spread_mailbox); 
     168} 
     169 
    151170INIT_FUNC(mod_accesslog_init) { 
    152171        plugin_data *p; 
    153172 
     
    370389                        buffer_free(s->access_logbuffer); 
    371390                        buffer_free(s->format); 
    372391                        buffer_free(s->access_logfile); 
     392                        buffer_free(s->spread_location); 
     393                        buffer_free(s->spread_group); 
    373394 
    374395                        if (s->parsed_format) { 
    375396                                size_t j; 
     
    400421                { "accesslog.filename",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, 
    401422                { "accesslog.use-syslog",           NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, 
    402423                { "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 }, 
    403426                { NULL,                             NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    404427        }; 
    405428 
     
    412435 
    413436                s = calloc(1, sizeof(plugin_config)); 
    414437                s->access_logfile = buffer_init(); 
     438                s->spread_location = buffer_init(); 
     439                s->spread_group = buffer_init(); 
    415440                s->format = buffer_init(); 
    416441                s->access_logbuffer = buffer_init(); 
    417442                s->ts_accesslog_str = buffer_init(); 
     
    423448                cv[0].destination = s->access_logfile; 
    424449                cv[1].destination = &(s->use_syslog); 
    425450                cv[2].destination = s->format; 
     451                cv[3].destination = s->spread_location; 
     452                cv[4].destination = s->spread_group; 
    426453 
     454 
     455    connect_to_spread(s->spread_location->ptr); 
     456 
    427457                p->config_storage[i] = s; 
    428458 
    429459                if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { 
     
    595625        plugin_config *s = p->config_storage[0]; 
    596626 
    597627        PATCH(access_logfile); 
     628        PATCH(spread_location); 
     629        PATCH(spread_group); 
    598630        PATCH(format); 
    599631        PATCH(log_access_fd); 
    600632        PATCH(last_generated_accesslog_ts_ptr); 
     
    663695 
    664696                                /* cache the generated timestamp */ 
    665697                                if (srv->cur_ts != *(p->conf.last_generated_accesslog_ts_ptr)) { 
    666                                         struct tm tm; 
    667698#if defined(HAVE_STRUCT_TM_GMTOFF) 
    668699                                        long scd, hrs, min; 
    669700#endif 
     
    671702                                        buffer_prepare_copy(p->conf.ts_accesslog_str, 255); 
    672703#if defined(HAVE_STRUCT_TM_GMTOFF) 
    673704# ifdef HAVE_LOCALTIME_R 
     705                                        struct tm tm; 
    674706                                        localtime_r(&(srv->cur_ts), &tm); 
    675707                                        strftime(p->conf.ts_accesslog_str->ptr, p->conf.ts_accesslog_str->size - 1, "[%d/%b/%Y:%H:%M:%S ", &tm); 
    676708# else 
     
    838870        } 
    839871 
    840872        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  } 
    841882 
    842883        if (p->conf.use_syslog ||  /* syslog doesn't cache */ 
    843884            (p->conf.access_logfile->used && p->conf.access_logfile->ptr[0] == '|') || /* pipes don't cache */