void CaPerfTranslator::trans_ibs_op_ls_dcmiss(struct transient* trans) { calog_data entry; dcmiss_data data; static cookie_t old_cookie = NO_COOKIE; static cookie_t old_app_cookie = NO_COOKIE; static char const* mod = NULL; static char const* app = NULL; const char vmlinux[10] = "vmlinux"; struct ibs_op_sample* trans_op = ((struct ibs_sample*)(trans->ext))->op; if (!dcmiss_log) { return; } if (old_app_cookie == INVALID_COOKIE || old_app_cookie == NO_COOKIE || old_app_cookie != trans->app_cookie) { app = find_cookie(trans->app_cookie); old_app_cookie = trans->cookie; } if (trans->in_kernel == 1) { mod = vmlinux; old_cookie = NO_COOKIE; } else { if (old_cookie == INVALID_COOKIE || old_cookie == NO_COOKIE || old_cookie != trans->cookie) { mod = find_cookie(trans->cookie); old_cookie = trans->cookie; } } /* Setup entry */ entry.cookie = trans->cookie; entry.app_cookie = trans->app_cookie; entry.cpu = trans->cpu; entry.tgid = trans->tgid; entry.tid = trans->tid; entry.offset = trans->pc; entry.cnt = 1; /* Setup data */ data.phy = trans_op->ibs_op_phys_addr_high; data.phy = (data.phy << 32) | trans_op->ibs_op_phys_addr_low; data.lin = trans_op->ibs_op_ldst_linaddr_high; data.lin = (data.lin << 32) | trans_op->ibs_op_ldst_linaddr_low; data.ld = IBS_OP_IBS_LD_OP(trans_op); data.lat = (data.ld) ? IBS_OP_DC_MISS_LATENCY(trans_op) : 0; calog_add_data(dcmiss_log, &entry, &data, sizeof(dcmiss_data), mod, app); }
void CaPerfTranslator::trans_ibs_op_bta(struct transient* trans) { calog_data entry; bta_data data; static cookie_t old_cookie = NO_COOKIE; static cookie_t old_app_cookie = NO_COOKIE; static char const* mod = NULL; static char const* app = NULL; const char vmlinux[10] = "vmlinux"; struct ibs_op_sample* trans_op = ((struct ibs_sample*)(trans->ext))->op; if (!bta_log) { return; } if (!trans_op->ibs_op_brtgt_addr) { return; } if (old_app_cookie == INVALID_COOKIE || old_app_cookie == NO_COOKIE || old_app_cookie != trans->app_cookie) { app = find_cookie(trans->app_cookie); old_app_cookie = trans->cookie; } if (trans->in_kernel == 1) { mod = vmlinux; old_cookie = NO_COOKIE; } else { if (old_cookie == INVALID_COOKIE || old_cookie == NO_COOKIE || old_cookie != trans->cookie) { mod = find_cookie(trans->cookie); old_cookie = trans->cookie; } } /* Setup entry */ entry.cookie = trans->cookie; entry.app_cookie = trans->app_cookie; entry.cpu = trans->cpu; entry.tgid = trans->tgid; entry.tid = trans->tid; entry.offset = trans->pc; entry.cnt = 1; /* Setup data */ data.bta = trans_op->ibs_op_brtgt_addr; calog_add_data(bta_log, &entry, &data, sizeof(bta_data), mod, app); }
static int do_cookie_auth(request_rec *r) { char *user; authn_google_config_rec *conf = ap_get_module_config(r->per_dir_config, &authn_google_module); if (conf->debugLevel) ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "**** COOKIE AUTH at T=%lu",apr_time_now()/1000000); if (conf->cookieLife && find_cookie(r,&user,0L,0L)) { if (conf->debugLevel) ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "User %s auth granted from cookie",user); r->user = user; r->ap_auth_type = "Cookie"; return OK; } else { if (conf->debugLevel) ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Cookie auth is DECLINED"); } return DECLINED; /* Let someone else deal with it */ }
static char const * get_dep_name(struct sfile const * sf) { if (sf->anon) return find_cookie(sf->app_cookie); /* avoid to call find_cookie(), caller can recover using image_name */ if (sf->cookie == sf->app_cookie) return NULL; if (!separate_kernel && !(separate_lib && !sf->kernel)) return NULL; /* this will fail if e.g. kernel thread */ if (sf->app_cookie == 0) return NULL; return find_cookie(sf->app_cookie); }
static char const * get_dep_name(struct sfile const * sf) { if (sf->anon) return find_cookie(sf->app_cookie); if (sf->cookie == sf->app_cookie) return NULL; if (!separate_kernel && !(separate_lib && !sf->kernel)) return NULL; if (sf->app_cookie == 0) return NULL; return find_cookie(sf->app_cookie); }
static char * mangle_filename(struct sfile * last, struct sfile const * sf, int counter, int cg) { char * mangled; struct mangle_values values; struct opd_event * event = find_counter_event(counter); values.flags = 0; if (sf->kernel) { values.image_name = sf->kernel->name; values.flags |= MANGLE_KERNEL; } else if (sf->anon) { values.flags |= MANGLE_ANON; values.image_name = mangle_anon(sf->anon); values.anon_name = sf->anon->name; } else { values.image_name = find_cookie(sf->cookie); } values.dep_name = get_dep_name(sf); if (!values.dep_name) values.dep_name = values.image_name; /* FIXME: log */ if (!values.image_name || !values.dep_name) return NULL; if (separate_thread) { values.flags |= MANGLE_TGID | MANGLE_TID; values.tid = sf->tid; values.tgid = sf->tgid; } if (separate_cpu) { values.flags |= MANGLE_CPU; values.cpu = sf->cpu; } if (cg) { values.flags |= MANGLE_CALLGRAPH; if (last->kernel) { values.cg_image_name = last->kernel->name; } else if (last->anon) { values.flags |= MANGLE_CG_ANON; values.cg_image_name = mangle_anon(last->anon); values.anon_name = last->anon->name; } else { values.cg_image_name = find_cookie(last->cookie); } /* FIXME: log */ if (!values.cg_image_name) { if (values.flags & MANGLE_ANON) free((char *)values.image_name); return NULL; } } values.event_name = event->name; values.count = event->count; values.unit_mask = event->um; mangled = op_mangle_filename(&values); if (values.flags & MANGLE_ANON) free((char *)values.image_name); if (values.flags & MANGLE_CG_ANON) free((char *)values.cg_image_name); return mangled; }
int opd_open_sample_file(odb_t *file, struct sfile *last, struct sfile * sf, int counter, int cg) { char * mangled; char const * binary; int spu_profile = 0; vma_t last_start = 0; int err; mangled = mangle_filename(last, sf, counter, cg); if (!mangled) return EINVAL; verbprintf(vsfile, "Opening \"%s\"\n", mangled); create_path(mangled); /* locking sf will lock associated cg files too */ sfile_get(sf); if (sf != last) sfile_get(last); retry: err = odb_open(file, mangled, ODB_RDWR, sizeof(struct opd_header)); /* This can naturally happen when racing against opcontrol --reset. */ if (err) { if (err == EMFILE) { if (sfile_lru_clear()) { printf("LRU cleared but odb_open() fails for %s.\n", mangled); abort(); } goto retry; } fprintf(stderr, "oprofiled: open of %s failed: %s\n", mangled, strerror(err)); goto out; } if (!sf->kernel) binary = find_cookie(sf->cookie); else binary = sf->kernel->name; if (last && last->anon) last_start = last->anon->start; if (sf->embedded_offset != UNUSED_EMBEDDED_OFFSET) spu_profile = 1; fill_header(odb_get_data(file), counter, sf->anon ? sf->anon->start : 0, last_start, !!sf->kernel, last ? !!last->kernel : 0, spu_profile, sf->embedded_offset, binary ? op_get_mtime(binary) : 0); out: sfile_put(sf); if (sf != last) sfile_put(last); free(mangled); return err; }
int main (int argc, char *argv[]) { int err, fake_argc = 1; char * fake_argv[] = {"hello", 0}; QofBook *book; Account *root; char *request_bufp, *reply_bufp; int rc, sz; /* intitialize the engine */ gnc_engine_init (fake_argc, fake_argv); /* contact the database, which is a flat file for this demo */ /* this should really be an SQL server */ book = qof_book_new (); rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE); if (!rc) goto bookerrexit; rc = gnc_book_load (book); if (!rc) goto bookerrexit; /* the root pointer points to our local cache of the data */ root = gnc_book_get_root_account (book); /* --------------------------------------------------- */ /* done with initialization, go into event loop */ while (FCGI_Accept() >= 0) { GList *split_list; Query *q = NULL; const char *request_method; const char *user_agent; const char *auth_string; const char *content_length; int read_len = 0; int send_accts = 0; /* get the user agent; reject if wrong agent */ user_agent = getenv ("HTTP_USER_AGENT"); if (strncmp ("gnucash", user_agent, 7)) { reject_user_agent (user_agent); continue; } /* get the request method */ request_method = getenv ("REQUEST_METHOD"); if (strcmp ("POST", request_method)) { /* method=post is the only spported method*/ reject_method(request_method); continue; } /* ----------------------------------------------- */ /* look for an authentication cookie */ auth_string = find_cookie ("gnc-server"); /* found the cookie, lets make sure that it is valid */ if (auth_string) { gboolean valid_session; valid_session = have_session (auth_string); if (!valid_session) { /* XXX invalid sessions are a sign of hacking; * this event should be noted in a security log * and the server admin contacted. */ reject_session (auth_string); continue; } } /* go ahead and read the message body. * we'll need this soon enough */ content_length = getenv("CONTENT_LENGTH"); read_len = atoi (content_length); /* read 'read_len' bytes from stdin ... */ request_bufp = (char *) g_malloc (read_len); fread (request_bufp, read_len, 1, stdin); /* if no previously authenticated session, * authenticate now */ if (!auth_string) { char *name = NULL, *passwd = NULL; parse_for_login (request_bufp, &name, &passwd); auth_string = auth_user (name, passwd); if (!auth_string) { reject_auth(); g_free (request_bufp); continue; } send_accts = 1; } /* ----------------------------------------------- */ /* send only the accounts to the user */ if (send_accts) { /* print the HTTP header */ printf("Content-type: text/gnc-xml\r\n" "Set-Cookie: %s\r\n" "Content-Length: %d\r\n" "\r\n", auth_string, sz); /* since this is the first time the user is logging * in, send them the full set of accounts. * (Do not send them any transactions yet). */ gncxml_write_account_tree_to_buf(root, &reply_bufp, &sz); /* send the xml to the client */ printf ("%s", reply_bufp); g_free (request_bufp); /* wait for the next request */ continue; } /* ----------------------------------------------- */ /* If we got to here, then the ser should be sending * us a query xml. * we should somehow error check that what we got * is really a valid query */ /* conver the xml input into a gnucash query structure... */ q = gncxml_read_query (request_bufp, read_len); xaccQuerySetGroup (q, root); /* hack -- limit to 30 splits ... */ xaccQuerySetMaxSplits (q, 30); split_list = xaccQueryGetSplits (q); /* poke those splits into an ccount group structure */ /* XXX not implemented */ /* send the account group structure back to the user */ /* XXX not implemented */ xaccFreeQuery (q); g_free (request_bufp); } bookerrexit: err = gnc_book_get_error (book); /* 500 Server Error */ FCGI_SetExitStatus (500); printf("Content-type: text/plain\r\n\r\n" "error was %s\n", strerror (err)); FCGI_Finish(); /* close the book */ qof_book_destroy (book); /* shut down the engine */ gnc_engine_shutdown (); sleep (1); /* must return a non-zero error code, otherwise fastcgi * attempts to respawn this daemon. */ return 500; }
int main(void) { int error; #if _MINT_ /* HR 151102 */ have_ssystem = Ssystem(-1, 0, 0) == 0; /* HR 151102: use Ssystem where possible */ mint = (find_cookie('MiNT') == -1) ? FALSE : TRUE; magx = (find_cookie('MagX') == -1) ? FALSE : TRUE; /* HR 151102 */ geneva = (find_cookie('Gnva') == -1) ? FALSE : TRUE; /* DjV 035 080203 */ mint |= magx; /* Quick & dirty */ if (mint) { Psigsetmask(0x7FFFE14EL); Pdomain(1); } #endif x_init(); if ((ap_id = appl_init()) < 0) return -1; if (_GemParBlk.glob.version >= 0x400) { shel_write(9, 1, 0, NULL, NULL); menu_register(ap_id, " Tera Desktop"); } if (rsrc_load(RSRCNAME) == 0) form_alert(1, msg_resnfnd); else { if ((error = init_xdialog(&vdi_handle, malloc, free, "Tera Desktop", 1, &nfonts)) < 0) xform_error(error); else { init_vdi(); rsc_init(); if (((max_w / screen_info.fnt_w) < 40) || ((max_h / screen_info.fnt_h) < 25)) alert_printf(1, MRESTLOW); else { if ((error = alloc_global_memory()) == 0) { if (exec_deskbat() == FALSE) { if (load_icons() == FALSE) { if (init() == FALSE) { graf_mouse(ARROW, NULL); evntloop(); wd_del_all(); menu_bar(menu, 0); xw_close_desk(); } free_icons(); /* HR 151102 */ wind_set(0, WF_NEWDESK, NULL, 0); dsk_draw(); } } Mfree(global_memory); } else xform_error(error); } if (vq_gdos() != 0) vst_unload_fonts(vdi_handle, 0); exit_xdialog(); } rsrc_free(); } /* DjV 013 030103 100203 ---vvv--- */ /* * The following section handles system shutdown and resolution change * If a resolution change is required, shutdown is performed first * If only shutdown s required, system will reset at the end. */ /* appl_exit(); */ if ( chrez || shutdown ) /* If change resolution or shutdown ... */ { /* Tell all applications which would understand it to end */ quit = shel_write ( 4, 2, 0, NULL, NULL ); /* complete shutdown */ evnt_timer( 3000, 0 ); /* Wait a bit? */ /* /* * In Mint, must tell all proceseses to terminate nicely ? * but this is only in this group ? What to do? */ Pkill(0, SIGTERM); evnt_timer(3000, 0); /* Wait a bit? */ */ /* * After all applications have hopefully been closed, * change the screen resolution if needed; * else- reset the computer */ if ( chrez ) get_set_video(2); #if 1 else #if _MINT_ if (!mint) /* HR 230203: Dont reset under MiNT or MagiC !!!!! */ #endif { /* Perform a reset here */ #if 0 /* with warnings */ long *m; /* to memory locations */ long rv; /* reset vector */ Super ( 0L ); /* Supervisor; old stack won't be needed again */ *(m = 0x420L) = 0L; /* memctrl */ *(m = 0x43aL) = 0L; /* memval2 */ *(m = 0x426L) = 0L; /* resvalid */ m = *( m = 0x4f2 ); /* to start of OS */ rv = *(m + 4); /* to routine that handles the reset */ Supexec(rv); /* execute it */ #else /* HR: without warnings */ long (*rv)(); /* reset vector */ Super ( 0L ); /* Supervisor; old stack won't be needed again */ memctrl = 0L; memval2 = 0L; resvalid = 0L; (long)rv = *((long *)os_start + 4); /* routine that handles the reset */ Supexec(rv); /* execute it */ #endif } #endif }
void get_set_video (int set){ /* 0=get, 1=set, 2=set & change rez */ long #ifdef _OVSCAN s, /* sup.stack p. */ #endif logb, /* logical screen base */ phyb; /* physical screen base */ #ifdef _OVSCAN char *acia; static int ov_max_h, ov_max_w; int std_x[4] = {320,640,1280,0}; int std_y[4] = {200,400,800,0}; int idi; #endif /* Where is the screen ? */ logb = xbios(3); /* Logbase(); */ phyb = xbios(2); /* Physbase(); */ if ( set == 0 ){ /* get data */ /* Find about video hardware (shifter; will be 0xffffffff without cookie */ vdo = find_cookie( '_VDO' ); /* Try to find out about a couple of overscan types */ #ifdef _OVSCAN if ( ( (over = find_cookie('OVER')) != - 1 ) || ( (over = find_cookie('Lace')) != - 1 ) ) { ovrstat = 0; for ( idi = 0; idi < 3; idi++ ) if ( max_h > std_y[idi] && max_h < std_y[idi + 1] ) { ov_max_w = max_w; ov_max_h = max_h; ovrstat = 1; break; } if ( ovrstat != 0 ) options.V2_2.vprefs |= VO_OVSCAN; else options.V2_2.vprefs &= ~VO_OVSCAN; } else over = 0xffffffffL; #endif /* Get current blitter state; insert into options */ if ( get_tosversion() >= 0x104 ) bltstat = Blitmode(-1); /* Function known only to tos >= 1.4 ? */ else bltstat = 0; if ( bltstat & 0x0001 ) options.V2_2.vprefs |= VO_BLITTER; else options.V2_2.vprefs &= ~VO_BLITTER; /* Which is the current standard resolution ? */ currez = xbios(4); /* Getrez() */ options.V2_2.vrez = currez; } else /* set data */ { /* Set blitter, if present */ if ( bltstat & 0x0002 ) { if ( options.V2_2.vprefs & VO_BLITTER ) bltstat |= 0x0001; else bltstat &= ~0x0001; bltstat = Blitmode ( bltstat ); } #ifdef _OVSCAN /* * Set overscan (Lacescan, in fact) * that which is below is ok but not enough !!!! * therefore disabled for the time being */ if ( (over != 0xffffffffL ) && ( (vprefsold^options.V2_2.vprefs) && VO_OVSCAN) ) { menu_bar ( menu, 0 ); s = Super (0L ); (long)acia = 0xFFFC00L; /* address of the acia chip reg HR 240203 (long) */ if ( options.V2_2.vprefs & VO_OVSCAN ) { *acia = 0xD6; /* value for the acia reg- switch overscan ON */ ovrstat = 1; max_h = ov_max_h; max_w = ov_max_w; } else { *acia = 0x96; /* value for the acia reg- switch overscan OFF */ ovrstat = 0; max_w = std_x[idi]; max_h = std_y[idi]; } /* * An attempt to change resolution (to the same one) will * provoke Lacescan to adapt */ xbios(5, logb, phyb, currez); /* Setscreen (logb,phyb,currez); */ Super ( (void *) s ); wind_set(0, WF_NEWDESK, desktop, 0); /* * For some reason desktop doesn't get redrawn correctly here * after overstat switch unless menu_bar is called TWICE * (possibly at first call it is too long and corrupts * part of the screen?) */ menu_bar(menu, 1); dsk_draw(); menu_bar(menu, 1); /* wd_attrib(); */ wd_fields(); /* HR 050303 */ } #endif /* Change resolution */ /* xbios(...) produces slightly smaller code */ if ( set > 1 ) { /* * This will actually (almost) reset the computer */ shel_write( 5, currez + 2, 0, NULL, NULL ); /* DjV 007 110203 */ /* DjV 007 290103: is no good, so disabled for the time being */ xbios(5, logb, phyb, currez); /* Setscreen (logb,phyb,currez); */ } } }
static int apply_rules(request_rec *r, apr_array_header_t *rules, apr_array_header_t *threshold_exceededs ) { int i, ret, go_to_blockedperiod; uint32_t incred_count; rule_entry *rule, *rs; char *id, *cookie; char *blockkey, *countkey, *blockval, *countval; char *mgetkeys; threshold_exceeded_entry *threshold_exceeded; interval_limit_config *conf = ap_get_module_config(r->per_dir_config, &interval_limit_module); if (rules) { /* init local vars */ blockkey = NULL; countkey = NULL; blockval = NULL; countval = NULL; /* init memcached */ ret = memcached_init_ilimit_func(r, conf->memc_addrs); if (ret < 0) { return -1; } /* apply rules */ rs = (rule_entry *)rules->elts; for ( i =0; i <rules->nelts; i++) { rule = &rs[i]; id = NULL; ILLOG_DEBUG(r, MODTAG "apply_rule %s type %d maxcount %ld interval %ld blockperiod %ld block %d", rule->name, rule->type, rule->max_count, rule->interval, rule->blocking_period, rule->block ); if ( rule->type == THRESHOLD_IP) { id = r->connection->remote_ip; } else if (rule->type == THRESHOLD_COOKIE) { if (!conf->cookie_name) { ILLOG_ERROR(r, MODTAG "no cookie name specified even if you choose cookie as user identifier! " "you must specify cookie name with IntervalLimitCookieName directive"); continue; } cookie = find_cookie(r, conf->cookie_name); if (!cookie) { continue; } id = cookie; } else { continue; } if (!id) { continue; } blockkey = (char*)apr_psprintf(r->pool, "%s-%s-%s", MEMC_KEY_PREFIX_BLOCKING, rule->name, id); countkey = (char*)apr_psprintf(r->pool, "%s-%s-%s", MEMC_KEY_PREFIX_COUNTING, rule->name, id); blockval = NULL; countval = NULL; /* key encode */ blockkey = get_encoded_string(r, blockkey); countkey = get_encoded_string(r, countkey); ILLOG_DEBUG(r, MODTAG "apply_rule request: id(raw)=%s blockkey=%s countkey=%s", id, blockkey, countkey); /* get block + count value */ ret = get_block_and_count_value(r, blockkey, countkey, &blockval, &countval); if ( ret < 0 ) { continue; } go_to_blockedperiod = 0; /* check if requestin user is not in the blocking period */ if ( blockval && !strcmp(blockval, MEMC_VAl_BLOCKED_PERIOD) ) { /* append to threshold_exceeded */ threshold_exceeded = (threshold_exceeded_entry *)apr_array_push(threshold_exceededs); threshold_exceeded->name = rule->name; threshold_exceeded->block = rule->block; ILLOG_DEBUG(r, MODTAG "apply_rule result rule=%s state=OverLimited block=%d", rule->name, rule->block ); continue; } /* check if the count has already exceeded threshold */ if ( countval && atoi(countval) >= rule->max_count) { go_to_blockedperiod = 1; /* check if the count hits threshold after incremented */ } else { ret = memcached_incr_ilimit_func(r, countkey, rule->interval, &incred_count); if (ret < 0) { ILLOG_ERROR(r, MODTAG "apply_rule increment count failure: rule=%s", rule->name ); continue; } if ( incred_count >= rule->max_count ) { go_to_blockedperiod = 1; } } if (go_to_blockedperiod){ /* append to threshold_exceeded */ threshold_exceeded = (threshold_exceeded_entry *)apr_array_push(threshold_exceededs); threshold_exceeded->name = rule->name; threshold_exceeded->block = rule->block; /* set blockperiod flag */ ret = memcached_set_ilimit_func(r, blockkey, (const char*)MEMC_VAl_BLOCKED_PERIOD, rule->blocking_period); if (ret < 0) { ILLOG_ERROR(r, MODTAG "apply_rule set blockperiod flag failure: rule=%s", rule->name ); continue; } /* reset count slot */ ret = memcached_del_ilimit_func(r, countkey); if (ret < 0) { ILLOG_ERROR(r, MODTAG "apply_rule reset counter slot failure: rule=%s", rule->name ); continue; } } ILLOG_DEBUG(r, MODTAG "apply_rule result rule=%s state=NotYetOverLimit block=%d count=%d", rule->name, rule->block, incred_count ); } // end of for } return 0; }