void corange_init(const char* core_assets_path) { /* Attach signal handlers */ signal(SIGABRT, corange_signal); signal(SIGFPE, corange_signal); signal(SIGILL, corange_signal); signal(SIGINT, corange_signal); signal(SIGSEGV, corange_signal); signal(SIGTERM, corange_signal); logout = fopen("output.log", "w"); at_error(corange_error); at_warning(corange_warning); at_debug(corange_debug); /* Starting Corange */ debug("Starting Corange..."); /* Asset Manager */ debug("Creating Asset Manager..."); debug("Core Assets At '%s' ...", core_assets_path); asset_init(); asset_add_path_variable(P("$CORANGE"), P(core_assets_path)); asset_handler(renderable, "bmf", bmf_load_file, renderable_delete); asset_handler(renderable, "obj", obj_load_file, renderable_delete); asset_handler(renderable, "smd", smd_load_file, renderable_delete); asset_handler(renderable, "ply", ply_load_file, renderable_delete); asset_handler(skeleton, "skl", skl_load_file, skeleton_delete); asset_handler(animation, "ani", ani_load_file, animation_delete); asset_handler(cmesh, "col", col_load_file, cmesh_delete); asset_handler(terrain, "raw", raw_load_file, terrain_delete); asset_handler(texture, "bmp", bmp_load_file, texture_delete); asset_handler(texture, "tga", tga_load_file, texture_delete); asset_handler(texture, "dds", dds_load_file, texture_delete); asset_handler(texture, "lut", lut_load_file, texture_delete); asset_handler(texture, "acv", acv_load_file, texture_delete); asset_handler(shader, "vs" , vs_load_file, shader_delete); asset_handler(shader, "fs" , fs_load_file, shader_delete); asset_handler(shader, "gs" , gs_load_file, shader_delete); asset_handler(shader, "tcs" , tcs_load_file, shader_delete); asset_handler(shader, "tes" , tes_load_file, shader_delete); asset_handler(config, "cfg", cfg_load_file, config_delete); asset_handler(lang, "lang", lang_load_file, lang_delete); asset_handler(font, "fnt", font_load_file, font_delete); asset_handler(material, "mat", mat_load_file, material_delete); asset_handler(effect, "effect" , effect_load_file, effect_delete); asset_handler(sound, "wav", wav_load_file, sound_delete); asset_handler(music, "ogg", ogg_load_file, music_delete); asset_handler(music, "mp3", mp3_load_file, music_delete); /* Entity Manager */ debug("Creating Entity Manager..."); entity_init(); entity_handler(static_object, static_object_new, static_object_delete); entity_handler(animated_object, animated_object_new, animated_object_delete); entity_handler(physics_object, physics_object_new, physics_object_delete); entity_handler(instance_object, instance_object_new, instance_object_delete); entity_handler(camera, camera_new, camera_delete); entity_handler(light, light_new, light_delete); entity_handler(landscape, landscape_new, landscape_delete); entity_handler(particles, particles_new, particles_delete); /* UI Manager */ debug("Creating UI Manager..."); ui_init(); ui_handler(ui_rectangle, ui_rectangle_new, ui_rectangle_delete, ui_rectangle_event, ui_rectangle_update, ui_rectangle_render); ui_handler(ui_text, ui_text_new, ui_text_delete, ui_text_event, ui_text_update, ui_text_render); ui_handler(ui_spinner, ui_spinner_new, ui_spinner_delete, ui_spinner_event, ui_spinner_update, ui_spinner_render); ui_handler(ui_button, ui_button_new, ui_button_delete, ui_button_event, ui_button_update, ui_button_render); ui_handler(ui_textbox, ui_textbox_new, ui_textbox_delete, ui_textbox_event, ui_textbox_update, ui_textbox_render); ui_handler(ui_browser, ui_browser_new, ui_browser_delete, ui_browser_event, ui_browser_update, ui_browser_render); ui_handler(ui_toast, ui_toast_new, ui_toast_delete, ui_toast_event, ui_toast_update, ui_toast_render); ui_handler(ui_dialog, ui_dialog_new, ui_dialog_delete, ui_dialog_event, ui_dialog_update, ui_dialog_render); ui_handler(ui_listbox, ui_listbox_new, ui_listbox_delete, ui_listbox_event, ui_listbox_update, ui_listbox_render); ui_handler(ui_option, ui_option_new, ui_option_delete, ui_option_event, ui_option_update, ui_option_render); ui_handler(ui_slider, ui_slider_new, ui_slider_delete, ui_slider_event, ui_slider_update, ui_slider_render); /* Graphics Manager */ debug("Creating Graphics Manager..."); graphics_init(); /* Audio Manager */ debug("Creating Audio Manager..."); audio_init(); /* Joystick Manager */ debug("Creating Joystick Manager..."); joystick_init(); /* Network Manager */ debug("Creating Network Manager..."); net_init(); debug("Finished!"); }
int main(int argc, char *argv[]) { printf("ISAKMP: main : <<<START>>> \n"); fd_set *rfds, *wfds; int n, m; size_t mask_size; struct timeval tv, *timeout; // closefrom(STDERR_FILENO + 1); /* * Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close * them. */ /* for (n = 0; n <= 2; n++) if (fcntl(n, F_GETFL, 0) == -1 && errno == EBADF) (void) open("/dev/null", n ? O_WRONLY : O_RDONLY, 0); */ /* Log cmd line parsing and initialization errors to stderr. */ log_to(stderr); parse_args(argc, argv); log_init(debug); /* Open protocols and services databases. */ setprotoent(1); setservent(1); /* Open command fifo */ ui_init(); set_slave_signals(); /* Daemonize before forking unpriv'ed child */ if (!debug) if (daemon(0, 0)) log_fatal("main: daemon (0, 0) failed"); /* Set timezone before priv'separation */ tzset(); write_pid_file(); /* if (monitor_init(debug)) { // The parent, with privileges enters infinite monitor loop. //monitor_loop(debug); //exit(0); // Never reached. }*/ /* Child process only from this point on, no privileges left. */ init(); /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init(pcap_file); /* Allocate the file descriptor sets just big enough. */ // we change here //n = getdtablesize(); n = 1000; mask_size = howmany(n, NFDBITS) * sizeof(fd_mask); rfds = (fd_set *) malloc(mask_size); if (!rfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); wfds = (fd_set *) malloc(mask_size); if (!wfds) log_fatal("main: malloc (%lu) failed", (unsigned long)mask_size); //monitor_init_done(); while (1) { /* If someone has sent SIGHUP to us, reconfigure. */ if (sighupped) { sighupped = 0; log_print("SIGHUP received"); reinit(); } /* and if someone sent SIGUSR1, do a state report. */ if (sigusr1ed) { sigusr1ed = 0; log_print("SIGUSR1 received"); report(); } /* * and if someone set 'sigtermed' (SIGTERM, SIGINT or via the * UI), this indicates we should start a controlled shutdown * of the daemon. * * Note: Since _one_ message is sent per iteration of this * enclosing while-loop, and we want to send a number of * DELETE notifications, we must loop atleast this number of * times. The daemon_shutdown() function starts by queueing * the DELETEs, all other calls just increments the * 'sigtermed' variable until it reaches a "safe" value, and * the daemon exits. */ if (sigtermed) daemon_shutdown(); /* Setup the descriptors to look for incoming messages at. */ bzero(rfds, mask_size); n = transport_fd_set(rfds); FD_SET(ui_socket, rfds); if (ui_socket + 1 > n) n = ui_socket + 1; /* * XXX Some day we might want to deal with an abstract * application class instead, with many instantiations * possible. */ if (!app_none && app_socket >= 0) { FD_SET(app_socket, rfds); if (app_socket + 1 > n) n = app_socket + 1; } /* Setup the descriptors that have pending messages to send. */ bzero(wfds, mask_size); m = transport_pending_wfd_set(wfds); printf(" m = %d , n = %d \n", m,n); if (m > n) n = m; /* Find out when the next timed event is. */ timeout = &tv; timer_next_event(&timeout); printf(" select (n n= %d )\n ",n ); n = select(n, rfds, wfds, 0, timeout); if (n == -1) { if (errno != EINTR) { log_error("main: select"); /* * In order to give the unexpected error * condition time to resolve without letting * this process eat up all available CPU * we sleep for a short while. */ sleep(1); } } else if (n) { transport_handle_messages(rfds); transport_send_messages(wfds); if (FD_ISSET(ui_socket, rfds)) ui_handler(); if (!app_none && app_socket >= 0 && FD_ISSET(app_socket, rfds)) app_handler(); } timer_handle_expirations(); } }
/** * Send an input key to the UI subsystem, with a print function for response * * @param key Input character * @param pf Print function for the response */ void ui_input_key(char key, struct re_printf *pf) { ui_handler(key, pf); }
int main (int argc, char *argv[]) { fd_set *rfds, *wfds; int n, m; size_t mask_size; struct timeval tv, *timeout; /* Make sure init() won't alloc fd 0, 1 or 2, as daemon() will close them. */ for (n = 0; n <= 2; n++) if (fcntl (n, F_GETFL, 0) == -1 && errno == EBADF) (void)open ("/dev/null", n ? O_WRONLY : O_RDONLY, 0); /* Log cmd line parsing and initialization errors to stderr. */ log_to (stderr); parse_args (argc, argv); log_init (); /* Do a clean daemon shutdown on TERM reception. (Needed by monitor). */ signal (SIGTERM, daemon_shutdown_now); if (debug) signal (SIGINT, daemon_shutdown_now); #if defined (USE_PRIVSEP) if (monitor_init ()) { /* The parent, with privileges. */ if (!debug) if (daemon (0, 0)) log_fatal ("main [priv]: daemon (0, 0) failed"); /* Enter infinite monitor loop. */ monitor_loop (debug); exit (0); /* Never reached. */ } /* Child process only from this point on, no privileges left. */ #endif init (); if (!debug) { if (daemon (0, 0)) log_fatal ("main: daemon (0, 0) failed"); /* Switch to syslog. */ log_to (0); } write_pid_file (); /* Reinitialize on HUP reception. */ signal (SIGHUP, sighup); /* Report state on USR1 reception. */ signal (SIGUSR1, sigusr1); /* Rehash soft expiration timers on USR2 reception. */ signal (SIGUSR2, sigusr2); #if defined (USE_DEBUG) /* If we wanted IKE packet capture to file, initialize it now. */ if (pcap_file != 0) log_packet_init (pcap_file); #endif /* Allocate the file descriptor sets just big enough. */ n = getdtablesize (); mask_size = howmany (n, NFDBITS) * sizeof (fd_mask); rfds = (fd_set *)malloc (mask_size); if (!rfds) log_fatal ("main: malloc (%lu) failed", (unsigned long)mask_size); wfds = (fd_set *)malloc (mask_size); if (!wfds) log_fatal ("main: malloc (%lu) failed", (unsigned long)mask_size); while (1) { /* If someone has sent SIGHUP to us, reconfigure. */ if (sighupped) { log_print ("SIGHUP received"); reinit (); sighupped = 0; } /* and if someone sent SIGUSR1, do a state report. */ if (sigusr1ed) { log_print ("SIGUSR1 received"); report (); } /* and if someone sent SIGUSR2, do a timer rehash. */ if (sigusr2ed) { log_print ("SIGUSR2 received"); rehash_timers (); } /* * and if someone set 'sigtermed' (SIGTERM or via the UI), this * indicated we should start a shutdown of the daemon. * * Note: Since _one_ message is sent per iteration of this enclosing * while-loop, and we want to send a number of DELETE notifications, * we must loop atleast this number of times. The daemon_shutdown() * function starts by queueing the DELETEs, all other calls just * increments the 'sigtermed' variable until it reaches a "safe" * value, and the daemon exits. */ if (sigtermed) daemon_shutdown (); /* Setup the descriptors to look for incoming messages at. */ memset (rfds, 0, mask_size); n = transport_fd_set (rfds); FD_SET (ui_socket, rfds); if (ui_socket + 1 > n) n = ui_socket + 1; /* * XXX Some day we might want to deal with an abstract application * class instead, with many instantiations possible. */ if (!app_none && app_socket >= 0) { FD_SET (app_socket, rfds); if (app_socket + 1 > n) n = app_socket + 1; } /* Setup the descriptors that have pending messages to send. */ memset (wfds, 0, mask_size); m = transport_pending_wfd_set (wfds); if (m > n) n = m; /* Find out when the next timed event is. */ timeout = &tv; timer_next_event (&timeout); n = select (n, rfds, wfds, 0, timeout); if (n == -1) { if (errno != EINTR) { log_error ("select"); /* * In order to give the unexpected error condition time to * resolve without letting this process eat up all available CPU * we sleep for a short while. */ sleep (1); } } else if (n) { transport_handle_messages (rfds); transport_send_messages (wfds); if (FD_ISSET (ui_socket, rfds)) ui_handler (); if (!app_none && app_socket >= 0 && FD_ISSET (app_socket, rfds)) app_handler (); } timer_handle_expirations (); } }
/** * Send input to the UI subsystem * * @param key Input character */ void ui_input(char key) { static struct re_printf pf_stdout = {stdout_handler, NULL}; ui_handler(key, &pf_stdout); }