void irc_handle_connect(connection_t *cptr) { /* add our server */ { cptr->flags = CF_UPLINK; cptr->recvq_handler = irc_recvq_handler; connection_setselect_read(cptr, recvq_put); slog(LG_INFO, "irc_handle_connect(): connection to uplink established"); me.connected = true; /* no SERVER message received */ me.recvsvr = false; server_login(); #ifdef HAVE_GETTIMEOFDAY /* start our burst timer */ s_time(&burstime); #endif /* done bursting by this time... */ ping_sts(); /* ping our uplink every 5 minutes */ if (ping_uplink_timer != NULL) mowgli_timer_destroy(base_eventloop, ping_uplink_timer); ping_uplink_timer = mowgli_timer_add(base_eventloop, "ping_uplink", ping_uplink, NULL, 300); me.uplinkpong = time(NULL); } }
void _modinit(module_t *m) { chanfix_persist_record_t *rec = mowgli_global_storage_get("atheme.chanfix.main.persist"); chanfix_gather_init(rec); if (rec != NULL) { free(rec); return; } chanfix = service_add("chanfix", NULL); service_bind_command(chanfix, &cmd_list); service_bind_command(chanfix, &cmd_chanfix); service_bind_command(chanfix, &cmd_scores); service_bind_command(chanfix, &cmd_info); service_bind_command(chanfix, &cmd_help); service_bind_command(chanfix, &cmd_mark); service_bind_command(chanfix, &cmd_nofix); hook_add_event("channel_can_register"); hook_add_channel_can_register(chanfix_can_register); add_bool_conf_item("AUTOFIX", &chanfix->conf_table, 0, &chanfix_do_autofix, false); chanfix_autofix_timer = mowgli_timer_add(base_eventloop, "chanfix_autofix", chanfix_autofix_ev, NULL, 60); }
void helper_start(mowgli_eventloop_helper_proc_t *helper, void *userdata) { mowgli_eventloop_t *eventloop = helper->eventloop; mowgli_writef(helper->fd, "hi from pid %d\n", getpid()); mowgli_timer_add(eventloop, "timer_tick", (mowgli_event_dispatch_func_t *) timer_tick, helper, 1); mowgli_timer_add_once(eventloop, "timer_oneshot", (mowgli_event_dispatch_func_t *) timer_oneshot, helper, 5); mowgli_eventloop_run(eventloop); mowgli_writef(helper->fd, "eventloop halted\n"); mowgli_eventloop_destroy(eventloop); }
int main(int argc, char *argv[]) { eventloop = mowgli_eventloop_create(); mowgli_timer_add(eventloop, "timer_tick", timer_tick, NULL, 1); mowgli_timer_add_once(eventloop, "timer_oneshot", timer_oneshot, NULL, 5); mowgli_eventloop_run(eventloop); printf("eventloop halted\n"); mowgli_eventloop_destroy(eventloop); return EXIT_SUCCESS; }
int atheme_main(int argc, char *argv[]) { int daemonize_pipe[2]; bool have_conf = false; bool have_log = false; bool have_datadir = false; char buf[32]; int pid, r; FILE *pid_file; const char *pidfilename = RUNDIR "/atheme.pid"; char *log_p = NULL; mowgli_getopt_option_t long_opts[] = { { NULL, 0, NULL, 0, 0 }, }; atheme_bootstrap(); /* do command-line options */ while ((r = mowgli_getopt_long(argc, argv, "c:dhrl:np:D:v", long_opts, NULL)) != -1) { switch (r) { case 'c': config_file = sstrdup(mowgli_optarg); have_conf = true; break; case 'd': log_force = true; break; case 'h': print_help(); exit(EXIT_SUCCESS); break; case 'r': readonly = true; break; case 'l': log_p = sstrdup(mowgli_optarg); have_log = true; break; case 'n': runflags |= RF_LIVE; break; case 'p': pidfilename = mowgli_optarg; break; case 'D': datadir = mowgli_optarg; have_datadir = true; break; case 'v': print_version(); exit(EXIT_SUCCESS); break; default: printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n"); exit(EXIT_FAILURE); break; } } if (!have_conf) config_file = sstrdup(SYSCONFDIR "/atheme.conf"); if (!have_log) log_p = sstrdup(LOGDIR "/atheme.log"); if (!have_datadir) datadir = sstrdup(DATADIR); cold_start = true; runflags |= RF_STARTING; atheme_init(argv[0], log_p); slog(LG_INFO, "%s is starting up...", PACKAGE_STRING); /* check for pid file */ #ifndef MOWGLI_OS_WIN if ((pid_file = fopen(pidfilename, "r"))) { if (fgets(buf, 32, pid_file)) { pid = atoi(buf); if (!kill(pid, 0)) { fprintf(stderr, "atheme: daemon is already running\n"); exit(EXIT_FAILURE); } } fclose(pid_file); } #endif if (!(runflags & RF_LIVE)) daemonize(daemonize_pipe); atheme_setup(); conf_init(); if (!conf_parse(config_file)) { slog(LG_ERROR, "Error loading config file %s, aborting", config_file); exit(EXIT_FAILURE); } if (config_options.languagefile) { slog(LG_DEBUG, "Using language: %s", config_options.languagefile); if (!conf_parse(config_options.languagefile)) slog(LG_INFO, "Error loading language file %s, continuing", config_options.languagefile); } if (!backend_loaded && authservice_loaded) { slog(LG_ERROR, "atheme: no backend modules loaded, see your configuration file."); exit(EXIT_FAILURE); } /* we've done the critical startup steps now */ cold_start = false; /* load our db */ if (db_load) db_load(NULL); else if (backend_loaded) { slog(LG_ERROR, "atheme: backend module does not provide db_load()!"); exit(EXIT_FAILURE); } db_check(); #ifdef HAVE_GETPID /* write pid */ if ((pid_file = fopen(pidfilename, "w"))) { fprintf(pid_file, "%d\n", getpid()); fclose(pid_file); } else { fprintf(stderr, "atheme: unable to write pid file\n"); exit(EXIT_FAILURE); } #endif /* detach from terminal */ if ((runflags & RF_LIVE) || !detach_console(daemonize_pipe)) { #ifdef HAVE_GETPID slog(LG_INFO, "pid %d", getpid()); #endif slog(LG_INFO, "running in foreground mode from %s", PREFIX); } /* no longer starting */ runflags &= ~RF_STARTING; /* we probably have a few open already... */ me.maxfd = 3; /* DB commit interval is configurable */ if (db_save && !readonly) mowgli_timer_add(base_eventloop, "db_save", db_save, NULL, config_options.commit_interval); /* check expires every hour */ mowgli_timer_add(base_eventloop, "expire_check", expire_check, NULL, 3600); /* check k/x/q line expires every minute */ mowgli_timer_add(base_eventloop, "kline_expire", kline_expire, NULL, 60); mowgli_timer_add(base_eventloop, "xline_expire", xline_expire, NULL, 60); mowgli_timer_add(base_eventloop, "qline_expire", qline_expire, NULL, 60); /* check authcookie expires every ten minutes */ mowgli_timer_add(base_eventloop, "authcookie_expire", authcookie_expire, NULL, 600); /* reseed rng a little every five minutes */ mowgli_timer_add(base_eventloop, "rng_reseed", rng_reseed, NULL, 293); me.connected = false; uplink_connect(); /* main loop */ io_loop(); /* we're shutting down */ hook_call_shutdown(); if (db_save && !readonly) db_save(NULL); remove(pidfilename); errno = 0; if (curr_uplink != NULL && curr_uplink->conn != NULL) sendq_flush(curr_uplink->conn); connection_close_all(); me.connected = false; /* should we restart? */ if (runflags & RF_RESTART) { slog(LG_INFO, "main(): restarting"); #ifdef HAVE_EXECVE execv(BINDIR "/atheme-services", argv); #endif } slog(LG_INFO, "main(): shutting down"); mowgli_eventloop_destroy(base_eventloop); log_shutdown(); return 0; }