EAPI int elm_main (int argc, char** argv) { rockon_data *rdata; if (log_init() == EINA_FALSE) { EINA_LOG_ERR("Log domains init failed"); } rdata = rockon_data_new(); gui_window_set(rdata); xmms2_connect(rdata); if (rdata->connection == NULL) { cmd_server_launch(rdata); } EINA_LOG_DBG("MainLoop Start"); elm_run(); EINA_LOG_DBG("MainLoop End"); rockon_data_del(rdata); log_shutdown(); elm_shutdown(); return 0; }
DEFINE_SYSCALL(exit_group, int, status) { log_info("exit_group(%d)\n", status); /* TODO: Gracefully shutdown mm, vfs, etc. */ log_shutdown(); ExitProcess(status); }
void sploit_shutdown(void) { ssl_shutdown(); net_shutdown(); str_shutdown(); io_shutdown(); dlink_shutdown(); queue_shutdown(); log_shutdown(); timer_shutdown(); mem_shutdown(); syscall_exit(1); }
int main(int argc, char **argv) { #ifdef HAVE_FT2 const char *text = "Test text!"; const char *font = "arial.ttf"; const char *file = "ttftest.gif"; const char *bg = "heading-yellow.gif"; const char *color = "#000000"; log_init(STDOUT_FILENO, LOG_ALL, L_warning); io_init_except(STDOUT_FILENO, STDOUT_FILENO, STDOUT_FILENO); mem_init(); dlink_init(); gif_init(); image_init(); ttf_init(); ttftest_log = log_source_register("ttftest"); log_level(LOG_ALL, L_verbose); if(argc > 1) text = argv[1]; if(argc > 2) font = argv[2]; if(argc > 3) file = argv[3]; if(argc > 4) bg = argv[4]; if(argc > 5) color = argv[5]; ttftest_write(text, font, file, bg, color); log_level(LOG_ALL, L_warning); log_source_unregister(ttftest_log); ttf_shutdown(); image_shutdown(); gif_shutdown(); dlink_shutdown(); mem_shutdown(); log_shutdown(); io_shutdown(); #endif return 0; }
void gwlib_shutdown(void) { gwlib_assert_init(); charset_shutdown(); http_shutdown(); socket_shutdown(); gwthread_shutdown(); octstr_shutdown(); gwlib_protected_shutdown(); uuid_shutdown(); cfg_shutdown(); gw_check_leaks(); log_shutdown(); gwmem_shutdown(); init = 0; }
/* -------------------------------------------------------------------------- * * Clean things up. * * -------------------------------------------------------------------------- */ void servauth_shutdown(void) { log(servauth_log, L_status, "Shutting down servauth..."); syscall_exit(0); connect_shutdown(); io_shutdown(); queue_shutdown(); dlink_shutdown(); mem_shutdown(); log_shutdown(); timer_shutdown(); log_source_unregister(servauth_log); }
static void shutdown_everything(void) { if (console.filename) { free(console.filename); console.filename = NULL; } if (console.nextfilename) { free(console.nextfilename); console.nextfilename = NULL; } //config.close(); JMH osd_shutdown(); vid_shutdown(); log_shutdown(); }
void thread_shutdown(void) { if (_initialized == 1) { thread_mutex_destroy(&_library_mutex); thread_mutex_destroy(&_threadtree_mutex); #ifdef THREAD_DEBUG thread_mutex_destroy(&_mutextree_mutex); avl_tree_free(_mutextree, _free_mutex); #endif avl_tree_free(_threadtree, _free_thread); } #ifdef THREAD_DEBUG log_close(_logid); log_shutdown(); #endif }
int main() { printf("log_init\n"); log_init(STDOUT_FILENO, LOG_ALL, L_status); io_init_except(STDOUT_FILENO, STDOUT_FILENO, STDOUT_FILENO); mem_init(); dlink_init(); gif_init(); giftest_write(); gif_shutdown(); dlink_shutdown(); mem_shutdown(); log_shutdown(); io_shutdown(); return 0; }
static void _shutdown_subsystems(void) { fserve_shutdown(); xslt_shutdown(); refbuf_shutdown(); slave_shutdown(); auth_shutdown(); yp_shutdown(); stats_shutdown(); global_shutdown(); connection_shutdown(); config_shutdown(); resolver_shutdown(); sock_shutdown(); thread_shutdown(); /* Now that these are done, we can stop the loggers. */ _stop_logging(); log_shutdown(); xmlCleanupParser(); }
int main() { log_init(STDOUT_FILENO, LOG_ALL, L_status); io_init_except(STDOUT_FILENO, STDOUT_FILENO, STDOUT_FILENO); mem_init(); dlink_init(); gif_init(); image_init(); timer_init(); graph_init(); graphtest_write(); graph_shutdown(); timer_shutdown(); image_shutdown(); gif_shutdown(); dlink_shutdown(); mem_shutdown(); log_shutdown(); io_shutdown(); return 0; }
void shutdown_subsystems(void) { connection_shutdown(); slave_shutdown(); fserve_shutdown(); stats_shutdown(); stop_logging(); config_shutdown(); refbuf_shutdown(); resolver_shutdown(); sock_shutdown(); DEBUG0 ("library cleanups"); #ifdef HAVE_CURL curl_global_cleanup(); #endif /* Now that these are done, we can stop the loggers. */ log_shutdown(); xslt_shutdown(); thread_shutdown(); global_shutdown(); }
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; }
/* * Spawns the initial bot process and waits for them all to exit. */ int main(int argc, char *argv[]) { char *pythonpath = getenv("PYTHONPATH"); if (pythonpath) { char *str = (char*)xzmalloc(strlen(pythonpath) + strlen(":") + strlen("./libs") + 1); sprintf(str, "%s:%s", "./libs", pythonpath); setenv("PYTHONPATH", str, 1); free(str); } else { setenv("PYTHONPATH", "./libs", 1); } Py_Initialize(); init_opencore(); PyObject *sysPath = PySys_GetObject("path"); PyObject *libDir = PyString_FromString("."); PyList_Append(sysPath, libDir); Py_DECREF(libDir); if (pthread_key_create(&g_tls_key, NULL) != 0) { Log(OP_SMOD, "Error creating thread-specific storage"); exit(-1); } pthread_setspecific(g_tls_key, NULL); /* make directories */ mkdir("files", 0700); /* setup packet handlers */ for (int i = 0; i < 256; ++i) { g_pkt_core_handlers[i] = null_handler; g_pkt_game_handlers[i] = null_handler; } g_pkt_core_handlers[0x02] = pkt_handle_core_0x02; g_pkt_core_handlers[0x03] = pkt_handle_core_0x03; g_pkt_core_handlers[0x04] = pkt_handle_core_0x04; g_pkt_core_handlers[0x05] = pkt_handle_core_0x05; g_pkt_core_handlers[0x06] = pkt_handle_core_0x06; g_pkt_core_handlers[0x07] = pkt_handle_core_0x07; g_pkt_core_handlers[0x08] = pkt_handle_core_0x08_0x09; g_pkt_core_handlers[0x09] = pkt_handle_core_0x08_0x09; g_pkt_core_handlers[0x0A] = pkt_handle_core_0x0A; g_pkt_core_handlers[0x0E] = pkt_handle_core_0x0E; g_pkt_game_handlers[0x02] = pkt_handle_game_0x02; g_pkt_game_handlers[0x03] = pkt_handle_game_0x03; g_pkt_game_handlers[0x04] = pkt_handle_game_0x04; g_pkt_game_handlers[0x07] = pkt_handle_game_0x07; g_pkt_game_handlers[0x06] = pkt_handle_game_0x06; g_pkt_game_handlers[0x0A] = pkt_handle_game_0x0A; g_pkt_game_handlers[0x0D] = pkt_handle_game_0x0D; g_pkt_game_handlers[0x0E] = pkt_handle_game_0x0E; g_pkt_game_handlers[0x14] = pkt_handle_game_0x14; g_pkt_game_handlers[0x19] = pkt_handle_game_0x19; g_pkt_game_handlers[0x1C] = pkt_handle_game_0x1C; g_pkt_game_handlers[0x1D] = pkt_handle_game_0x1D; g_pkt_game_handlers[0x27] = pkt_handle_game_0x27; g_pkt_game_handlers[0x28] = pkt_handle_game_0x28; g_pkt_game_handlers[0x29] = pkt_handle_game_0x29; g_pkt_game_handlers[0x2E] = pkt_handle_game_0x2E; g_pkt_game_handlers[0x2F] = pkt_handle_game_0x2F; g_pkt_game_handlers[0x31] = pkt_handle_game_0x31; struct utsname uts; bzero(&uts, sizeof(struct utsname)); uname(&uts); uint64_t hash = hash_buf(&uts, sizeof(struct utsname)); g_machineid = gen_valid_mid(hash & 0xFFFFFFFF); g_permissionid = hash >> 32; load_op_file(); static const char* const masterconfig = "types/master.conf"; log_init(); db_init(masterconfig); botman_init(); /* run the master bot */ char arenaname[32] = { '\0' }; config_get_string("login.masterarena", arenaname, sizeof(arenaname), "#master", masterconfig); LogFmt(OP_MOD, "Starting master into %s", arenaname); char *err = StartBot("master", arenaname, NULL); if (err) { LogFmt(OP_MOD, "Error starting master bot: %s", err); return -1; } /* become the bot management thread and loop */ botman_mainloop(); botman_shutdown(); db_shutdown(); log_shutdown(); pthread_key_delete(g_tls_key); Py_Finalize(); return 0; }
int main(int argc, char *argv[]) { bool have_conf = false; bool have_log = false; char buf[32]; int i, pid, r; FILE *pid_file; const char *pidfilename = RUNDIR "/atheme.pid"; #ifdef HAVE_GETRLIMIT struct rlimit rlim; #endif curr_uplink = NULL; mowgli_init(); /* Prepare gettext */ #ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); #endif /* change to our local directory */ if (chdir(PREFIX) < 0) { perror(PREFIX); return 20; } #ifdef HAVE_GETRLIMIT /* it appears certian systems *ahem*linux*ahem* * don't dump cores by default, so we do this here. */ if (!getrlimit(RLIMIT_CORE, &rlim)) { rlim.rlim_cur = rlim.rlim_max; setrlimit(RLIMIT_CORE, &rlim); } #endif /* do command-line options */ while ((r = getopt(argc, argv, "c:dhrl:np:v")) != -1) { switch (r) { case 'c': config_file = sstrdup(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_path = sstrdup(optarg); have_log = true; break; case 'n': runflags |= RF_LIVE; break; case 'p': pidfilename = optarg; break; case 'v': print_version(); exit(EXIT_SUCCESS); break; default: printf("usage: atheme [-dhnvr] [-c conf] [-l logfile] [-p pidfile]\n"); exit(EXIT_SUCCESS); break; } } if (!have_conf) config_file = sstrdup(SYSCONFDIR "/atheme.conf"); if (!have_log) log_path = sstrdup(LOGDIR "/atheme.log"); cold_start = true; runflags |= RF_STARTING; me.kline_id = 0; me.start = time(NULL); CURRTIME = me.start; srand(arc4random()); me.execname = argv[0]; /* set signal handlers */ init_signal_handlers(); /* initialize strshare */ strshare_init(); /* open log */ log_open(); mowgli_log_set_cb(process_mowgli_log); slog(LG_INFO, "%s is starting up...", PACKAGE_STRING); /* check for pid file */ 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); } #if HAVE_UMASK /* file creation mask */ umask(077); #endif event_init(); hooks_init(); init_netio(); init_socket_queues(); db_init(); translation_init(); #ifdef ENABLE_NLS language_init(); #endif init_nodes(); init_confprocess(); init_newconf(); servtree_init(); modules_init(); pcommand_init(); 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); } authcookie_init(); common_ctcp_init(); 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(); else if (backend_loaded) { slog(LG_ERROR, "atheme: backend module does not provide db_load()!"); exit(EXIT_FAILURE); } db_check(); #ifdef HAVE_FORK /* fork into the background */ if (!(runflags & RF_LIVE)) { close(0); if (open("/dev/null", O_RDWR) != 0) { slog(LG_ERROR, "unable to open /dev/null??"); exit(EXIT_FAILURE); } if ((i = fork()) < 0) { slog(LG_ERROR, "can't fork into the background"); exit(EXIT_FAILURE); } /* parent */ else if (i != 0) { slog(LG_INFO, "pid %d", i); slog(LG_INFO, "running in background mode from %s", PREFIX); exit(EXIT_SUCCESS); } /* parent is gone, just us now */ if (setsid() < 0) { slog(LG_ERROR, "unable to create new session: %s", strerror(errno)); exit(EXIT_FAILURE); } dup2(0, 1); dup2(0, 2); } else { slog(LG_INFO, "pid %d", getpid()); slog(LG_INFO, "running in foreground mode from %s", PREFIX); } #else slog(LG_INFO, "running in foreground mode from %s", PREFIX); #endif #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 /* 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) event_add("db_save", db_save, NULL, config_options.commit_interval); /* check expires every hour */ event_add("expire_check", expire_check, NULL, 3600); /* check k/x/q line expires every minute */ event_add("kline_expire", kline_expire, NULL, 60); event_add("xline_expire", xline_expire, NULL, 60); event_add("qline_expire", qline_expire, NULL, 60); /* check authcookie expires every ten minutes */ event_add("authcookie_expire", authcookie_expire, NULL, 600); /* reseed rng a little every five minutes */ event_add("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"); log_shutdown(); return 0; }
static LONG CALLBACK exception_handler(PEXCEPTION_POINTERS ep) { if (ep->ExceptionRecord->ExceptionCode == DBG_CONTROL_C) return EXCEPTION_CONTINUE_SEARCH; if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) return EXCEPTION_CONTINUE_SEARCH; if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { uint8_t* code = (uint8_t *)ep->ContextRecord->Xip; if (ep->ExceptionRecord->ExceptionInformation[0] == 8) { /* DEP problem */ if (mm_handle_page_fault(code, false)) return EXCEPTION_CONTINUE_EXECUTION; else { /* The problem may be actually in the next page */ if (mm_handle_page_fault(code + PAGE_SIZE, false)) return EXCEPTION_CONTINUE_EXECUTION; } } else { /* Read/write problem */ log_info("IP: 0x%p", ep->ContextRecord->Xip); bool is_write = (ep->ExceptionRecord->ExceptionInformation[0] == 1); if (mm_handle_page_fault((void *)ep->ExceptionRecord->ExceptionInformation[1], is_write)) return EXCEPTION_CONTINUE_EXECUTION; void *ip = (void *)ep->ContextRecord->Xip; if (ip >= &mm_check_read_begin && ip <= &mm_check_read_end) { ep->ContextRecord->Xip = (XWORD)&mm_check_read_fail; log_warning("mm_check_read() failed at location 0x%x", ep->ExceptionRecord->ExceptionInformation[1]); return EXCEPTION_CONTINUE_EXECUTION; } if (ip >= &mm_check_read_string_begin && ip <= &mm_check_read_string_end) { ep->ContextRecord->Xip = (XWORD)&mm_check_read_string_fail; log_warning("mm_check_read_string() failed at location 0x%x", ep->ExceptionRecord->ExceptionInformation[1]); return EXCEPTION_CONTINUE_EXECUTION; } if (ip >= &mm_check_write_begin && ip <= &mm_check_write_end) { ep->ContextRecord->Xip = (XWORD)&mm_check_write_fail; log_warning("mm_check_write() failed at location 0x%x", ep->ExceptionRecord->ExceptionInformation[1]); return EXCEPTION_CONTINUE_EXECUTION; } } if (ep->ExceptionRecord->ExceptionInformation[0] == 0) log_error("Page fault(read): %p at %p", ep->ExceptionRecord->ExceptionInformation[1], ep->ContextRecord->Xip); else if (ep->ExceptionRecord->ExceptionInformation[0] == 1) log_error("Page fault(write): %p at %p", ep->ExceptionRecord->ExceptionInformation[1], ep->ContextRecord->Xip); else if (ep->ExceptionRecord->ExceptionInformation[0] == 8) log_error("Page fault(DEP): %p at %p", ep->ExceptionRecord->ExceptionInformation[1], ep->ContextRecord->Xip); } log_info("Application crashed, dumping debug information..."); mm_dump_memory_mappings(); mm_dump_windows_memory_mappings(GetCurrentProcess()); mm_dump_stack_trace(ep->ContextRecord); #ifdef _WIN64 log_info("RAX: 0x%p", ep->ContextRecord->Rax); log_info("RCX: 0x%p", ep->ContextRecord->Rcx); log_info("RDX: 0x%p", ep->ContextRecord->Rdx); log_info("RBX: 0x%p", ep->ContextRecord->Rbx); log_info("RSP: 0x%p", ep->ContextRecord->Rsp); log_info("RBP: 0x%p", ep->ContextRecord->Rbp); log_info("RSI: 0x%p", ep->ContextRecord->Rsi); log_info("RDI: 0x%p", ep->ContextRecord->Rdi); log_info("R8: 0x%p", ep->ContextRecord->R8); log_info("R9: 0x%p", ep->ContextRecord->R9); log_info("R10: 0x%p", ep->ContextRecord->R10); log_info("R11: 0x%p", ep->ContextRecord->R11); log_info("R12: 0x%p", ep->ContextRecord->R12); log_info("R13: 0x%p", ep->ContextRecord->R13); log_info("R14: 0x%p", ep->ContextRecord->R14); log_info("R15: 0x%p", ep->ContextRecord->R15); #else log_info("EAX: 0x%p", ep->ContextRecord->Eax); log_info("ECX: 0x%p", ep->ContextRecord->Ecx); log_info("EDX: 0x%p", ep->ContextRecord->Edx); log_info("EBX: 0x%p", ep->ContextRecord->Ebx); log_info("ESP: 0x%p", ep->ContextRecord->Esp); log_info("EBP: 0x%p", ep->ContextRecord->Ebp); log_info("ESI: 0x%p", ep->ContextRecord->Esi); log_info("EDI: 0x%p", ep->ContextRecord->Edi); #endif /* If we come here we're sure to crash, so gracefully close logging */ log_shutdown(); return EXCEPTION_CONTINUE_SEARCH; }
void fork_init() { if (!strcmp(GetCommandLineA(), "/?/fork")) { /* We're a fork child */ log_info("We're a fork child.\n"); fork_child(); } else { #ifdef _WIN64 /* On Win64, the default base address for ET_EXEC executable is 0x400000 * which is problematic that sometimes win32 dlls will allocate memory there * To workaround this issue, we first check if the address space there is * occupied. If so, we create a suspended child process and pre-reserve * the memory region, then transfer control to the child process. * The child process detects such circumstances and release the preserved * memory before use. */ size_t region_start = 0x400000; size_t region_size = 0x10000000; /* 256MB maximum executable size */ MEMORY_BASIC_INFORMATION info; VirtualQuery(region_start, &info, sizeof(MEMORY_BASIC_INFORMATION)); if (info.State == MEM_FREE && info.RegionSize >= region_size) { /* That's good, reserve the space now */ VirtualAlloc(region_start, region_size, MEM_RESERVE, PAGE_NOACCESS); } else if (info.State == MEM_RESERVE && info.RegionSize == region_size) { /* We're a child who has the pages protected by the parent, nothing to do here */ } else { /* Not good, create a child process and hope this time we can do it better */ log_warning("The address %p is occupied, we have to create another process to proceed.\n", region_start); wchar_t filename[MAX_PATH]; GetModuleFileNameW(NULL, filename, sizeof(filename) / sizeof(filename[0])); PROCESS_INFORMATION info; STARTUPINFOW si = { 0 }; si.cb = sizeof(si); if (!CreateProcessW(filename, GetCommandLineW(), NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &info)) { log_error("CreateProcessW() failed, error code: %d\n", GetLastError()); ExitProcess(1); } /* Pre-reserve the memory */ if (!VirtualAllocEx(info.hProcess, region_start, region_size, MEM_RESERVE, PAGE_NOACCESS)) { log_error("VirtualAllocEx() failed, error code: %d\n", GetLastError()); ExitProcess(1); } /* All done */ log_shutdown(); ResumeThread(info.hThread); ExitProcess(0); } #endif /* Allocate fork_info memory early to avoid possible VirtualAlloc() collision */ VirtualAlloc(FORK_INFO_BASE, BLOCK_SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); /* Return control flow to main() */ } }
int main(int argc, char **argv) { char logpath[FILENAME_MAX]; int log; if (argc != 2) { fprintf(stderr, PACKAGE_STRING "\n" " (c) Copyright 2001-2004 The IceS Development Team <*****@*****.**>\n" " Michael Smith <*****@*****.**>\n" " Karl Heyes <*****@*****.**>\n" " and others\n" "\n" "Usage: \"ices config.xml\"\n"); return 1; } config_initialize(); if (config_read(argv[1]) <= 0) { fprintf(stderr, "Failed to read config file \"%s\"\n", argv[1]); goto fail; } if (ices_config->background) { #ifndef _WIN32 int ret = 0; /* Start up new session, to lose old session and process group */ switch (fork()) { case 0: break; /* child continues */ case -1: perror ("fork"); ret = -1; default: exit (ret); } /* Disassociate process group and controlling terminal */ setsid(); /* Become a NON-session leader so that a */ /* control terminal can't be reacquired */ switch (fork()) { case 0: break; /* child continues */ case -1: perror ("fork"); ret = -1; default: exit (ret); } #else FreeConsole(); #endif } log_initialize(); thread_initialize(); shout_init(); encode_init(); #ifndef _WIN32 signals_setup(); #endif snprintf(logpath, FILENAME_MAX, "%s/%s", ices_config->logpath, ices_config->logfile); if(ices_config->log_stderr) log = log_open_file(stderr); else { log = log_open(logpath); if (log < 0) fprintf (stderr, "unable to open log %s\n", logpath); log_set_trigger (log, ices_config->logsize); } /* Set the log level, if requested - defaults to 2 (WARN) otherwise */ if (ices_config->loglevel) log_set_level(log, ices_config->loglevel); ices_config->log_id = log; LOG_INFO0(PACKAGE_STRING " started..."); if (ices_config->pidfile != NULL) { FILE *f = fopen (ices_config->pidfile, "w"); if (f) { fprintf (f, "%i", getpid()); fclose (f); } else { LOG_WARN1("pidfile \"%s\" cannot be written to", ices_config->pidfile); xmlFree (ices_config->pidfile); ices_config->pidfile = NULL; } } /* Start the core streaming loop */ input_loop(); if (ices_config->pidfile) remove (ices_config->pidfile); LOG_INFO0("Shutdown complete"); log_close(log); fail: encode_close(); shout_shutdown(); config_shutdown(); thread_shutdown(); log_shutdown(); return 0; }
void cmd_parser(unsigned long data) { char *curr_pos = &user_string[0]; int ret; while(1) { while(cmd_in_progress) os_TaskDelay(10); DBG_P(( DBG_L0 "\r\n> ")); cmd_parser_read_line(); if(strlen(user_string) == 0) { /* Do Nothing. */ } else if(!memcmp(user_string,"iwlist",6)){ userif_prepare_scan_cmd(0); } else if(!memcmp(user_string,"iwconf",6)){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos,"essid",5)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; specificSSID.Len = strlen(curr_pos); memcpy((void *)specificSSID.SsId, curr_pos, strlen(curr_pos)); if(link_present) { if(currbss_type != BSS_INDEPENDENT) userif_prepare_deauth_cmd(); else userif_prepare_adhoc_stop_cmd(); } else { userif_prepare_scan_cmd(1); } link_present = 0; } else if (!memcmp(curr_pos,"mode",4)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; if(!memcmp(curr_pos,"ad-hoc",6)) { bss_type = BSS_INDEPENDENT; } else if(!memcmp(curr_pos,"manage",6)) { bss_type = BSS_INFRASTRUCTURE; } else { bss_type = BSS_ANY; } } else if (!memcmp(curr_pos,"ap",2)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; get_macaddr(curr_pos,(char *)specificBSSID); if (FindBSSIDinList()) { userif_prepare_auth_cmd(); } else { if(link_present) { link_present = 0; userif_prepare_deauth_cmd(); } else { userif_prepare_scan_cmd(2); } } } } else if(!memcmp(user_string,"econfi",6)){ unsigned int ip; unsigned int nm; unsigned int gw; curr_pos = &user_string[get_next_word(user_string)]; get_ipaddr(curr_pos, (char *)&ip); curr_pos = &curr_pos[get_next_word(curr_pos)]; get_ipaddr(curr_pos, (char *)&nm); curr_pos = &curr_pos[get_next_word(curr_pos)]; get_ipaddr(curr_pos, (char *)&gw); sys_tcpip_init(ip, nm); } else if(!memcmp(user_string, "printip", 7)){ DBG_P(( DBG_L0 "%d.%d.%d.%d,", ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3] )); DBG_P(( DBG_L0 "%d.%d.%d.%d,", net_mask[0], net_mask[1], net_mask[2], net_mask[3] )); DBG_P(( DBG_L0 "%d.%d.%d.%d\r\n", def_gtwy[0], def_gtwy[1], def_gtwy[2], def_gtwy[3] )); } else if(!memcmp(user_string, "printmac", 8)){ char mac[6]; GetMACAddr(NULL, mac); DBG_P(( DBG_L0 "%02x:%02x:%02x:%02x:%02x:%02x\r\n", \ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])); } else if(!memcmp(user_string,"ping",4)){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos,"stop",4)) { send_ping = 0; } else { get_ipaddr(curr_pos, ping_ipaddr); #ifdef EMBEDDED_TCPIP userif_prepare_open_raw_socket(); #else userif_prepare_macaddr_get_cmd(); #endif send_ping = 1; } } /* Link-local address manager. */ else if(!memcmp(user_string, "linklocal", 9)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { /* Launch the link local manager */ ret = ll_init(); if(ret) DBG_P(( DBG_L0 "Error launching link local: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "stop", 4)) { /* Kill the link local manager. */ ret = ll_shutdown(); if(ret) DBG_P(( DBG_L0 "Error killing link local: %d.\r\n", ret)); } } /* mDNS responder */ else if(!memcmp(user_string, "mdns", 4)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { /* launch the mDNS responder */ ret = mdns_responder_init(); if(ret) DBG_P(( DBG_L0 "Error launching mDNS responder: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "stop", 4)) { /* stop the mDNS responder */ ret = mdns_responder_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping mDNS responder: %d.\r\n", ret)); } } else if(!memcmp(user_string, "mcast", 5 )){ curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "get", 3 )) { userif_prepare_mcast_cmd(); } else if(!memcmp(curr_pos, "set", 3 )) { userif_prepare_mcast_add_cmd(); } } /* httpd interface */ else if(!memcmp(user_string, "httpd", 5)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "start", 5)) { ret = httpd_init(); if(ret) DBG_P(( DBG_L0 "Error launching httpd: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "stop", 4)) { ret = httpd_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping httpd: %d.\r\n", ret)); } else { DBG_P(( DBG_L0 "No such httpd command: %s.\r\n", curr_pos)); } } /* log interface */ else if(!memcmp(user_string, "log", 3)) { curr_pos = &user_string[get_next_word(user_string)]; if(!memcmp(curr_pos, "init", 5)) { ret = log_init(); if(ret) DBG_P(( DBG_L0 "Error launching logger: %d.\r\n",ret)); } else if(!memcmp(curr_pos, "shutdown", 8)) { ret = log_shutdown(); if(ret) DBG_P(( DBG_L0 "Error stopping logger: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "dump", 4)) { ret = log_dump(); if(ret) DBG_P(( DBG_L0 "Error dumping log: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "purge", 5)) { ret = log_purge(); if(ret) DBG_P(( DBG_L0 "Error purging log: %d.\r\n", ret)); } else if(!memcmp(curr_pos, "write", 5)) { curr_pos = &curr_pos[get_next_word(curr_pos)]; ret = log(curr_pos); if(ret) DBG_P(( DBG_L0 "Failed to write log: %d.\r\n", ret)); } else { DBG_P(( DBG_L0 "No such log command: %s.\r\n", curr_pos)); } } else if(!memcmp(user_string, "help", 4)) { print_usage(); } else { #ifdef UART_DRV DBG_P(( DBG_L0 "Unknown command.\r\n")); #endif } } }
void module_fini(void) { log_shutdown(); dsme_log(LOG_DEBUG, "bootreasonlogger.so unloaded"); }