static void load_default_apps( const char* filename ) { char buf[1024]; int len; FILE* file = fopen( filename, "r" ); if( file ) { while ( fgets( buf, sizeof(buf) - 2, file ) ) { if ( buf[0] == '\0' || buf[0] == '\n' || buf[0] == '#' ) continue; /* a comment */ len = strlen ( buf ); if( buf[ len - 1 ] == '\n' ) /* remove the '\n' at the end of line */ { --len; buf[ len ] = '\0'; } switch(buf[0]) { case '@': /* if the app should be restarted on crash */ run_app( buf + 1, TRUE ); break; default: /* just run the program */ run_app( buf, FALSE ); } } fclose( file ); } }
void Application::algorithm(std::string name) { //emit print_log("create algorithm: " + name); if (name.compare("rnd") == 0) { if (alg == 0 && sp == 0) { sp = new SpaceParam(1024); alg = new RND(sp); connect(alg, SIGNAL(run_application(Point)), this, SLOT(run_app(Point))); connect(alg, SIGNAL(publish_result(FunctionND)), this, SLOT(publish_result(FunctionND))); connect(alg, SIGNAL(update_status(Status)), this, SLOT(update_status(Status))); } } else if (name.compare("bf") == 0) { if (alg == 0 && sp == 0) { sp = new SpaceParam(1024); alg = new BruteForce(sp); connect(alg, SIGNAL(run_application(Point)), this, SLOT(run_app(Point))); connect(alg, SIGNAL(publish_result(FunctionND)), this, SLOT(publish_result(FunctionND))); connect(alg, SIGNAL(update_status(Status)), this, SLOT(update_status(Status))); } } else if (name.compare("gr") == 0) { if (alg == 0 && sp == 0) { sp = new SpaceParam(1024); alg = new Gradient(sp); connect(alg, SIGNAL(run_application(Point)), this, SLOT(run_app(Point))); connect(alg, SIGNAL(publish_result(FunctionND)), this, SLOT(publish_result(FunctionND))); connect(alg, SIGNAL(update_status(Status)), this, SLOT(update_status(Status))); } } else if (name.compare("dhs") == 0) { if (alg == 0 && sp == 0) { sp = new SpaceParam(1024); alg = new Downhill_Simplex(sp); connect(alg, SIGNAL(run_application(Point)), this, SLOT(run_app(Point))); connect(alg, SIGNAL(publish_result(FunctionND)), this, SLOT(publish_result(FunctionND))); connect(alg, SIGNAL(update_status(Status)), this, SLOT(update_status(Status))); } } }
int main(void) { uint8_t app_index = 0; init_hw(); // cycle through apps for(;;) { reset_hw(); run_app(&apps[app_index]); reset_hw(); if(app_direction > 0) { play_melody(up_mldy, ARRAY_SIZE(up_mldy), 4, 100); app_index++; if(apps[app_index].run == NULL) { app_index = 0; } } else { play_melody(down_mldy, ARRAY_SIZE(down_mldy), 4, 100); if(app_index == 0) { app_index = MAX_APPS - 1; while(apps[app_index].run == NULL) --app_index; } else { app_index--; } } } }
/* * system wide default config is /etc/xdg/lxsession/SESSION_NAME/desktop.conf * system wide default apps are listed in /etc/xdg/lxsession/SESSION_NAME/autostart */ void start_session() { const gchar* const *dirs = g_get_system_config_dirs(); const gchar* const *dir; char* filename; /* run window manager first */ if( G_LIKELY( window_manager ) ) run_app( window_manager, TRUE ); if( G_UNLIKELY( !no_autostart ) ) { /* load system-wide default apps */ for( dir = dirs; *dir; ++dir ) { filename = g_build_filename( *dir, prog_name, session_name, autostart_filename, NULL ); load_default_apps( filename ); g_free( filename ); } /* load user-specific default apps */ filename = g_build_filename( g_get_user_config_dir(), prog_name, session_name, autostart_filename, NULL ); load_default_apps( filename ); g_free( filename ); /* Support autostart spec of freedesktop.org if not disable*/ xdg_autostart( session_name ); } }
static void on_child_exit( GPid pid, gint status, gchar* cmd ) { int sig = WTERMSIG( status ); /* if the term signal is not SIGTERM or SIGKILL, this might be a crash! */ if( sig && sig != SIGTERM && sig != SIGKILL ) run_app( cmd, TRUE ); }
AtspiAccessible * get_root_obj (const char *file_name) { int i; AtspiAccessible *obj = NULL; run_app (file_name); /* sleep is needed to wait for fored test application*/ sleep (1); obj = atspi_get_desktop (0); gint child_count = atspi_accessible_get_child_count (obj, NULL); if (child_count < 1) { g_test_message ("Fail, test application not found\n"); g_test_fail (); kill (child_pid, SIGTERM); return NULL; } for (i=0; i<child_count; i++) { AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,i, NULL); if (!strcmp (atspi_accessible_get_name (child, NULL), "root_object")) return child; } g_test_message ("test object not found\n"); g_test_fail (); kill (child_pid, SIGTERM); return NULL; }
/** @brief Run the application. */ static void boot(void) { #ifdef ENABLE_UART // extra null bytes to make sure the status is properly sent uart_send(0); uart_send(0); // wait for the last byte while( !(UCSRxA & ((1<<UDREx)|(1<<TXCx))) ) ; UCSRxB = 0; // disable #endif #ifdef ENABLE_I2C_SLAVE TWCR = 0; TWAR = 0; #endif /* interruptions not used, moving interrupt vector not needed IVCR = (1<<IVCE); IVCR = (0<<IVSEL); */ #ifdef BOOT_CODE do{ BOOT_CODE }while(0); #endif run_app(); }
int main() { run_tests(); run_app(); getchar(); return 0; }
/* Load a file, open a directory or run an application. Or, if 'edit' is set: * edit a file, open an application, follow a symlink or mount a device. * * filer_window is the window to use for displaying a directory. * NULL will always use a new directory when needed. * src_window is the window to copy options from, or NULL. * * Returns TRUE on success. */ gboolean run_diritem(const guchar *full_path, DirItem *item, FilerWindow *filer_window, FilerWindow *src_window, gboolean edit) { if (item->flags & ITEM_FLAG_SYMLINK && edit) return follow_symlink(full_path, filer_window, src_window); switch (item->base_type) { case TYPE_DIRECTORY: if (item->flags & ITEM_FLAG_APPDIR && !edit) { run_app(full_path); return TRUE; } if (item->flags & ITEM_FLAG_MOUNT_POINT) { open_mountpoint(full_path, item, filer_window, src_window, edit); } else if (filer_window) filer_change_to(filer_window, full_path, NULL); else filer_opendir(full_path, src_window, NULL); return TRUE; case TYPE_FILE: if (EXECUTABLE_FILE(item) && !edit) { const char *argv[] = {NULL, NULL}; guchar *dir = filer_window ? filer_window->sym_path : NULL; if (item->mime_type == application_x_desktop) return run_desktop(full_path, NULL, dir); else argv[0] = full_path; return rox_spawn(dir, argv) != 0; } return open_file(full_path, edit ? text_plain : item->mime_type); case TYPE_ERROR: delayed_error(_("File doesn't exist, or I can't " "access it: %s"), full_path); return FALSE; default: delayed_error( _("I don't know how to open '%s'"), full_path); return FALSE; } }
int main(int argc, char *argv[]) { int exitcode = EXIT_FAILURE; init_early_config(argc, argv, BB_RUN_APP); /* Setup signal handling before anything else */ signal(SIGHUP, handle_signal); signal(SIGTERM, handle_signal); signal(SIGINT, handle_signal); signal(SIGQUIT, handle_signal); bb_init_log(); /* Initializing configuration */ init_config(argc, argv); bbconfig_parse_opts(argc, argv, PARSE_STAGE_PRECONF); GKeyFile *bbcfg = bbconfig_parse_conf(); /* XXX load the driver (or even better, the ldpath) through the protocol */ bbconfig_parse_opts(argc, argv, PARSE_STAGE_DRIVER); driver_detect(); if (bbcfg) { bbconfig_parse_conf_driver(bbcfg, bb_config.driver); g_key_file_free(bbcfg); } bbconfig_parse_opts(argc, argv, PARSE_STAGE_OTHER); config_dump(); bb_log(LOG_DEBUG, "%s version %s starting...\n", "optirun", GITVERSION); /* Connect to listening daemon */ bb_status.bb_socket = socketConnect(bb_config.socket_path, SOCK_NOBLOCK); if (bb_status.bb_socket < 0) { bb_log(LOG_ERR, "Could not connect to bumblebee daemon - is it running?\n"); run_fallback(argv + optind); bb_closelog(); return exitcode; } /* Request status */ if (bb_status.runmode == BB_RUN_STATUS) { exitcode = report_daemon_status(); } /* Run given application */ if (bb_status.runmode == BB_RUN_APP) { if (optind >= argc) { bb_log(LOG_ERR, "Missing argument: application to run\n"); print_usage(EXIT_FAILURE); } else { exitcode = run_app(argc, argv); } } bb_closelog(); bb_stop_all(); //stop any started processes that are left return exitcode; }
int boxer_main(int argc, char *argv[]) { int ret; uintptr_t sp; struct elf_data data; if (argc < 2) return -EINVAL; /* XXX needed. Probably does some libc stuff */ printf(" \b"); // printf("%s\n", environ[0]); ret = dune_init(0); if (ret) { printf("sandbox: failed to initialize Dune\n"); return ret; } ret = dune_enter(); if (ret) { printf("sandbox: failed to enter Dune mode\n"); return ret; } ret = load_elf(argv[1], &data); if (ret) return ret; // printf("sandbox: entry addr is %lx\n", data.entry); dune_set_user_fs(0); // default starting fs ret = trap_init(); if (ret) { printf("failed to initialize trap handlers\n"); return ret; } ret = umm_alloc_stack(&sp); if (ret) { printf("failed to alloc stack\n"); return ret; } sp = setup_arguments(sp, argv[1], &argv[2], environ, data); if (!sp) { printf("failed to setup arguments\n"); return -EINVAL; } ret = run_app(sp, data.entry); return ret; }
void ebbrt::lrt::boot::init_cpu() { /* per-core translation setup */ trans::init_cpu(); if (app::multi) { /* if multi, then construct only on core 0 and spin the others */ static std::atomic<bool> initialized {false}; if (event::get_location() == 0) { construct(); initialized = true; } else { while (initialized == false) ; } run_app(); } else if (event::get_location() == 0) { construct(); run_app(); } }
int main(int argc, char** argv) { if (argc != 2) { std::cout << "Usage: " << argv[0] << " WINDOWID" << std::endl; } else { Window foreign_window = hex2int(argv[1]); run_app(foreign_window); return 0; } }
int main() { BasePanel panel; ButtonPanel b_panel("base", "b_panel_1"); b_panel.setBounds(sf::Rect<int>(20, 20, 100, 100)); Panel::registerBasePanel(&panel); //EventDispatcher::getInstance()->registerSubscription(); //PanelContainer::getInstance()->registerPanel(&panel); run_app(); return 0; }
int main (int argc, char* argv[]) { t_window *window = NULL; if ((window = init_app()) == NULL) kill_app(window); int imgFlags = IMG_INIT_JPG|IMG_INIT_PNG|IMG_INIT_TIF; // Flags pour charger le support du JPG, PNG et TIF // Demarre SDL if ( SDL_Init(SDL_INIT_VIDEO) == -1 ) { fprintf(stderr,"Erreur lors de l'initialisation de la SDL\n"); return -1; } if ( IMG_Init(imgFlags) != imgFlags ) { fprintf(stderr,"Erreur lors de l'initialisation de la SDL_image : '%s'\n",IMG_GetError()); return -1; } run_app(window); kill_app(window); return 0; }
static PT_THREAD(handle_bl(void)) { PT_BEGIN(&s.pt); s.retries = 3; do { flash_init(); tftpc_init(); tftpc_get(FIRMWARE_FILENAME); PT_WAIT_UNTIL(&s.pt, !tftpc_busy()); uint8_t rc = tftpc_result(); if(rc == TFTPC_FLASH_ERROR) { // any flash write errors, make sure the code doesn't run invalidate_code(); } // valid app code in place? if(!check_valid_code()) { // figure out what happened // and set indicator switch(rc) { case TFTPC_SUCCESS: diag_set(1); s.retries--; break; case TFTPC_SERVER_DOWN: diag_set(2); break; case TFTPC_FILE_NOT_FOUND: diag_set(3); break; case TFTPC_ERROR: diag_set(4); s.retries--; break; case TFTPC_FLASH_ERROR: diag_set(5); s.retries--; break; } } else { run_app(); } timer_set(&s.timer, RETRY_TIME); PT_WAIT_UNTIL(&s.pt, timer_expired(&s.timer)); } while (s.retries > 0); while(1) { PT_YIELD(&s.pt); } PT_END(&s.pt); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { // int c; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ SystemInit(); RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(SystemCoreClock / SYSTICK_FREQUENCY_HZ); #ifdef TRACEUART TRACEUART_Configuration(); #endif //TRACEUART UART_Configuration(); LED_Init(); /* Output a message on Hyperterminal using printf function */ printf("\n\r\n\r"); printf("*** LATTICE FW LOADER V1.00 Build by phalt on ("__DATE__ "-" __TIME__ ")\n\r"); printf("*** LATTICE FW LOADER V1.00 Rebooting ...\n\r"); /* * wait for a keystroke (or a button press if you want.) */ // printf("\n\rPress Return to start, any other key To Enter the Console ...\n\r"); // c = awaitkey(DEFAULT_BOOT_DELAY); if(1) //(((c != '\r') && (c != '\n') && (c != '\0'))) { Delay(500); GPIO_ResetBits(BLINK_PORT, (0xF << LED1)); // traceprintf("\rtrace start OK\n\r"); // Codec_GPIO_Init(); // Delay(1); // /* Reset the Codec Registers */ // Codec_Reset(); // Delay(1); // /* Initialize the Control interface of the Audio Codec */ // Codec_CtrlInterface_Init(); // Delay(1); if(1) { GPIO_SetBits(BLINK_PORT, (0xF << LED1)); // WavePlayBack(AUDIOFREQ, 1); WavePlayerInit(AUDIOFREQ); GPIO_ResetBits(BLINK_PORT, (0xF << LED1)); } while(1) //eugene loop { // Codec_CtrlInterface_Init(); GPIO_SetBits(BLINK_PORT, (0x1 << LED1)); // Codec_Write(); Codec_ReadRegister(0x00); //test read of codec GPIO_ResetBits(BLINK_PORT, (0x1 << LED1)); Delay(1000); } if(1) //test { init_builtin_cmds(); serial_term(); } } printf("*** JUMP to Application now ...\n\r"); run_app(0x08000000); /* Infinite loop */ while (1); }
/** * @brief Entry function for coex * @param argc number of arguments * @param argv A pointer to arguments array * @return MLAN_STATUS_SUCCESS--success, otherwise--fail */ int main(int argc, char *argv[]) { char *ifname = "mlan0"; int c, daemonize = FALSE; for (;;) { c = getopt(argc, argv, "Bhi:v"); /* check if all command-line options have been parsed */ if (c == NO_OPTION) break; switch (c) { case 'B': daemonize = TRUE; break; case 'h': display_usage(); return MLAN_STATUS_SUCCESS; case 'v': fprintf(stdout, "Marvell 20/40coex application version %s\n", COEX_VER); return MLAN_STATUS_SUCCESS; case 'i': ifname = optarg; break; default: fprintf(stdout, "Invalid argument\n"); display_usage(); return MLAN_STATUS_SUCCESS; } } strncpy(dev_name, ifname, IFNAMSIZ); /* create a socket */ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { fprintf(stderr, "mlan2040coex: Cannot open socket.\n"); goto done; } if (get_range() != MLAN_STATUS_SUCCESS) { fprintf(stderr, "mlan2040coex: Cannot get range.\n"); goto done; } /* create a netlink socket */ if ((nl_sk = open_netlink()) == MLAN_STATUS_FAILURE) { fprintf(stderr, "mlan2040coex: Cannot open netlink socket.\n"); goto done; } signal(SIGHUP, terminate_handler); /* catch hangup signal */ signal(SIGTERM, terminate_handler); /* catch kill signal */ /** Make the process background-process */ if (daemonize) daemon(0, 0); /** run the application */ run_app(); done: if (sockfd) close(sockfd); if (nl_sk) close(nl_sk); return MLAN_STATUS_SUCCESS; }
int main(int argc, char *argv[]) { int exitcode = EXIT_FAILURE; init_early_config(argc, argv, BB_RUN_APP); /* Setup signal handling before anything else */ signal(SIGHUP, handle_signal); signal(SIGTERM, handle_signal); signal(SIGINT, handle_signal); signal(SIGQUIT, handle_signal); bb_init_log(); /* Initializing configuration */ init_config(argc, argv); bbconfig_parse_opts(argc, argv, PARSE_STAGE_PRECONF); __unused GKeyFile *bbcfg = bbconfig_parse_conf(); /* Connect to listening daemon */ bb_status.bb_socket = socketConnect(bb_config.socket_path, SOCK_BLOCK); if (bb_status.bb_socket < 0) { bb_log(LOG_ERR, "Could not connect to bumblebee daemon - is it running?\n"); run_fallback(argv + optind); bb_closelog(); return exitcode; } free_and_set_value(&bb_config.ld_path, malloc(BUFFER_SIZE)); if (bbsocket_query("LibraryPath", bb_config.ld_path, BUFFER_SIZE)) { bb_log(LOG_ERR, "Failed to retrieve LibraryPath setting.\n"); return EXIT_FAILURE; } free_and_set_value(&bb_config.x_display, malloc(BUFFER_SIZE)); if (bbsocket_query("VirtualDisplay", bb_config.x_display, BUFFER_SIZE)) { bb_log(LOG_ERR, "Failed to retrieve VirtualDisplay setting.\n"); return EXIT_FAILURE; } /* parse remaining common and optirun-specific options */ bbconfig_parse_opts(argc, argv, PARSE_STAGE_OTHER); bb_log(LOG_DEBUG, "%s version %s starting...\n", "optirun", GITVERSION); config_dump(); /* Request status */ if (bb_status.runmode == BB_RUN_STATUS) { exitcode = report_daemon_status(); } /* Run given application */ if (bb_status.runmode == BB_RUN_APP) { if (optind >= argc) { bb_log(LOG_ERR, "Missing argument: application to run\n"); print_usage(EXIT_FAILURE); } else { exitcode = run_app(argc, argv); } } bb_closelog(); bb_stop_all(); //stop any started processes that are left return exitcode; }
/* * A program runner. */ int main(int argc, char *argv[]) { int ch; GtkWidget *box, *label, *apps_tree, *scrollable; GValue g_9 = G_VALUE_INIT; GtkBindingSet *binding_set; struct state *st; st = init_state(); while ((ch = getopt(argc, argv, "")) != -1) usage(); argc -= optind; argv += optind; gtk_init(&argc, &argv); if (argc > 1) usage(); if (argc == 1) { st->name = strdup(argv[0]); run_app(st); return 0; } g_value_init(&g_9, G_TYPE_INT); g_value_set_int(&g_9, 9); window = gtk_dialog_new_with_buttons( "bytestream", NULL, 0, "_Close", GTK_RESPONSE_CLOSE, "_Run", GTK_RESPONSE_OK, NULL); box = gtk_dialog_get_content_area(GTK_DIALOG(window)); label = gtk_label_new("Select program."); scrollable = gtk_scrolled_window_new(NULL, NULL); if ((apps_tree = apps_tree_new()) == NULL) return 1; gtk_widget_set_size_request(window, 400, 300); g_object_set_property(G_OBJECT(box), "margin", &g_9); gtk_container_add(GTK_CONTAINER(scrollable), apps_tree); gtk_box_pack_start(GTK_BOX(box), label, /* expand */ 0, /* fill */ 1, /* padding */ 3); gtk_box_pack_start(GTK_BOX(box), scrollable, /* expand */ 1, /* fill */ 1, /* padding */ 3); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window, "response", G_CALLBACK(handle_response), apps_tree); g_signal_connect(window, "key-press-event", G_CALLBACK(key_pressed), st); g_signal_connect(apps_tree, "row-activated", G_CALLBACK(app_selected), st); binding_set = gtk_binding_set_by_class(G_OBJECT_GET_CLASS(apps_tree)); gtk_binding_entry_add_signal( binding_set, GDK_KEY_Return, GDK_SHIFT_MASK, "select-cursor-row", 1, G_TYPE_BOOLEAN, TRUE); gtk_binding_entry_add_signal( binding_set, GDK_KEY_ISO_Enter, GDK_SHIFT_MASK, "select-cursor-row", 1, G_TYPE_BOOLEAN, TRUE); gtk_binding_entry_add_signal( binding_set, GDK_KEY_KP_Enter, GDK_SHIFT_MASK, "select-cursor-row", 1, G_TYPE_BOOLEAN, TRUE); gtk_widget_show_all(window); gtk_main(); free_state(st); return 0; }
/** * Entry point */ int main(int argc, char **argv) { static const char* cmds[] = { "b", "buffer", "1", SETTINGR("Buffer size [KW], default: ",COLLECT_BUFSIZE), "d", "data", "1", SETTINGR("Data cache size [KB], with fallback to: ", GENERIC_DCACHE ), "i", "inst", "1", SETTINGR("Instruction cache size [KB], with fallback to: ", GENERIC_ICACHE), "f", "file", "1", "Sample output file, default: '" OUTPUT_DEFAULT "', '-' for stdout", "F", "Foreground", "0", "Run daemon in foreground", "r", "run", "1", "0=daemon, 1=config info, >1=<r>KB sample", "n", "number", "1", "Output size in [k|m|g|t] bytes, 0 = unlimited to stdout", "o", "onlinetest", "1", "[t<x>][c<x>] x=[a[n][w]][b[w]] 't'ot, 'c'ontinuous, default: ta8b", "p", "pidfile", "1", "daemon pidfile, default: " PID_DEFAULT , "s", "source", "1", "Injection source file, default: '" INPUT_DEFAULT "', '-' for stdin", "t", "threads", "1", "Number of threads", "v", "verbose", "1", "Verbose mask 0=none,1=summary,2=retries,4=timing,8=loop,16=code,32=test", "w", "write", "1", "Set write_wakeup_threshold [bits]", "h", "help", "0", "This help" }; static int nopts = sizeof(cmds)/(4*sizeof(char *)); struct option long_options[nopts+1]; char short_options[1+nopts*2]; int c,i,j; H_UINT bufct, bufrem, ierr; H_PARAMS cmd; if (havege_version(HAVEGE_PREP_VERSION)==NULL) error_exit("version conflict %s!=%s", HAVEGE_PREP_VERSION, havege_version(NULL)); #if NO_DAEMON==1 params->setup |= RUN_AS_APP; #endif #ifdef RAW_IN_ENABLE #define DIAG_USAGE2 SETTINGL("=inject ticks,", DIAG_RUN_INJECT)\ SETTINGL("=inject data", DIAG_RUN_TEST) params->setup |= INJECT | RUN_AS_APP; #else #define DIAG_USAGE2 "" #endif #ifdef RAW_OUT_ENABLE #define DIAG_USAGE1 SETTINGL("=capture,", DIAG_RUN_CAPTURE) params->setup |= CAPTURE | RUN_AS_APP; #else #define DIAG_USAGE1 "" #endif #if NUMBER_CORES>1 params->setup |= MULTI_CORE; #endif #ifdef SIGHUP signal(SIGHUP, tidy_exit); #endif signal(SIGINT, tidy_exit); signal(SIGTERM, tidy_exit); strcpy(short_options,""); bufct = bufrem = 0; /** * Build options */ for(i=j=0;j<(nopts*4);j+=4) { switch(cmds[j][0]) { case 'o': #ifdef ONLINE_TESTS_ENABLE break; #else continue; #endif case 'r': #if defined(RAW_IN_ENABLE) || defined (RAW_OUT_ENABLE) if (0!=(params->setup & (INJECT|CAPTURE))) { params->daemon = "havege_diagnostic"; cmds[j+3] = "run level, 0=diagnostic off,1=config info," DIAG_USAGE1 DIAG_USAGE2 ; } else #endif if (0!=(params->setup & RUN_AS_APP)) continue; break; case 's': if (0 == (params->setup & INJECT)) continue; break; case 't': if (0 == (params->setup & MULTI_CORE)) continue; break; case 'p': case 'w': case 'F': if (0 !=(params->setup & RUN_AS_APP)) continue; break; } long_options[i].name = cmds[j+1]; long_options[i].has_arg = atoi(cmds[j+2]); long_options[i].flag = NULL; long_options[i].val = cmds[j][0]; strcat(short_options,cmds[j]); if (long_options[i].has_arg!=0) strcat(short_options,":"); i += 1; } memset(&long_options[i], 0, sizeof(struct option)); do { c = getopt_long (argc, argv, short_options, long_options, NULL); switch(c) { case 'F': params->setup |= RUN_IN_FG; params->foreground = 1; break; case 'b': params->buffersz = ATOU(optarg) * 1024; if (params->buffersz<4) error_exit("invalid size %s", optarg); break; case 'd': params->d_cache = ATOU(optarg); break; case 'i': params->i_cache = ATOU(optarg); break; case 'f': params->sample_out = optarg; if (strcmp(optarg,"-") == 0 ) params->setup |= USE_STDOUT; break; case 'n': if (get_runsize(&bufct, &bufrem, optarg)) error_exit("invalid count: %s", optarg); params->setup |= RUN_AS_APP|RANGE_SPEC; if (bufct==0 && bufrem==0) params->setup |= USE_STDOUT; /* ugly but documented behavior! */ break; case 'o': params->tests_config = optarg; break; case 'p': params->pid_file = optarg; break; case 'r': params->run_level = ATOU(optarg); if (params->run_level != 0) params->setup |= RUN_AS_APP; break; case 's': params->sample_in = optarg; break; case 't': params->ncores = ATOU(optarg); if (params->ncores > NUMBER_CORES) error_exit("invalid thread count: %s", optarg); break; case 'v': params->verbose = ATOU(optarg); break; case 'w': params->setup |= SET_LWM; params->low_water = ATOU(optarg); break; case '?': case 'h': usage(0, nopts, long_options, cmds); case -1: break; } } while (c!=-1); if (params->tests_config == 0) params->tests_config = (0 != (params->setup & RUN_AS_APP))? TESTS_DEFAULT_APP : TESTS_DEFAULT_RUN; memset(&cmd, 0, sizeof(H_PARAMS)); cmd.collectSize = params->buffersz; cmd.icacheSize = params->i_cache; cmd.dcacheSize = params->d_cache; cmd.options = params->verbose & 0xff; cmd.nCores = params->ncores; cmd.testSpec = params->tests_config; cmd.msg_out = print_msg; if (0 != (params->setup & RUN_AS_APP)) { cmd.ioSz = APP_BUFF_SIZE * sizeof(H_UINT); if (params->verbose!=0 && 0==(params->setup & RANGE_SPEC)) params->run_level = 1; } #ifndef NO_DAEMON else { poolSize = get_poolsize(); i = (poolSize + 7)/8 * sizeof(H_UINT); cmd.ioSz = sizeof(struct rand_pool_info) + i *sizeof(H_UINT); } #endif if (0 != (params->verbose & H_DEBUG_TIME)) cmd.metering = show_meterInfo; if (0 !=(params->setup & CAPTURE) && 0 != (params->run_level == DIAG_RUN_CAPTURE)) cmd.options |= H_DEBUG_RAW_OUT; #ifdef RAW_IN_ENABLE if (0 !=(params->setup & INJECT) && 0 != (params->run_level & (DIAG_RUN_INJECT|DIAG_RUN_TEST))) { if (strcmp(params->sample_in,"-") == 0 ) fd_in = stdin; else fd_in = fopen(params->sample_in, "rb"); if (NULL == fd_in) error_exit("Unable to open: %s", params->sample_in); cmd.injection = injectFile; if (params->run_level==DIAG_RUN_INJECT) cmd.options |= H_DEBUG_RAW_IN; else if (params->run_level==DIAG_RUN_TEST) cmd.options |= H_DEBUG_TEST_IN; else usage(1, nopts, long_options, cmds); } #endif handle = havege_create(&cmd); ierr = handle==NULL? H_NOHANDLE : handle->error; switch(ierr) { case H_NOERR: break; case H_NOTESTSPEC: error_exit("unrecognized test setup: %s", cmd.testSpec); break; default: error_exit("Couldn't initialize haveged (%d)", ierr); } if (0 != (params->setup & RUN_AS_APP)) { if (params->run_level==1) anchor_info(handle); else if (0==(params->setup&(INJECT|CAPTURE))) { /* must specify range with --nunber or --run > 1 but not both */ if (params->run_level>1) { if (0==(params->setup&RANGE_SPEC)) { /* --run specified */ bufct = params->run_level/sizeof(H_UINT); bufrem = (params->run_level%sizeof(H_UINT))*1024; } else usage(2, nopts, long_options, cmds); /* both specified */ } else if (0==(params->setup&RANGE_SPEC)) usage(3,nopts, long_options, cmds); /* neither specified */ else if (0==(params->setup&USE_STDOUT)&&(bufct+bufrem)==0) usage(4, nopts, long_options, cmds); /* only with stdout */ run_app(handle, bufct, bufrem); } else if (0==(params->setup&USE_STDOUT)&&(bufct+bufrem)==0) usage(5, nopts, long_options, cmds); /* only with stdout */ else run_app(handle, bufct, bufrem); } #ifndef NO_DAEMON else run_daemon(handle); #endif havege_destroy(handle); exit(0); }
static int psgi_handler(request_rec *r) { SV *app, *env, *res; psgi_dir_config *c; int rc; psgi_apps_t *psgi_apps; int locked = 0; if (strcmp(r->handler, PSGI_HANDLER_NAME)) { return DECLINED; } rc = apr_global_mutex_lock(psgi_mutex); if (rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, r->server, "apr_global_mutex_lock() failed"); rc = HTTP_INTERNAL_SERVER_ERROR; goto exit; } locked = 1; c = (psgi_dir_config *) ap_get_module_config(r->per_dir_config, &psgi_module); if (c->file == NULL) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, r->server, "PSGIApp not configured"); return DECLINED; } PERL_SET_CONTEXT(perlinterp); ENTER; SAVETMPS; psgi_apps = (psgi_apps_t *)apr_shm_baseaddr_get(psgi_shm); app = apr_hash_get(psgi_apps->apps, c->file, APR_HASH_KEY_STRING); if (app == NULL) { app = load_psgi(r->pool, c->file); if (app == NULL) { server_error(r, "%s had compilation errors.", c->file); rc = HTTP_INTERNAL_SERVER_ERROR; goto exit; } SvREFCNT_inc(app); apr_hash_set(psgi_apps->apps, c->file, APR_HASH_KEY_STRING, app); } env = make_env(r, c); res = run_app(r, app, env); if (res == NULL) { server_error(r, "invalid response"); rc = HTTP_INTERNAL_SERVER_ERROR; goto exit; } rc = output_response(r, res); SvREFCNT_dec(res); exit: if (locked) { apr_global_mutex_unlock(psgi_mutex); } FREETMPS; LEAVE; return rc; }