Exemplo n.º 1
0
static void core_minutely()
{
  check_tcl_time(&nowtm);
  check_tcl_cron(&nowtm);
  do_check_timers(&timer);
  if (quick_logs != 0) {
    flushlogs();
    check_logsize();
  }
}
Exemplo n.º 2
0
/* Called once a second.
 *
 * Note:  Try to not put any Context lines in here (guppy 21Mar2000).
 */
static void core_secondly()
{
  static int cnt = 0;
  int miltime;

  do_check_timers(&utimer);     /* Secondly timers */
  cnt++;
  if (cnt >= 10) {              /* Every 10 seconds */
    cnt = 0;
    check_expired_dcc();
    if (con_chan && !backgrd) {
      dprintf(DP_STDOUT, "\033[2J\033[1;1H");
      tell_verbose_status(DP_STDOUT);
      do_module_report(DP_STDOUT, 0, "server");
      do_module_report(DP_STDOUT, 0, "channels");
      tell_mem_status_dcc(DP_STDOUT);
    }
  }
  egg_memcpy(&nowtm, localtime(&now), sizeof(struct tm));
  if (nowtm.tm_min != lastmin) {
    int i = 0;

    /* Once a minute */
    lastmin = (lastmin + 1) % 60;
    call_hook(HOOK_MINUTELY);
    check_expired_ignores();
    autolink_cycle(NULL);       /* Attempt autolinks */
    /* In case for some reason more than 1 min has passed: */
    while (nowtm.tm_min != lastmin) {
      /* Timer drift, dammit */
      debug2("timer: drift (lastmin=%d, now=%d)", lastmin, nowtm.tm_min);
      i++;
      lastmin = (lastmin + 1) % 60;
      call_hook(HOOK_MINUTELY);
    }
    if (i > 1)
      putlog(LOG_MISC, "*", "(!) timer drift -- spun %d minutes", i);
    miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
    if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) {     /* 5 min */
      call_hook(HOOK_5MINUTELY);
      check_botnet_pings();
      if (!quick_logs) {
        flushlogs();
        check_logsize();
      }
      if (!miltime) {           /* At midnight */
        char s[25];
        int j;

        strncpyz(s, ctime(&now), sizeof s);
        if (quiet_save < 3)
          putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
        call_hook(HOOK_BACKUP);
        for (j = 0; j < max_logs; j++) {
          if (logs[j].filename != NULL && logs[j].f != NULL) {
            fclose(logs[j].f);
            logs[j].f = NULL;
          }
        }
      }
    }
    if (nowtm.tm_min == notify_users_at)
      call_hook(HOOK_HOURLY);
    /* These no longer need checking since they are all check vs minutely
     * settings and we only get this far on the minute.
     */
    if (miltime == switch_logfiles_at) {
      call_hook(HOOK_DAILY);
      if (!keep_all_logs) {
        if (quiet_save < 3)
          putlog(LOG_MISC, "*", MISC_LOGSWITCH);
        for (i = 0; i < max_logs; i++)
          if (logs[i].filename) {
            char s[1024];

            if (logs[i].f) {
              fclose(logs[i].f);
              logs[i].f = NULL;
            }
            egg_snprintf(s, sizeof s, "%s.yesterday", logs[i].filename);
            unlink(s);
            movefile(logs[i].filename, s);
          }
      }
    }
  }
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
  
  setup_corefile(); /* we wan't core files for debug */
  setup_signals();
  srandom(time(NULL)); /* random seed */  
  /* check if we are just doing a configuration change */
  if((argc > 1) && (strcasecmp(argv[1], "conf")==0))
    return cmd_conf(argc-2, &argv[2]);

  parse_command_line(argc, argv); /* parse command line options */
  printf("Starting %s, CopyRight PTlink IRC Software 1999-2005\n", svs_version);
  printf("Setting ircsvs log file to "LOGPATH "/ircsvs.log\n");

  /* rotate the logsize if required */
  check_logsize();  
  if(init_log(LOGPATH "/ircsvs.log") == 0)
  {
    fprintf(stderr,"ERROR: Could not create log file\n");
    return 3;
  }
  slog(L_INFO, "Starting %s", svs_version);
#if 0  
  if(TimeZone)
  {  
#ifdef HAVE_SETENV
    setenv("TZ",TimeZone,1);
    tzset();
#else
    fprintf(stderr, "TimeZone defined but setenv() is not supported on this OS!");
#endif
    }
#endif    
  /* Let's init the irc functions first, we may use them on modules */

  e_expire = mod_register_event("e_expire");
  e_complete = mod_register_event("e_complete");
  if(load_modules_file("ircsvs") < 0)
    {
      fprintf(stderr,"ERROR: Error loading modules\n");
      return -3;
    }
 
  stdlog(L_INFO, "All modules succesfully loaded");   
  /* check it here to avoid "Server already exists" uppon connection */
  if( nofork == 0 )
      check_pidfile();

#if 0
#warning need to move ExpireInterval to the module
  if(ExpireInterval)
    {
      stdlog(L_INFO, "Running expire routines...");
      ev_expire(NULL, NULL);    
      stdlog(L_INFO,"Expire interval set to %d minute(s)", ExpireInterval / 60);
      irc_AddEvent(ET_LOOP, ev_expire); /* set the expire routines */
    }
  else
    stdlog(L_WARN, "Data expiration is disabled");
#endif    

  stdlog(L_INFO, "Services startup completed.");
  mod_do_event(e_complete, NULL, NULL);  
  
  return 0;
}