int main(int argc, char **argv) { int ret; struct kmscon_app app; ret = conf_parse_argv(argc, argv); if (ret) goto err_out; if (conf_global.exit) return EXIT_SUCCESS; if (!conf_global.debug && !conf_global.verbose && conf_global.silent) log_set_config(&LOG_CONFIG_WARNING(0, 0, 0, 0)); else log_set_config(&LOG_CONFIG_INFO(conf_global.debug, conf_global.verbose)); log_print_init("kmscon"); memset(&app, 0, sizeof(app)); ret = setup_app(&app); if (ret) goto err_out; if (conf_global.switchvt) { ret = kmscon_vt_enter(app.vt); if (ret) log_warn("cannot enter VT"); } ev_eloop_run(app.eloop, -1); if (conf_global.switchvt) { /* The VT subsystem needs to acknowledge the VT-leave so if it * returns -EINPROGRESS we need to wait for the VT-leave SIGUSR2 * signal to arrive. Therefore, we use a separate eloop object * which is used by the VT system only. Therefore, waiting on * this eloop allows us to safely wait 50ms for the SIGUSR2 to * arrive. * We use a timeout of 100ms to avoid haning on exit. * We could also wait on app.eloop but this would allow other * subsystems to continue receiving events and this is not what * we want. */ app.exit = true; ret = kmscon_vt_leave(app.vt); if (ret == -EINPROGRESS) ev_eloop_run(app.vt_eloop, 50); } destroy_app(&app); log_info("exiting"); return EXIT_SUCCESS; err_out: log_err("cannot initialize kmscon, errno %d: %s", ret, strerror(-ret)); return -ret; }
int main(int argc, char **argv) { int ret; struct uvtd_app app; log_set_config(&LOG_CONFIG_INFO(1, 1)); log_print_init("uvtd"); memset(&app, 0, sizeof(app)); ret = setup_app(&app); if (ret) goto err_out; ev_eloop_run(app.eloop, -1); ret = 0; destroy_app(&app); err_out: if (ret) log_err("cannot initialize uvtd, errno %d: %s", ret, strerror(-ret)); log_info("exiting"); return -ret; }
static int setup_app(struct kmscon_app *app) { int ret; ret = ev_eloop_new(&app->eloop); if (ret) goto err_app; ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM, sig_generic, app); if (ret) goto err_app; ret = ev_eloop_register_signal_cb(app->eloop, SIGINT, sig_generic, app); if (ret) goto err_app; ret = ev_eloop_new_eloop(app->eloop, &app->vt_eloop); if (ret) goto err_app; ret = kmscon_vt_new(&app->vt, vt_switch, app); if (ret) goto err_app; ret = uterm_video_new(&app->video, app->eloop, UTERM_VIDEO_DRM, "/dev/dri/card0"); if (ret) goto err_app; ret = uterm_video_use(app->video); if (ret) goto err_app; ret = kmscon_input_new(&app->input); if (ret) goto err_app; ret = kmscon_input_connect_eloop(app->input, app->eloop); if (ret) goto err_app; ret = kmscon_vt_open(app->vt, KMSCON_VT_NEW, app->vt_eloop); if (ret) goto err_app; ret = kmscon_ui_new(&app->ui, app->eloop, app->video, app->input); if (ret) goto err_app; return 0; err_app: destroy_app(app); return ret; }
static int setup_app(struct uvtd_app *app) { int ret, fd; shl_dlist_init(&app->seats); ret = ev_eloop_new(&app->eloop, log_llog, NULL); if (ret) { log_error("cannot create eloop object: %d", ret); goto err_app; } ret = ev_eloop_register_signal_cb(app->eloop, SIGTERM, app_sig_generic, app); if (ret) { log_error("cannot register SIGTERM signal handler: %d", ret); goto err_app; } ret = ev_eloop_register_signal_cb(app->eloop, SIGINT, app_sig_generic, app); if (ret) { log_error("cannot register SIGINT signal handler: %d", ret); goto err_app; } ret = ev_eloop_register_signal_cb(app->eloop, SIGPIPE, app_sig_ignore, app); if (ret) { log_error("cannot register SIGPIPE signal handler: %d", ret); goto err_app; } ret = uterm_monitor_new(&app->mon, app->eloop, app_monitor_event, app); if (ret) { log_error("cannot create device monitor: %d", ret); goto err_app; } ret = uvt_ctx_new(&app->ctx, log_llog, NULL); if (ret) { log_error("cannot create UVT context: %d", ret); goto err_app; } fd = uvt_ctx_get_fd(app->ctx); if (fd >= 0) { ret = ev_eloop_new_fd(app->eloop, &app->ctx_fd, fd, EV_READABLE, app_ctx_event, app); if (ret) { log_error("cannot create UVT ctx efd: %d", ret); goto err_app; } } log_debug("scanning for devices..."); uterm_monitor_scan(app->mon); return 0; err_app: destroy_app(app); return ret; }
int main(int argc, char *argv[]) { static char report[1024]; printf("PJSIP Performance Measurement Tool v%s\n" "(c)2006 pjsip.org\n\n", PJ_VERSION); if (create_app() != 0) return 1; if (init_options(argc, argv) != 0) return 1; if (init_sip() != 0) return 1; if (init_media() != 0) return 1; pj_log_set_level(app.log_level); if (app.log_level > 4) { pjsip_endpt_register_module(app.sip_endpt, &msg_logger); } /* Misc infos */ if (app.client.dst_uri.slen != 0) { if (app.client.method.id == PJSIP_INVITE_METHOD) { if (app.client.stateless) { PJ_LOG(3,(THIS_FILE, "Info: --stateless option makes no sense for INVITE," " ignored.")); } } } if (app.client.dst_uri.slen) { /* Client mode */ pj_status_t status; char test_type[64]; unsigned msec_req, msec_res; unsigned i; /* Get the job name */ if (app.client.method.id == PJSIP_INVITE_METHOD) { pj_ansi_strcpy(test_type, "INVITE calls"); } else if (app.client.stateless) { pj_ansi_sprintf(test_type, "stateless %.*s requests", (int)app.client.method.name.slen, app.client.method.name.ptr); } else { pj_ansi_sprintf(test_type, "stateful %.*s requests", (int)app.client.method.name.slen, app.client.method.name.ptr); } printf("Sending %d %s to '%.*s' with %d maximum outstanding jobs, please wait..\n", app.client.job_count, test_type, (int)app.client.dst_uri.slen, app.client.dst_uri.ptr, app.client.job_window); for (i=0; i<app.thread_count; ++i) { status = pj_thread_create(app.pool, NULL, &client_thread, (void*)(long)i, 0, 0, &app.thread[i]); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to create thread", status); return 1; } } for (i=0; i<app.thread_count; ++i) { pj_thread_join(app.thread[i]); app.thread[i] = NULL; } if (app.client.last_completion.sec) { pj_time_val duration; duration = app.client.last_completion; PJ_TIME_VAL_SUB(duration, app.client.first_request); msec_res = PJ_TIME_VAL_MSEC(duration); } else { msec_res = app.client.timeout * 1000; } if (msec_res == 0) msec_res = 1; if (app.client.requests_sent.sec) { pj_time_val duration; duration = app.client.requests_sent; PJ_TIME_VAL_SUB(duration, app.client.first_request); msec_req = PJ_TIME_VAL_MSEC(duration); } else { msec_req = app.client.timeout * 1000; } if (msec_req == 0) msec_req = 1; if (app.client.job_submitted < app.client.job_count) puts("\ntimed-out!\n"); else puts("\ndone.\n"); pj_ansi_snprintf( report, sizeof(report), "Total %d %s sent in %d ms at rate of %d/sec\n" "Total %d responses receieved in %d ms at rate of %d/sec:", app.client.job_submitted, test_type, msec_req, app.client.job_submitted * 1000 / msec_req, app.client.total_responses, msec_res, app.client.total_responses*1000/msec_res); write_report(report); /* Print detailed response code received */ pj_ansi_sprintf(report, "\nDetailed responses received:"); write_report(report); for (i=0; i<PJ_ARRAY_SIZE(app.client.response_codes); ++i) { const pj_str_t *reason; if (app.client.response_codes[i] == 0) continue; reason = pjsip_get_status_text(i); pj_ansi_snprintf( report, sizeof(report), " - %d responses: %7d (%.*s)", i, app.client.response_codes[i], (int)reason->slen, reason->ptr); write_report(report); } /* Total responses and rate */ pj_ansi_snprintf( report, sizeof(report), " ------\n" " TOTAL responses: %7d (rate=%d/sec)\n", app.client.total_responses, app.client.total_responses*1000/msec_res); write_report(report); pj_ansi_sprintf(report, "Maximum outstanding job: %d", app.client.stat_max_window); write_report(report); } else { /* Server mode */ char s[10], *unused; pj_status_t status; unsigned i; puts("pjsip-perf started in server-mode"); printf("Receiving requests on the following URIs:\n" " sip:0@%.*s:%d%s for stateless handling\n" " sip:1@%.*s:%d%s for stateful handling\n" " sip:2@%.*s:%d%s for call handling\n", (int)app.local_addr.slen, app.local_addr.ptr, app.local_port, (app.use_tcp ? ";transport=tcp" : ""), (int)app.local_addr.slen, app.local_addr.ptr, app.local_port, (app.use_tcp ? ";transport=tcp" : ""), (int)app.local_addr.slen, app.local_addr.ptr, app.local_port, (app.use_tcp ? ";transport=tcp" : "")); printf("INVITE with non-matching user part will be handled call-statefully\n"); for (i=0; i<app.thread_count; ++i) { status = pj_thread_create(app.pool, NULL, &server_thread, (void*)(long)i, 0, 0, &app.thread[i]); if (status != PJ_SUCCESS) { app_perror(THIS_FILE, "Unable to create thread", status); return 1; } } puts("\nPress <ENTER> to quit\n"); fflush(stdout); unused = fgets(s, sizeof(s), stdin); PJ_UNUSED_ARG(unused); app.thread_quit = PJ_TRUE; for (i=0; i<app.thread_count; ++i) { pj_thread_join(app.thread[i]); app.thread[i] = NULL; } puts(""); } destroy_app(); return 0; }