void gtk_debugger_close (void) { #ifndef NO_GDB // hide all windows gdbtk_hide_insight(); dbg_on = 0; if(options3.dbg_dock) dbgdock_hide_all(!0); else dbgwnds_hide_all(!0); // and restarts the emulator ti68k_bkpt_set_cause(0, 0, 0); dbgbkpts_erase_context(); if (engine_is_stopped()) gdbcall_continue(); #else // hide all windows dbg_on = 0; if(options3.dbg_dock) dbgdock_hide_all(!0); else dbgwnds_hide_all(!0); // and restarts the emulator ti68k_bkpt_set_cause(0, 0, 0); dbgbkpts_erase_context(); engine_start(); #endif }
/* * Driver initialisation at IOC startup (ecAsynInit) * * path - location of Unix Domain Socket, must match the scanner's * max_message - maximum size of messages between scanner and ioc * This must be able to accommodate the configuration * of the chain that is transferred from the scanner to * the ioc. */ static void makePorts(char * path, int max_message) { ENGINE_USER * usr = (ENGINE_USER *)callocMustSucceed (1, sizeof(ENGINE_USER), "can't allocate socket engine private data"); ellInit(&usr->ports); usr->master = new ecMaster((char *)"MASTER0"); ellAdd(&usr->ports, &usr->master->node); usr->config_ready = rtMessageQueueCreate(1, sizeof(int)); // TODO - no assert for runtime errors, so what should we use to throw? assert(usr->config_ready != NULL); usr->config = (EC_CONFIG *)callocMustSucceed (1, sizeof(EC_CONFIG), "can't allocate chain config lists"); usr->writeq = rtMessageQueueCreate(1, max_message); assert(usr->writeq != NULL); ENGINE * engine = new_engine(max_message); engine->path = strdup(path); engine->connect = client_connect; engine->on_connect = receive_config_on_connect; engine->send_message = ioc_send; engine->receive_message = ioc_receive; engine->usr = usr; engine_start(engine); new_timer(1000000000, usr->writeq, 0, MSG_HEARTBEAT); int ack; rtMessageQueueReceive(usr->config_ready, &ack, sizeof(int)); }
bool TiEmuDCOP::send_file(QString filename) { if (img_loaded && !engine_is_stopped()) { engine_stop(); fs_send_file(filename.local8Bit()); engine_start(); return true; } else return false; }
bool TiEmuDCOP::enter_debugger() { if (img_loaded && !engine_is_stopped()) { engine_stop(); ti68k_debug_break(); engine_start(); return true; } else return false; }
bool TiEmuDCOP::send_files(QStringList filenames) { if (img_loaded && !engine_is_stopped()) { engine_stop(); for (QStringList::Iterator it = filenames.begin(); it != filenames.end(); ++it) fs_send_file((*it).local8Bit()); engine_start(); return true; } else return false; }
bool TiEmuDCOP::turn_calc_on() { if (img_loaded && !engine_is_stopped()) { engine_stop(); hw_m68k_irq(6); while (ti68k_debug_is_supervisor()) hw_m68k_run(1,0); engine_start(); return true; } else return false; }
int main() { engine_init( 800, 600, "Snake", 100); engine_start(); engine_destroy(); }
bool TiEmuDCOP::reset_calc(bool clearram) { if (img_loaded) { engine_stop(); if(clearram) std::memset(tihw.ram, 0, tihw.ram_size); ti68k_reset(); if (dbg_on) close_debugger_async(); else engine_start(); return true; } else return false; }
static VALUE roscil_pulse(VALUE obj, VALUE freq) { PaStreamParameters *sp; int i; waveData *dp; Need_Float(freq); dp = (waveData *)malloc(sizeof(waveData)); set_pulse_data(dp); dp->freq = NUM2DBL(freq); sp = (PaStreamParameters *)malloc(sizeof(PaStreamParameters)); sp->hostApiSpecificStreamInfo = NULL; engine_start(sp); engine_play(sp, dp); engine_end(); }
GLADE_CB void on_dockmode1_activate (GtkMenuItem *menu_item, gpointer user_data) { msg_box1(_("Warning"), _("TiEmu is about to restart...")); #ifndef NO_GDB // In GDB mode, we have to restart the engine here, otherwise // gtk_debugger_close will call gdbcall_continue to do so and never // return. engine_start(); #endif gtk_debugger_close(); // Stop the engine before calling gtk_main_quit. // Otherwise, it will keep running even when it is supposed to have // been stopped by the debugger. engine_stop(); if(options3.dbg_dock) gtk_widget_destroy(dbgw.dock); options3.dbg_dock = GTK_CHECK_MENU_ITEM(menu_item)->active; gtk_main_quit(); }
int main(int argc, char **argv) { struct engine *engine = NULL; Display *dpy; int num; XSetWindowAttributes attr; unsigned long mask; Window root; Window win; XVisualInfo *info = NULL; GLXContext ctx = NULL; int conf[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, GL_FALSE, GLX_DEPTH_SIZE, 1, None, }; dpy = XOpenDisplay(NULL); if (!dpy) { _err("failed to open X display\n"); return 1; } num = DefaultScreen(dpy); _inf("use GLX_SGIX_pbuffer on screen %d\n", num); root = RootWindow(dpy, num); info = glXChooseVisual(dpy, num, conf); if (!info) { _err("glXChooseVisual() failed\n"); goto out; } /* window attributes */ attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, info->visual, AllocNone); attr.event_mask = ButtonPressMask | ExposureMask | KeyPressMask; mask = CWBorderPixel | CWColormap | CWEventMask; win = XCreateWindow(dpy, root, 0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, 0, info->depth, InputOutput, info->visual, mask, &attr); ctx = glXCreateContext(dpy, info, NULL, GL_TRUE); if (!ctx) { _err("glXCreateContext() failed\n"); goto out; } XFree(info); info = NULL; XMapWindow(dpy, win); _msg("call glXMakeCurrent()\n"); glXMakeCurrent(dpy, win, ctx); _inf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); _inf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); _inf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); _inf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); _inf("GL_SHADING_LANGUAGE_VERSION = %s\n", (char *) glGetString(GL_SHADING_LANGUAGE_VERSION)); _msg("clear window\n"); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); glXSwapBuffers(dpy, win); _msg("init engine\n"); if (engine_init(&engine, argc, argv) < 0) { _err("engine_init() failed\n"); goto out; } _msg("start engine\n"); engine_start(engine); glXSwapBuffers(dpy, win); engine_stop(engine); event_loop(dpy); _msg("exit engine\n"); engine_exit(&engine); out: glXMakeCurrent(dpy, 0, 0); if (info) XFree(info); if (ctx) glXDestroyContext(dpy, ctx); XDestroyWindow(dpy, win); XCloseDisplay(dpy); return 0; }
int main(int argc, char **argv) { int forks = 1; array_t(char*) addr_set; array_init(addr_set); char *keyfile = NULL; const char *config = NULL; char *keyfile_buf = NULL; /* Long options. */ int c = 0, li = 0, ret = 0; struct option opts[] = { {"addr", required_argument, 0, 'a'}, {"config", required_argument, 0, 'c'}, {"keyfile",required_argument, 0, 'k'}, {"forks",required_argument, 0, 'f'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; while ((c = getopt_long(argc, argv, "a:c:f:k:vVh", opts, &li)) != -1) { switch (c) { case 'a': array_push(addr_set, optarg); break; case 'c': config = optarg; break; case 'f': g_interactive = 0; forks = atoi(optarg); if (forks == 0) { kr_log_error("[system] error '-f' requires number, not '%s'\n", optarg); return EXIT_FAILURE; } #if (!defined(UV_VERSION_HEX)) || (!defined(SO_REUSEPORT)) if (forks > 1) { kr_log_error("[system] libuv 1.7+ is required for SO_REUSEPORT support, multiple forks not supported\n"); return EXIT_FAILURE; } #endif break; case 'k': keyfile_buf = malloc(PATH_MAX); assert(keyfile_buf); /* Check if the path is absolute */ if (optarg[0] == '/') { keyfile = strdup(optarg); } else { /* Construct absolute path, the file may not exist */ keyfile = realpath(".", keyfile_buf); if (keyfile) { int len = strlen(keyfile); int namelen = strlen(optarg); if (len + namelen < PATH_MAX - 1) { keyfile[len] = '/'; memcpy(keyfile + len + 1, optarg, namelen + 1); keyfile = strdup(keyfile); /* Duplicate */ } else { keyfile = NULL; /* Invalidate */ } } } free(keyfile_buf); if (!keyfile) { kr_log_error("[system] keyfile '%s': not writeable\n", optarg); return EXIT_FAILURE; } break; case 'v': kr_debug_set(true); break; case 'V': kr_log_info("%s, version %s\n", "Knot DNS Resolver", PACKAGE_VERSION); return EXIT_SUCCESS; case 'h': case '?': help(argc, argv); return EXIT_SUCCESS; default: help(argc, argv); return EXIT_FAILURE; } } /* Switch to rundir. */ if (optind < argc) { const char *rundir = argv[optind]; if (access(rundir, W_OK) != 0) { kr_log_error("[system] rundir '%s': %s\n", rundir, strerror(errno)); return EXIT_FAILURE; } ret = chdir(rundir); if (ret != 0) { kr_log_error("[system] rundir '%s': %s\n", rundir, strerror(errno)); return EXIT_FAILURE; } if(config && access(config, R_OK) != 0) { kr_log_error("[system] rundir '%s'\n", rundir); kr_log_error("[system] config '%s': %s\n", config, strerror(errno)); return EXIT_FAILURE; } } kr_crypto_init(); /* Fork subprocesses if requested */ int fork_count = forks; while (--forks > 0) { int pid = fork(); if (pid < 0) { perror("[system] fork"); return EXIT_FAILURE; } /* Forked process */ if (pid == 0) { kr_crypto_reinit(); break; } } /* Block signals. */ uv_loop_t *loop = uv_default_loop(); uv_signal_t sigint, sigterm; uv_signal_init(loop, &sigint); uv_signal_init(loop, &sigterm); uv_signal_start(&sigint, signal_handler, SIGINT); uv_signal_start(&sigterm, signal_handler, SIGTERM); /* Create a server engine. */ knot_mm_t pool = { .ctx = mp_new (4096), .alloc = (knot_mm_alloc_t) mp_alloc }; struct engine engine; ret = engine_init(&engine, &pool); if (ret != 0) { kr_log_error("[system] failed to initialize engine: %s\n", kr_strerror(ret)); return EXIT_FAILURE; } /* Create worker */ struct worker_ctx *worker = init_worker(loop, &engine, &pool, forks, fork_count); if (!worker) { kr_log_error("[system] not enough memory\n"); return EXIT_FAILURE; } /* Bind to sockets and run */ for (size_t i = 0; i < addr_set.len; ++i) { int port = 53; const char *addr = set_addr(addr_set.at[i], &port); ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP); if (ret != 0) { kr_log_error("[system] bind to '%s#%d' %s\n", addr, port, knot_strerror(ret)); ret = EXIT_FAILURE; } } /* Start the scripting engine */ if (ret == 0) { ret = engine_start(&engine, config ? config : "config"); if (ret == 0) { if (keyfile) { auto_free char *cmd = afmt("trust_anchors.file = '%s'", keyfile); if (!cmd) { kr_log_error("[system] not enough memory\n"); return EXIT_FAILURE; } engine_cmd(&engine, cmd); lua_settop(engine.L, 0); } /* Run the event loop */ ret = run_worker(loop, &engine); } } /* Cleanup. */ array_clear(addr_set); engine_deinit(&engine); worker_reclaim(worker); mp_delete(pool.ctx); if (ret != 0) { ret = EXIT_FAILURE; } kr_crypto_cleanup(); return ret; }
/** * Main. start engine and run it. * */ int main(int argc, char* argv[]) { int c; int options_index = 0; int info = 0; int single_run = 0; int daemonize = 1; int cmdline_verbosity = 0; const char* cfgfile = ODS_SE_CFGFILE; static struct option long_options[] = { {"single-run", no_argument, 0, '1'}, {"config", required_argument, 0, 'c'}, {"no-daemon", no_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {"info", no_argument, 0, 'i'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, { 0, 0, 0, 0} }; /* parse the commandline */ while ((c=getopt_long(argc, argv, "1c:dhivV", long_options, &options_index)) != -1) { switch (c) { case '1': single_run = 1; break; case 'c': cfgfile = optarg; break; case 'd': daemonize = 0; break; case 'h': usage(stdout); exit(0); break; case 'i': info = 1; break; case 'v': cmdline_verbosity++; break; case 'V': version(stdout); exit(0); break; default: usage(stderr); exit(2); break; } } argc -= optind; argv += optind; if (argc != 0) { usage(stderr); exit(2); } #ifdef ENFORCER_TIMESHIFT if (getenv("ENFORCER_TIMESHIFT")) { fprintf(stdout, "WARNING: timeshift %s detected, running once only\n", getenv("ENFORCER_TIMESHIFT")); single_run = 1; } else { fprintf(stdout, "DEBUG: timeshift mode enabled, but not set.\n"); } #endif /* ENFORCER_TIMESHIFT */ /* main stuff */ fprintf(stdout, "OpenDNSSEC signer engine version %s\n", PACKAGE_VERSION); engine_start(cfgfile, cmdline_verbosity, daemonize, info, single_run); /* done */ return 0; }