/* * Prepare task execution. */ EXPORT void make_dormant( TCB *tcb ) { /* Initialize variables which should be reset at DORMANT state */ tcb->state = TS_DORMANT; tcb->priority = tcb->bpriority = tcb->ipriority; tcb->sysmode = tcb->isysmode; tcb->wupcnt = 0; tcb->suscnt = 0; tcb->waitmask = 0; tcb->nodiswai = FALSE; tcb->klockwait = FALSE; tcb->klocked = FALSE; tcb->slicetime = 0; tcb->stime = 0; tcb->utime = 0; #ifdef NUM_MTXID tcb->mtxlist = NULL; #endif tcb->tskevt = 0; tcb->reqdct = 0; /* clear DCT request */ tcb->texhdr = NULL; /* Undefined task exception handler */ tcb->texmask = 0; tcb->pendtex = 0; tcb->exectex = 0; tcb->texflg = 0; tcb->execssid = 0; /* Set context to start task */ setup_context(tcb); }
void mono_ppc_throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, mgreg_t *int_regs, gdouble *fp_regs, gboolean rethrow) { MonoError error; MonoContext ctx; /* adjust eip so that it point into the call instruction */ eip -= 4; setup_context (&ctx); /*printf ("stack in throw: %p\n", esp);*/ MONO_CONTEXT_SET_BP (&ctx, esp); MONO_CONTEXT_SET_IP (&ctx, eip); memcpy (&ctx.regs, int_regs, sizeof (mgreg_t) * MONO_MAX_IREGS); memcpy (&ctx.fregs, fp_regs, sizeof (double) * MONO_MAX_FREGS); if (mono_object_isinst_checked (exc, mono_defaults.exception_class, &error)) { MonoException *mono_ex = (MonoException*)exc; if (!rethrow) { mono_ex->stack_trace = NULL; mono_ex->trace_ips = NULL; } } mono_error_assert_ok (&error); mono_handle_exception (&ctx, exc); mono_restore_context (&ctx); g_assert_not_reached (); }
void setup_globals(pmOptions *opts) { pmID pmids[HOST_NMETRICS]; pmDesc descs[HOST_NMETRICS]; pmResult *result; setup_context(opts); setup_metrics(hostmetrics, &pmids[0], &descs[0], HOST_NMETRICS); fetch_metrics("host", HOST_NMETRICS, pmids, &result); if (HOST_NMETRICS != result->numpmid) { fprintf(stderr, "%s: pmFetch failed to fetch initial metric value(s)\n", pmProgname); cleanstop(1); } hertz = extract_integer(result, descs, HOST_HERTZ); pagesize = extract_integer(result, descs, HOST_PAGESIZE); extract_string(result, descs, HOST_RELEASE, sysname.release, sizeof(sysname.release)); extract_string(result, descs, HOST_VERSION, sysname.version, sizeof(sysname.version)); extract_string(result, descs, HOST_MACHINE, sysname.machine, sizeof(sysname.machine)); extract_string(result, descs, HOST_NODENAME, sysname.nodename, sizeof(sysname.nodename)); nodenamelen = strlen(sysname.nodename); pmFreeResult(result); }
static void on_connection(pa_socket_client *client, pa_iochannel*io, void *userdata) { pa_context *c = userdata; int saved_errno = errno; pa_assert(client); pa_assert(c); pa_assert(c->state == PA_CONTEXT_CONNECTING); pa_context_ref(c); pa_socket_client_unref(client); c->client = NULL; if (!io) { /* Try the next item in the list */ if (saved_errno == ECONNREFUSED || saved_errno == ETIMEDOUT || saved_errno == EHOSTUNREACH) { try_next_connection(c); goto finish; } pa_context_fail(c, PA_ERR_CONNECTIONREFUSED); goto finish; } setup_context(c, io); finish: pa_context_unref(c); }
Thread::Thread(Thread_Function _tf, char * _stack, unsigned int _stack_size) { /* Construct a new thread and initialize its stack. The thread is then ready to run. (The dispatcher is implemented in file "thread_scheduler".) */ /* -- INITIALIZE THREAD */ /* ---- THREAD ID */ thread_id = nextFreePid++; /* ---- STACK POINTER */ esp = (char*)((unsigned int)_stack + _stack_size); /* RECALL: The stack starts at the end of the reserved stack memory area. */ stack = _stack; stack_size = _stack_size; /* Assign the next thread pointer to zero initially */ next_thread = 0; /* -- INITIALIZE THE STACK OF THE THREAD */ setup_context(_tf); }
void init_processes() { int i; #ifdef _TEST_ proc_member test; for (i = 0; i < NUM_TEST_PROCS; i++) { test.function = g_test_proc[i].entry; test.pid = (int) g_test_proc[i].pid; test.priority = (signed int) g_test_proc[i].priority; test.stack_size = g_test_proc[i].sz_stack; test.procType = USER_PROC; setup_context(&test); } #endif for (i = 0; i < sizeof(proc_array) / sizeof(proc_member); i++) { setup_context(&proc_array[i]); } }
/** @brief Initializes ViennaCL with an already existing context * * @param i ID of the context to be set up * @param c The OpenCL handle of the existing context * @param devices A vector of OpenCL device-IDs that should be added to the context * @param queue One queue per device */ static void setup_context(long i, cl_context c, std::vector<cl_device_id> const & devices, std::vector<cl_command_queue> const & queue) { assert(devices.size() == queue.size() && bool("ViennaCL expects one queue per device!")); //wrap queue vector into map std::map< cl_device_id, std::vector<cl_command_queue> > queues_map; for (vcl_size_t j = 0; j<devices.size(); ++j) queues_map[devices[j]].push_back(queue[j]); setup_context(i, c, devices, queues_map); }
PRIVATE void allocate_stack(thread_no_t task_no, thread_no_t maxtasks) /* create space on stack for threads from task_no to maxtasks */ { char space[STACK_SPACE]; /* essential stack allocation*/ if (task_no >= maxtasks) longjmp(home, 1); /* all threads are created*/ #if DEBUG_LEVEL printf("Thread %d stack begins after %p\n", task_no, &space[STACK_SPACE]); #endif setup_context(task_no, maxtasks); }
int main(int argc, char* argv[]) { gtk_init(&argc, &argv); display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); rand = g_rand_new(); g_width = 400; g_height = 300; if (setup_context() != 0) return -1; ref = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(ref), g_width, g_height); g_object_connect(ref, "signal::draw", on_ref_draw, NULL, "signal::configure-event", on_ref_configure, NULL, "signal::map-event", on_ref_mapped, NULL, "signal::delete-event", on_deleted, NULL, NULL); gtk_widget_show_all(ref); top = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(top), g_width, g_height); gtk_widget_set_app_paintable(top, TRUE); gtk_widget_set_double_buffered(top, FALSE); g_object_connect(top, "signal::draw", on_draw, NULL, "signal::delete-event", on_deleted, NULL, NULL); gtk_widget_show_all(top); GdkWindow* gdkwin = gtk_widget_get_window(top); glxwin = glXCreateWindow(display, bestFbc, GDK_WINDOW_XID(gdkwin), NULL); g_timeout_add(1000, on_timeout, NULL); gtk_main(); if (glx_pm) { glXDestroyPixmap(display, glx_pm); XFreePixmap(display, back_pixmap); } glXDestroyContext(ctx); g_rand_free(rand); }
static void cgreg_notify(GAtResult *result, gpointer user_data) { int status, lac, ci, tech; if (state != STATE_ATTACHING) return; if (at_util_parse_reg_unsolicited(result, "+CGREG:", &status, &lac, &ci, &tech) == FALSE) return; if (status != 1 && status != 5) return; setup_context(status); }
static PyObject * do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level) { PyObject *filename, *module, *registry, *res; int lineno; if (!setup_context(stack_level, &filename, &lineno, &module, ®istry)) return NULL; res = warn_explicit(category, message, filename, lineno, module, registry, NULL); Py_DECREF(filename); Py_DECREF(registry); Py_DECREF(module); return res; }
static void cgreg_cb(gboolean ok, GAtResult *result, gpointer user_data) { int status, lac, ci, tech; if (!ok) return; if (at_util_parse_reg(result, "+CGREG:", NULL, &status, &lac, &ci, &tech) == FALSE) return; if (status != 1 && status != 5) { g_at_chat_register(control, "+CGREG:", cgreg_notify, FALSE, NULL, NULL); return; } setup_context(status); }
static void init_context(void) { cl_int err; cl_uint n; cl_platform_id *plats; cl_context_properties props[3]; cl_context c; if (ctx != NULL) return; err = clGetPlatformIDs(0, NULL, &n); if (err != CL_SUCCESS) return; plats = (cl_platform_id *)calloc(n, sizeof(cl_platform_id)); if (plats == NULL) return; err = clGetPlatformIDs(n, plats, NULL); if (err != CL_SUCCESS) goto fail_id; props[0] = CL_CONTEXT_PLATFORM; props[1] = (cl_context_properties)plats[0]; props[2] = 0; c = clCreateContextFromType(props, CL_DEVICE_TYPE_GPU, NULL, NULL, &err); if (err != CL_SUCCESS) { fprintf(stderr, "Could not create context, will fail later (%d)!\n", err); /* error - error - error */ /* but we do nothing */ goto fail_id; } free(plats); setup_context(c); clReleaseContext(c); return; fail_id: free(plats); }
int main (int argc, char **argv) { /* Setup locale */ setlocale (LC_ALL, ""); /* Setup context */ if (!setup_context (argc, argv)) { g_printerr ("Context setup failed... exiting\n"); return -1; } /* Either text or file must be given */ if (filename == NULL && text == NULL) { g_printerr ("Either 'file' or 'text' options should be used\n" "Run '%s --help' to see a full list of available " "command line options.\n", argv[0]); return -2; } /* If required, load file contents */ if (filename != NULL && !load_file_contents ()) { g_printerr ("Loading file '%s' contents failed... exiting\n", filename); return -3; } /* Run the parsing! */ if (!run_parsing ()) { g_printerr ("Parsing operation failed... exiting\n"); return -4; } /* Clean exit */ if (filename) g_free (text); return 0; }
static void throw_exception (MonoObject *exc, unsigned long eip, unsigned long esp, gboolean rethrow) { static void (*restore_context) (MonoContext *); MonoContext ctx; #ifdef DEBUG_EXCEPTIONS g_print ("throw_exception: exc=%p eip=%p esp=%p rethrow=%d\n", exc, (void *)eip, (void *) esp, rethrow); #endif if (!restore_context) restore_context = mono_get_restore_context (); /* adjust eip so that it point into the call instruction */ eip -= 8; setup_context (&ctx); /*g_print ("stack in throw: %p\n", esp);*/ memcpy (&ctx.sc_regs, (void *)(esp + MIPS_STACK_PARAM_OFFSET), sizeof (gulong) * MONO_SAVED_GREGS); memset (&ctx.sc_fpregs, 0, sizeof (mips_freg) * MONO_SAVED_FREGS); MONO_CONTEXT_SET_IP (&ctx, eip); if (mono_object_isinst (exc, mono_defaults.exception_class)) { MonoException *mono_ex = (MonoException*)exc; if (!rethrow) mono_ex->stack_trace = NULL; } mono_handle_exception (&ctx, exc, (void *)eip, FALSE); #ifdef DEBUG_EXCEPTIONS g_print ("throw_exception: restore to pc=%p sp=%p fp=%p ctx=%p\n", (void *) ctx.sc_pc, (void *) ctx.sc_regs[mips_sp], (void *) ctx.sc_regs[mips_fp], &ctx); #endif restore_context (&ctx); g_assert_not_reached (); }
void main_init() { context = setup_context(); }
/* * mono_arch_unwind_frame: * * See exceptions-amd64.c for docs. */ gboolean mono_arch_unwind_frame (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *ji, MonoContext *ctx, MonoContext *new_ctx, MonoLMF **lmf, mgreg_t **save_locations, StackFrameInfo *frame) { gpointer ip = MONO_CONTEXT_GET_IP (ctx); MonoPPCStackFrame *sframe; memset (frame, 0, sizeof (StackFrameInfo)); frame->ji = ji; *new_ctx = *ctx; setup_context (new_ctx); if (ji != NULL) { int i; mgreg_t regs [ppc_lr + 1]; guint8 *cfa; guint32 unwind_info_len; guint8 *unwind_info; if (ji->is_trampoline) frame->type = FRAME_TYPE_TRAMPOLINE; else frame->type = FRAME_TYPE_MANAGED; unwind_info = mono_jinfo_get_unwind_info (ji, &unwind_info_len); sframe = (MonoPPCStackFrame*)MONO_CONTEXT_GET_SP (ctx); MONO_CONTEXT_SET_BP (new_ctx, sframe->sp); if (!ji->is_trampoline && jinfo_get_method (ji)->save_lmf) { /* sframe->sp points just past the end of the LMF */ guint8 *lmf_addr = (guint8*)sframe->sp - sizeof (MonoLMF); memcpy (&new_ctx->fregs [MONO_PPC_FIRST_SAVED_FREG], lmf_addr + G_STRUCT_OFFSET (MonoLMF, fregs), sizeof (double) * MONO_SAVED_FREGS); memcpy (&new_ctx->regs [MONO_PPC_FIRST_SAVED_GREG], lmf_addr + G_STRUCT_OFFSET (MonoLMF, iregs), sizeof (mgreg_t) * MONO_SAVED_GREGS); /* the calling IP is in the parent frame */ sframe = (MonoPPCStackFrame*)sframe->sp; /* we substract 4, so that the IP points into the call instruction */ MONO_CONTEXT_SET_IP (new_ctx, sframe->lr - 4); } else { regs [ppc_lr] = ctx->sc_ir; regs [ppc_sp] = ctx->sc_sp; for (i = MONO_PPC_FIRST_SAVED_GREG; i < MONO_MAX_IREGS; ++i) regs [i] = ctx->regs [i]; mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start, (guint8*)ji->code_start + ji->code_size, ip, NULL, regs, ppc_lr + 1, save_locations, MONO_MAX_IREGS, &cfa); /* we substract 4, so that the IP points into the call instruction */ MONO_CONTEXT_SET_IP (new_ctx, regs [ppc_lr] - 4); MONO_CONTEXT_SET_BP (new_ctx, cfa); for (i = MONO_PPC_FIRST_SAVED_GREG; i < MONO_MAX_IREGS; ++i) new_ctx->regs [i] = regs [i]; } return TRUE; } else if (*lmf) { if ((ji = mini_jit_info_table_find (domain, (gpointer)(*lmf)->eip, NULL))) { } else { if (!(*lmf)->method) return FALSE; /* Trampoline lmf frame */ frame->method = (*lmf)->method; } /*sframe = (MonoPPCStackFrame*)MONO_CONTEXT_GET_SP (ctx); MONO_CONTEXT_SET_BP (new_ctx, sframe->sp); MONO_CONTEXT_SET_IP (new_ctx, sframe->lr);*/ MONO_CONTEXT_SET_BP (new_ctx, (*lmf)->ebp); MONO_CONTEXT_SET_IP (new_ctx, (*lmf)->eip); memcpy (&new_ctx->regs [MONO_PPC_FIRST_SAVED_GREG], (*lmf)->iregs, sizeof (mgreg_t) * MONO_SAVED_GREGS); memcpy (&new_ctx->fregs [MONO_PPC_FIRST_SAVED_FREG], (*lmf)->fregs, sizeof (double) * MONO_SAVED_FREGS); frame->ji = ji; frame->type = FRAME_TYPE_MANAGED_TO_NATIVE; /* FIXME: what about trampoline LMF frames? see exceptions-x86.c */ *lmf = (*lmf)->previous_lmf; return TRUE; } return FALSE; }
int main(int argc, char **argv) { int c; int sts; char *endnum; iflag = isatty(0); while ((c = pmgetopt_r(argc, argv, &opts)) != EOF) { switch (c) { case 'D': /* debug flag */ sts = __pmParseDebug(opts.optarg); if (sts < 0) { fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n", pmProgname, opts.optarg); opts.errors++; } else pmDebug |= sts; break; case 'e': /* echo input */ eflag++; break; case 'f': /* skip .dbpmdarc processing */ fflag++; break; case 'i': /* be interactive */ iflag = 1; break; case 'n': /* alternative name space file */ pmnsfile = opts.optarg; break; case 'q': sts = (int)strtol(opts.optarg, &endnum, 10); if (*endnum != '\0' || sts <= 0.0) { pmprintf("%s: -q requires a positive numeric argument\n", pmProgname); opts.errors++; } else { _creds_timeout = sts; } break; case 'U': /* run under alternate user account */ __pmSetProcessIdentity(opts.optarg); break; default: case '?': opts.errors++; break; } } if ((c = argc - opts.optind) > 0) { if (c > 1) opts.errors++; else { /* pid was specified */ if (primary) { pmprintf("%s: you may not specify both -P and a pid\n", pmProgname); opts.errors++; } else { pid = (int)strtol(argv[opts.optind], &endnum, 10); if (*endnum != '\0') { pmprintf("%s: pid must be a numeric process id\n", pmProgname); opts.errors++; } } } } if (opts.errors) { pmUsageMessage(&opts); exit(1); } if (pmnsfile == PM_NS_DEFAULT) { if ((sts = pmLoadNameSpace(pmnsfile)) < 0) { fprintf(stderr, "%s: Cannot load default namespace: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } else { if ((sts = pmLoadASCIINameSpace(pmnsfile, 1)) < 0) { fprintf(stderr, "%s: Cannot load namespace from \"%s\": %s\n", pmProgname, pmnsfile, pmErrStr(sts)); exit(1); } } /* initialize the "fake context" ... */ setup_context(); setlinebuf(stdout); setlinebuf(stderr); #ifdef HAVE_ATEXIT atexit(cleanup); #endif for ( ; ; ) { initmetriclist(); yyparse(); if (yywrap()) { if (iflag) putchar('\n'); break; } __pmSetInternalState(PM_STATE_PMCS); switch (stmt_type) { case OPEN: profile_changed = 1; break; case CLOSE: switch (connmode) { case CONN_DSO: closedso(); break; case CONN_DAEMON: closepmda(); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } connmode = NO_CONN; break; case DESC: switch (connmode) { case CONN_DSO: dodso(PDU_DESC_REQ); break; case CONN_DAEMON: dopmda(PDU_DESC_REQ); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case FETCH: switch (connmode) { case CONN_DSO: dodso(PDU_FETCH); break; case CONN_DAEMON: dopmda(PDU_FETCH); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case INSTANCE: switch (connmode) { case CONN_DSO: dodso(PDU_INSTANCE_REQ); break; case CONN_DAEMON: dopmda(PDU_INSTANCE_REQ); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case STORE: switch (connmode) { case CONN_DSO: dodso(PDU_RESULT); break; case CONN_DAEMON: dopmda(PDU_RESULT); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case HELP: dohelp(param.number, param.pmid); break; case WATCH: break; case DBG: pmDebug = param.number; break; case QUIT: goto done; case STATUS: dostatus(); break; case INFO: switch (connmode) { case CONN_DSO: dodso(PDU_TEXT_REQ); break; case CONN_DAEMON: dopmda(PDU_TEXT_REQ); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case NAMESPACE: if (cmd_namespace != NULL) free(cmd_namespace); cmd_namespace = strdup(param.name); if (cmd_namespace == NULL) { fprintf(stderr, "%s: No memory for new namespace\n", pmProgname); exit(1); } pmUnloadNameSpace(); strcpy(cmd_namespace, param.name); if ((sts = pmLoadASCIINameSpace(cmd_namespace, 1)) < 0) { fprintf(stderr, "%s: Cannot load namespace from \"%s\": %s\n", pmProgname, cmd_namespace, pmErrStr(sts)); pmUnloadNameSpace(); if (pmnsfile == PM_NS_DEFAULT) { fprintf(stderr, "%s: Reload default namespace\n", pmProgname); if ((sts = pmLoadNameSpace(pmnsfile)) < 0) { fprintf(stderr, "%s: Cannot load default namespace: %s\n", pmProgname, pmErrStr(sts)); exit(1); } } else { fprintf(stderr, "%s: Reload namespace from \"%s\"\n", pmProgname, pmnsfile); if ((sts = pmLoadASCIINameSpace(pmnsfile, 1)) < 0) { fprintf(stderr, "%s: Cannot load namespace from \"%s\"" ": %s\n", pmProgname, pmnsfile, pmErrStr(sts)); exit(1); } } } break; case EOL: break; case PMNS_NAME: switch (connmode) { case CONN_DSO: dodso(PDU_PMNS_IDS); break; case CONN_DAEMON: dopmda(PDU_PMNS_IDS); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case PMNS_PMID: switch (connmode) { case CONN_DSO: dodso(PDU_PMNS_NAMES); break; case CONN_DAEMON: dopmda(PDU_PMNS_NAMES); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case PMNS_CHILDREN: switch (connmode) { case CONN_DSO: dodso(PDU_PMNS_CHILD); break; case CONN_DAEMON: dopmda(PDU_PMNS_CHILD); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case PMNS_TRAVERSE: switch (connmode) { case CONN_DSO: dodso(PDU_PMNS_TRAVERSE); break; case CONN_DAEMON: dopmda(PDU_PMNS_TRAVERSE); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; case ATTR: switch (connmode) { case CONN_DSO: dodso(PDU_AUTH); break; case CONN_DAEMON: dopmda(PDU_AUTH); break; case NO_CONN: yywarn("No PMDA currently opened"); break; } break; default: printf("Unexpected result (%d) from parser?\n", stmt_type); break; } __pmSetInternalState(PM_STATE_APPL); } done: cleanup(); exit(0); }
int run_backend(const MythCommandLineParser &cmdline) { if (!setup_context(cmdline)) return GENERIC_EXIT_NO_MYTHCONTEXT; bool ismaster = gCoreContext->IsMasterHost(); if (!UpgradeTVDatabaseSchema(ismaster, ismaster)) { VERBOSE(VB_IMPORTANT, "Couldn't upgrade database to new schema"); return GENERIC_EXIT_DB_OUTOFDATE; } /////////////////////////////////////////// g_pUPnp = new MediaServer(ismaster, !cmdline.IsUPnPEnabled() ); if (!ismaster) { int ret = connect_to_master(); if (ret != GENERIC_EXIT_OK) return ret; } QString myip = gCoreContext->GetSetting("BackendServerIP"); int port = gCoreContext->GetNumSetting("BackendServerPort", 6543); if (myip.isEmpty()) { cerr << "No setting found for this machine's BackendServerIP.\n" << "Please run setup on this machine and modify the first page\n" << "of the general settings.\n"; return GENERIC_EXIT_SETUP_ERROR; } MythSystemEventHandler *sysEventHandler = new MythSystemEventHandler(); if (ismaster) { VERBOSE(VB_GENERAL, LOC + "Starting up as the master server."); gCoreContext->LogEntry("mythbackend", LP_INFO, "MythBackend started as master server", ""); } else { VERBOSE(VB_GENERAL, LOC + "Running as a slave backend."); gCoreContext->LogEntry("mythbackend", LP_INFO, "MythBackend started as a slave backend", ""); } print_warnings(cmdline); bool fatal_error = false; bool runsched = setupTVs(ismaster, fatal_error); if (fatal_error) { delete sysEventHandler; return GENERIC_EXIT_SETUP_ERROR; } if (ismaster) { if (runsched) { sched = new Scheduler(true, &tvList); int err = sched->GetError(); if (err) return err; if (!cmdline.IsSchedulerEnabled()) sched->DisableScheduling(); } if (cmdline.IsHouseKeeperEnabled()) housekeeping = new HouseKeeper(true, ismaster, sched); if (cmdline.IsAutoExpirerEnabled()) { expirer = new AutoExpire(&tvList); if (sched) sched->SetExpirer(expirer); } } else if (cmdline.IsHouseKeeperEnabled()) { housekeeping = new HouseKeeper(true, ismaster, NULL); } if (cmdline.IsJobQueueEnabled()) jobqueue = new JobQueue(ismaster); // Setup status server HttpStatus *httpStatus = NULL; HttpServer *pHS = g_pUPnp->GetHttpServer(); if (pHS) { VERBOSE(VB_IMPORTANT, "Main::Registering HttpStatus Extension"); httpStatus = new HttpStatus(&tvList, sched, expirer, ismaster); if (httpStatus) pHS->RegisterExtension(httpStatus); } VERBOSE(VB_IMPORTANT, QString("Enabled verbose msgs: %1") .arg(verboseString)); MainServer *mainServer = new MainServer( ismaster, port, &tvList, sched, expirer); int exitCode = mainServer->GetExitCode(); if (exitCode != GENERIC_EXIT_OK) { VERBOSE(VB_IMPORTANT, "Backend exiting, MainServer initialization " "error."); delete mainServer; return exitCode; } if (httpStatus && mainServer) httpStatus->SetMainServer(mainServer); StorageGroup::CheckAllStorageGroupDirs(); if (gCoreContext->IsMasterBackend()) SendMythSystemEvent("MASTER_STARTED"); /////////////////////////////// /////////////////////////////// exitCode = qApp->exec(); /////////////////////////////// /////////////////////////////// if (gCoreContext->IsMasterBackend()) { SendMythSystemEvent("MASTER_SHUTDOWN"); qApp->processEvents(); } gCoreContext->LogEntry("mythbackend", LP_INFO, "MythBackend exiting", ""); delete sysEventHandler; delete mainServer; return exitCode; }
int main(int argc, char **argv) { krb5_error_code ret; int optidx = 0; int i; krb5_keytab keytab; krb5_socket_t sfd = rk_INVALID_SOCKET; setprogname(argv[0]); ret = krb5_init_context(&context); if (ret) errx (1, "krb5_init_context failed: %d", ret); if (getarg(args, num_args, argc, argv, &optidx)) { warnx("error at argument `%s'", argv[optidx]); usage(1); } if (help_flag) usage (0); if (version_flag) { print_version(NULL); exit(0); } setup_context(context); /* * Now, do the same for the gssapi thread we are going to be running in */ { krb5_context gssctx; ret = _gsskrb5_init(&gssctx); if (ret) errx(1, "failed to setup gssapi context"); setup_context(gssctx); krb5_gss_register_acceptor_identity("HDB:"); } ret = krb5_kt_resolve(context, keytab_str, &keytab); if(ret) krb5_err(context, 1, ret, "krb5_kt_resolve"); kadm5_setup_passwd_quality_check (context, check_library, check_function); for (i = 0; i < policy_libraries.num_strings; i++) { ret = kadm5_add_passwd_quality_verifier(context, policy_libraries.strings[i]); if (ret) krb5_err(context, 1, ret, "kadm5_add_passwd_quality_verifier"); } ret = kadm5_add_passwd_quality_verifier(context, NULL); if (ret) krb5_err(context, 1, ret, "kadm5_add_passwd_quality_verifier"); #ifdef ___APPLE__ if (sandbox_flag) { char *errorstring; ret = sandbox_init("kadmind", SANDBOX_NAMED, &errorstring); if (ret) errx(1, "sandbox_init failed: %d: %s", ret, errorstring); } #endif if(debug_flag) { int debug_port; if(port_str == NULL) debug_port = krb5_getportbyname (context, "kerberos-adm", "tcp", 749); else debug_port = htons(atoi(port_str)); mini_inetd(debug_port, &sfd); } else { #ifdef _WIN32 pidfile(NULL); start_server(context, port_str); #else struct sockaddr_storage __ss; struct sockaddr *sa = (struct sockaddr *)&__ss; socklen_t sa_size = sizeof(__ss); /* * Check if we are running inside inetd or not, if not, start * our own server. */ if(roken_getsockname(STDIN_FILENO, sa, &sa_size) < 0 && rk_SOCK_ERRNO == ENOTSOCK) { pidfile(NULL); start_server(context, port_str); } #endif /* _WIN32 */ sfd = STDIN_FILENO; } if(realm) krb5_set_default_realm(context, realm); /* XXX */ kadmind_loop(context, keytab, sfd); return 0; }
int main(int argc, char** argv) { setup_context(); float points[] = { -0.5, -0.5, 0, 0.5, -0.5, 0, 0, 0.5, 0 }; //no error checking done for any of this except shader compilation GLuint program = load_shader_pair(vs_shader_str, fs_shader_str); if (!program) { printf("failed to compile/link shaders\n"); exit(0); } glUseProgram(program); float Red[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; int loc = glGetUniformLocation(program, "color"); glUniform4fv(loc, 1, Red); //no default vao in core profile ... GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); GLuint triangle; glGenBuffers(1, &triangle); glBindBuffer(GL_ARRAY_BUFFER, triangle); glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); unsigned int old_time = 0, new_time=0, counter = 0; while (1) { if (handle_events()) break; counter++; new_time = SDL_GetTicks(); if (new_time - old_time > 3000) { printf("%f FPS\n", counter*1000.f/(new_time-old_time)); fflush(stdout); //stupid windows doesn't flush with \n >:-/ old_time = new_time; counter = 0; } glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); SDL_GL_SwapWindow(window); } glDeleteBuffers(1, &triangle); glDeleteProgram(program); cleanup(); return 0; }
int main(int argc, char** argv) { status_t status = init_timers(); if (status < B_OK) { fprintf(stderr, "tcp_tester: Could not initialize timers: %s\n", strerror(status)); return 1; } _add_builtin_module((module_info*)&gNetStackModule); _add_builtin_module((module_info*)&gNetBufferModule); _add_builtin_module((module_info*)&gNetSocketModule); _add_builtin_module((module_info*)&gNetDatalinkModule); _add_builtin_module(modules[0]); if (_get_builtin_dependencies() < B_OK) { fprintf(stderr, "tcp_tester: Could not initialize modules: %s\n", strerror(status)); return 1; } sockaddr_in interfaceAddress; interfaceAddress.sin_len = sizeof(sockaddr_in); interfaceAddress.sin_family = AF_INET; interfaceAddress.sin_addr.s_addr = htonl(0xc0a80001); gInterface.address = (sockaddr*)&interfaceAddress; gInterface.domain = &sDomain; status = get_module("network/protocols/tcp/v1", (module_info **)&gTCPModule); if (status < B_OK) { fprintf(stderr, "tcp_tester: Could not open TCP module: %s\n", strerror(status)); return 1; } net_protocol* client = init_protocol(&gClientSocket); if (client == NULL) return 1; net_protocol* server = init_protocol(&gServerSocket); if (server == NULL) return 1; setup_context(sClientContext, false); setup_context(sServerContext, true); printf("*** Server: %p (%ld), Client: %p (%ld)\n", server, sServerContext.thread, client, sClientContext.thread); setup_server(); while (true) { printf("> "); fflush(stdout); char line[1024]; if (fgets(line, sizeof(line), stdin) == NULL) break; argc = 0; argv = build_argv(line, &argc); if (argv == NULL || argc == 0) continue; int length = strlen(argv[0]); #if 0 char *newLine = strchr(line, '\n'); if (newLine != NULL) newLine[0] = '\0'; #endif if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit") || !strcmp(argv[0], "q")) break; bool found = false; for (cmd_entry* command = sBuiltinCommands; command->name != NULL; command++) { if (!strncmp(command->name, argv[0], length)) { command->func(argc, argv); found = true; break; } } if (!found) fprintf(stderr, "Unknown command \"%s\". Type \"help\" for a list of commands.\n", argv[0]); free(argv); } close_protocol(client); close_protocol(server); snooze(2000000); cleanup_context(sClientContext); cleanup_context(sServerContext); put_module("network/protocols/tcp/v1"); uninit_timers(); return 0; }
ProtocolError DTLSMessageChannel::establish(uint32_t& flags, uint32_t app_state_crc) { int ret = 0; INFO("establish"); ProtocolError error = setup_context(); if (error) { INFO("setup_contex error %x", error); return error; } bool renegotiate = false; SessionPersist::RestoreStatus restoreStatus = sessionPersist.restore(&ssl_context, renegotiate, keys_checksum, coap_state, callbacks.restore); DEBUG("restoreStatus = %d", restoreStatus); if (restoreStatus==SessionPersist::COMPLETE) { DEBUG("out_ctr %d,%d,%d,%d,%d,%d,%d,%d, next_coap_id=%d", sessionPersist.out_ctr[0], sessionPersist.out_ctr[1],sessionPersist.out_ctr[2],sessionPersist.out_ctr[3], sessionPersist.out_ctr[4],sessionPersist.out_ctr[5],sessionPersist.out_ctr[6], sessionPersist.out_ctr[7], sessionPersist.next_coap_id); sessionPersist.make_persistent(); uint32_t actual = sessionPersist.application_state_checksum(this->callbacks.calculate_crc); DEBUG("application state checksum: %x, expected: %x", actual, app_state_crc); if (actual==app_state_crc) { DEBUG("skipping sending hello message"); flags |= Protocol::SKIP_SESSION_RESUME_HELLO; } DEBUG("restored session from persisted session data. next_msg_id=%d", *coap_state); return SESSION_RESUMED; } else if (restoreStatus==SessionPersist::RENEGOTIATE) { // session partially restored, fully restored via handshake } else // no session or clear { reset_session(); ProtocolError error = setup_context(); if (error) return error; } uint8_t random[64]; do { while (ssl_context.state != MBEDTLS_SSL_HANDSHAKE_OVER) { ret = mbedtls_ssl_handshake_step(&ssl_context); if (ret != 0) break; // we've already received the ServerHello, thus // we have the random values for client and server if (ssl_context.state == MBEDTLS_SSL_SERVER_KEY_EXCHANGE) { memcpy(random, ssl_context.handshake->randbytes, 64); } } } while(ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE); if (ret) { DEBUG("handshake failed -%x", -ret); reset_session(); } else { sessionPersist.prepare_save(random, keys_checksum, &ssl_context, 0); } return ret==0 ? NO_ERROR : IO_ERROR; }
int main(int argc, char *argv[]) { u32 done; memset(&_ctx, 0x00, sizeof _ctx); ctx = &_ctx; parse_args(argc, argv); #if 0 u64 local_ptr; local_ptr = 0xdead0000dead0000ULL; ctx->reg[3][0] = (u32)(local_ptr >> 32); ctx->reg[3][1] = (u32)local_ptr; ctx->reg[4][0] = 0xdead0000; ctx->reg[4][1] = 0xdead0000; #endif ctx->ls = (u8*)malloc(LS_SIZE); if (ctx->ls == NULL) fail("Unable to allocate local storage."); memset(ctx->ls, 0, LS_SIZE); #if 0 wbe64(ctx->ls + 0x3f000, 0x100000000ULL); wbe32(ctx->ls + 0x3f008, 0x10000); wbe32(ctx->ls + 0x3e000, 0xff); #endif if (gdb_port < 0) { ctx->paused = 0; } else { gdb_init(gdb_port); ctx->paused = 1; gdb_signal(SIGABRT); } elf_load(elf_path); setup_context(); done = 0; while(done == 0) { if (ctx->paused == 0 || ctx->paused == 2) done = emulate(); // data watchpoints if (done == 2) { ctx->paused = 0; gdb_signal(SIGTRAP); done = 0; } if (done != 0) { printf("emulated() returned, sending SIGSEGV to gdb stub\n"); ctx->paused = 1; done = gdb_signal(SIGSEGV); } if (done != 0) { #ifdef STOP_DUMP_REGS dump_regs(); #endif #ifdef STOP_DUMP_LS dump_ls(); #endif } //if (ctx->paused == 1) gdb_handle_events(); } printf("emulate() returned. we're done!\n"); dump_ls(); free(ctx->ls); gdb_deinit(); return 0; }