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 main(int argc, char* argv[]) { /* 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(); check_secondary(); init_config(argc, argv); /* Change GID and mask according to configuration */ if ((bb_config.gid_name != 0) && (bb_config.gid_name[0] != 0)){ bb_chgid(); } bb_log(LOG_DEBUG, "%s version %s starting...\n", bb_status.program_name, GITVERSION); /* Daemonized if daemon flag is activated */ if (bb_status.runmode == BB_RUN_DAEMON) { daemonize(); } /* Initialize communication socket, enter main loop */ bb_status.bb_socket = socketServer(bb_config.socket_path, SOCK_NOBLOCK); stop_secondary();//turn off card, nobody is connected right now. main_loop(); unlink(bb_config.socket_path); bb_status.runmode = BB_RUN_EXIT;//make sure all methods understand we are shutting down if (bb_config.card_shutdown_state) { //if shutdown state = 1, turn on card start_secondary(); } else { //if shutdown state = 0, turn off card stop_secondary(); } bb_closelog(); bb_stop_all(); //stop any started processes that are left return (EXIT_SUCCESS); }
int main(int argc, char* argv[]) { /* Setup signal handling before anything else */ signal(SIGHUP, handle_signal); signal(SIGTERM, handle_signal); signal(SIGINT, handle_signal); signal(SIGQUIT, handle_signal); /* Initializing configuration */ init_config(argc, argv); /* set runmode depending on leftover arguments */ if (optind >= argc) { bb_status.runmode = BB_RUN_STATUS; } else { bb_status.runmode = BB_RUN_APP; } bb_init_log(); bb_log(LOG_DEBUG, "%s version %s starting...\n", bb_status.program_name, 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"); bb_closelog(); return EXIT_FAILURE; } char buffer[BUFFER_SIZE]; int r; /* Request status */ if (bb_status.runmode == BB_RUN_STATUS) { r = snprintf(buffer, BUFFER_SIZE, "Status?"); socketWrite(&bb_status.bb_socket, buffer, r); while (bb_status.bb_socket != -1) { r = socketRead(&bb_status.bb_socket, buffer, BUFFER_SIZE); if (r > 0) { printf("Bumblebee status: %*s\n", r, buffer); socketClose(&bb_status.bb_socket); } } } /* Run given application */ if (bb_status.runmode == BB_RUN_APP) { int ranapp = 0; r = snprintf(buffer, BUFFER_SIZE, "Checking availability..."); socketWrite(&bb_status.bb_socket, buffer, r); while (bb_status.bb_socket != -1) { r = socketRead(&bb_status.bb_socket, buffer, BUFFER_SIZE); if (r > 0) { bb_log(LOG_INFO, "Response: %*s\n", r, buffer); switch (buffer[0]) { case 'N': //No, run normally. socketClose(&bb_status.bb_socket); if (!bb_config.fallback_start){ bb_log(LOG_ERR, "Cannot access secondary GPU. Aborting.\n"); } break; case 'Y': //Yes, run through vglrun bb_log(LOG_INFO, "Running application through vglrun.\n"); ranapp = 1; //run vglclient if any method other than proxy is used if (strncmp(bb_config.vgl_compress, "proxy", BUFFER_SIZE) != 0) { char * vglclient_args[] = { "vglclient", "-detach", 0 }; bb_run_fork(vglclient_args); } char ** vglrun_args = malloc(sizeof (char *) * (9 + argc - optind)); vglrun_args[0] = "vglrun"; vglrun_args[1] = "-c"; vglrun_args[2] = bb_config.vgl_compress; vglrun_args[3] = "-d"; vglrun_args[4] = bb_config.x_display; vglrun_args[5] = "-ld"; vglrun_args[6] = bb_config.ld_path; vglrun_args[7] = "--"; for (r = 0; r < argc - optind; r++) { vglrun_args[8 + r] = argv[optind + r]; } vglrun_args[8 + r] = 0; bb_run_fork_wait(vglrun_args); socketClose(&bb_status.bb_socket); break; default: //Something went wrong - output and exit. bb_log(LOG_ERR, "Problem: %*s\n", r, buffer); socketClose(&bb_status.bb_socket); break; } } } if (!ranapp && bb_config.fallback_start) { bb_log(LOG_WARNING, "Running application normally.\n"); bb_run_exec(argv + optind); } } bb_closelog(); bb_stop_all(); //stop any started processes that are left return (EXIT_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; }