Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:513:   {    if(shutdown_recurse >= 4)    {    if (mixed err =    catch (report_notice("Exiting roxen (spurious signals received).\n")) ||    catch (stop_all_configurations()))    master()->handle_error (err);    // Zap some of the remaining caches.    destruct(argcache);    destruct(cache); +  stop_error_log_cleaner();   #ifdef THREADS   #if constant(Filesystem.Monitor.basic)    stop_fsgarb();   #endif    if (mixed err = catch (stop_handler_threads()))    master()->handle_error (err);   #endif /* THREADS */    roxenloader.real_exit(exit_code);    }    if (shutdown_recurse++) return;
Roxen.git/server/base_server/roxen.pike:3216:    if( conf )    {    if( conf->error_log )    conf->error_log[log_index] += ({ log_time });    }       if(errtype >= 1)    report_debug( s );   }    + protected BackgroundProcess error_log_cleaner_process; +  + protected void clean_error_log(mapping(string:array(int)) log, +  mapping(string:int) cutoffs) + { +  if (!log || !sizeof(log)) return; +  foreach(cutoffs; string prefix; int cutoff) { +  foreach(log; string key; array(int) times) { +  if (!has_prefix(key, prefix)) continue; +  int sz = sizeof(times); +  times = filter(times, `>=, cutoff); +  if (sizeof(times) == sz) continue; +  // NB: There's a race here, where newly triggered errors may be lost. +  // It's very unlikely to be a problem in practice though. +  if (!sizeof(times)) { +  m_delete(log, key); +  } else { +  log[key] = times; +  } +  } +  } + } +  + protected void error_log_cleaner() + { +  mapping(string:int) cutoffs = ([ +  "1,": time(1) - 3600*24*7, // Keep notices for 7 days. +  ]); +  +  // First the global error_log. +  clean_error_log(error_log, cutoffs); +  +  // Then all configurations and modules. +  foreach(configurations, Configuration conf) { +  clean_error_log(conf->error_log, cutoffs); +  +  foreach(indices(conf->otomod), RoxenModule mod) { +  clean_error_log(mod->error_log, cutoffs); +  } +  } + } +  + protected void start_error_log_cleaner() + { +  if (error_log_cleaner_process) return; +  +  // Clean the error log once every hour. +  error_log_cleaner_process = BackgroundProcess(3600, error_log_cleaner); + } +  + protected void stop_error_log_cleaner() + { +  if (error_log_cleaner_process) { +  error_log_cleaner_process->stop(); +  error_log_cleaner_process = UNDEFINED; +  } + } +    // When was Roxen started?   int boot_time =time();   int start_time =time();      string version()   {   #ifndef NSERIOUS    return query("default_ident")?real_version:query("ident");   #else    multiset choices=(<>);
Roxen.git/server/base_server/roxen.pike:6019:    c->enable_all_modules();   #endif // RUN_SELF_TEST      #ifdef THREADS    start_handler_threads();   #if constant(Filesystem.Monitor.basic)    start_fsgarb();   #endif   #endif /* THREADS */    +  start_error_log_cleaner(); +    #ifdef TEST_EUID_CHANGE    if (test_euid_change) {    Stdio.File f = Stdio.File();    if (f->open ("rootonly", "r") && f->read())    werror ("Backend thread can read rootonly\n");    else    werror ("Backend thread can't read rootonly\n");    }   #endif