/** * starts a RPC specific server * * @author imarom (17-Aug-15) */ void TrexRpcServerInterface::start() { m_is_running = true; verbose_msg("Starting RPC Server"); /* prepare for run */ _prepare(); m_thread = new std::thread(&TrexRpcServerInterface::_rpc_thread_cb, this); if (!m_thread) { throw TrexRpcException("unable to create RPC thread"); } }
void CollectionBase::IndexerBase::prepare() { Lock::assertWriteLocked(_cl->_ns); const StringData &name = _info["name"].Stringdata(); const BSONObj &keyPattern = _info["key"].Obj(); massert(16922, "dropDups is not supported, we should have stripped it out earlier", !_info["dropDups"].trueValue()); uassert(12588, "cannot add index with a hot index build in progress", !_cl->_indexBuildInProgress); uassert(12523, "no index name specified", _info["name"].ok()); uassert(16753, str::stream() << "index with name " << name << " already exists", _cl->findIndexByName(name) < 0); uassert(16754, str::stream() << "index already exists with diff name " << name << " " << keyPattern.toString(), _cl->findIndexByKeyPattern(keyPattern) < 0); uassert(12505, str::stream() << "add index fails, too many indexes for " << name << " key:" << keyPattern.toString(), _cl->nIndexes() < Collection::NIndexesMax); // The first index we create should be the pk index, when we first create the collection. if (!_isSecondaryIndex) { massert(16923, "first index should be pk index", keyPattern == _cl->_pk); } // Note this ns in the rollback so if this transaction aborts, we'll // close this ns, forcing the next user to reload in-memory metadata. CollectionMapRollback &rollback = cc().txn().collectionMapRollback(); rollback.noteNs(_cl->_ns); // Store the index in the _indexes array so that others know an // index with this name / key pattern exists and is being built. _idx = IndexDetailsBase::make(_info); _cl->_indexes.push_back(_idx); _cl->_indexBuildInProgress = true; addToNamespacesCatalog(_idx->indexNamespace()); _prepare(); }
void NamespaceDetails::Indexer::prepare() { Lock::assertWriteLocked(_d->_ns); const StringData &name = _info["name"].Stringdata(); const BSONObj &keyPattern = _info["key"].Obj(); uassert(16922, str::stream() << "dropDups is not supported and is likely to remain " << "unsupported for some time because it deletes arbitrary data", !_info["dropDups"].trueValue()); uassert(12588, "cannot add index with a hot index build in progress", !_d->_indexBuildInProgress); uassert(12523, "no index name specified", _info["name"].ok()); uassert(16753, str::stream() << "index with name " << name << " already exists", _d->findIndexByName(name) < 0); uassert(16754, str::stream() << "index already exists with diff name " << name << " " << keyPattern.toString(), _d->findIndexByKeyPattern(keyPattern) < 0); uassert(12505, str::stream() << "add index fails, too many indexes for " << name << " key:" << keyPattern.toString(), _d->nIndexes() < NIndexesMax); // The first index we create should be the pk index, when we first create the collection. if (!_isSecondaryIndex) { massert(16923, "first index should be pk index", keyPattern == _d->_pk); } // Note this ns in the rollback so if this transaction aborts, we'll // close this ns, forcing the next user to reload in-memory metadata. NamespaceIndexRollback &rollback = cc().txn().nsIndexRollback(); rollback.noteNs(_d->_ns); // Store the index in the _indexes array so that others know an // index with this name / key pattern exists and is being built. _idx = IndexDetails::make(_info); _d->_indexes.push_back(_idx); _d->_indexBuildInProgress = true; _prepare(); }
bool IDbConnection::executeStatement(const String &sql, const DbSqlValues &values) { try { shared_ptr<IDbStatement> statement = _prepare(sql); for(DbSqlValues::iterator i = values.begin(); i != values.end(); i++) { statement->addParameter()->setValue(i->second); } statement->execute(); return true; } catch(std::exception &e) { logError(sql, e); } return false; }
void inject_restore_socketcall(struct tracedump *td, struct pid *sp) { struct user_regs_struct regs2; /* prepare */ _prepare(sp); memcpy(®s2, &sp->regs, sizeof regs2); regs2.eax = sp->regs.orig_eax; regs2.eip = sp->vdso_addr; /* exec */ ptrace_setregs(sp, ®s2); ptrace_cont_syscall(sp, 0, true); ptrace_cont_syscall(sp, 0, true); /* rewrite the return code */ ptrace_getregs(sp, ®s2); sp->regs.eax = regs2.eax; /* restore */ ptrace_setregs(sp, &sp->regs); }
int32_t inject_socketcall(struct tracedump *td, struct pid *sp, uint32_t sc_code, ...) { struct user_regs_struct regs, regs2; int ss_vals, ss_mem, ss; va_list vl; enum arg_type type; uint32_t sv; void *ptr; uint8_t *stack, *stack_mem; uint32_t *stack32; int i, j; /* * get the required amount of stack space */ ss_vals = 0; // stack space for immediate values ss_mem = 0; // stack space for pointer values va_start(vl, sc_code); do { type = va_arg(vl, enum arg_type); if (type == AT_LAST) break; sv = va_arg(vl, uint32_t); /* each socketcall argument takes 4 bytes */ ss_vals += 4; /* if its memory, it takes additional sv bytes */ if (type == AT_MEM_IN || type == AT_MEM_INOUT) { ss_mem += sv; ptr = va_arg(vl, void *); } } while (true); va_end(vl); ss = ss_vals + ss_mem; /* * backup */ ptrace_getregs(sp, ®s); memcpy(®s2, ®s, sizeof regs); /* * write the stack */ stack = mmatic_zalloc(td->mm, ss); // stack area for immediate values stack32 = (uint32_t *) stack; stack_mem = stack + ss_vals; // stack area for pointer values va_start(vl, sc_code); i = 0; j = 0; do { type = va_arg(vl, enum arg_type); if (type == AT_LAST) break; sv = va_arg(vl, uint32_t); if (type == AT_VALUE) { stack32[i++] = sv; } else { /* i.e. its a memory arg */ stack32[i++] = regs.esp - ss_mem + j; /* copy the memory */ ptr = va_arg(vl, void *); memcpy(stack_mem + j, ptr, sv); j += sv; } } while (true); va_end(vl); ptrace_write(sp, regs.esp - ss, stack, ss); /* * write the code and run */ _prepare(sp); regs2.eax = 102; // socketcall regs2.ebx = sc_code; regs2.ecx = regs.esp - ss; regs2.eip = sp->vdso_addr; // gateway to int3 ptrace_setregs(sp, ®s2); ptrace_cont_syscall(sp, 0, true); // enter... ptrace_cont_syscall(sp, 0, true); // ...and exit /* * read back */ ptrace_getregs(sp, ®s2); ptrace_read(sp, regs.esp - ss_mem, stack_mem, ss_mem); va_start(vl, sc_code); do { type = va_arg(vl, enum arg_type); if (type == AT_LAST) break; sv = va_arg(vl, uint32_t); if (type == AT_VALUE) continue; ptr = va_arg(vl, void *); if (type == AT_MEM_IN) continue; memcpy(ptr, stack_mem, sv); stack_mem += sv; } while (true); va_end(vl); /* restore */ ptrace_setregs(sp, ®s); mmatic_free(stack); return regs2.eax; }
int main (int argc, char *argv[]) { Params p; int obj = -1, reader = -1, writer = -1; int i = 0; char number[100]; char outfilename[4096]; const char *id; p.width = p.height = p.bond = p.mode = -1; p.id = p.string_to_load = p.file_to_load = NULL; p.hydro_set = p.query_set = p.smarts_set = 0; p.aromatization = NONE; p.comment_field = NULL; p.comment = NULL; p.comment_name = 0; if (argc <= 2) USAGE(); indigoSetErrorHandler(onError, 0); indigoSetOption("ignore-stereochemistry-errors", "on"); if (parseParams(&p, argc, argv) < 0) return -1; p.out_ext = OEXT_OTHER; if (strcmp(p.outfile_ext, "mol") == 0) p.out_ext = OEXT_MOL; else if (strcmp(p.outfile_ext, "sdf") == 0) p.out_ext = OEXT_SDF; else if (strcmp(p.outfile_ext, "rxn") == 0) p.out_ext = OEXT_RXN; else if (strcmp(p.outfile_ext, "rdf") == 0) p.out_ext = OEXT_RDF; else if (strcmp(p.outfile_ext, "cml") == 0) p.out_ext = OEXT_CML; // guess whether to layout or render by extension p.action = ACTION_LAYOUT; if (p.out_ext == OEXT_OTHER) { indigoSetOption("render-output-format", p.outfile_ext); p.action = ACTION_RENDER; } // read in the input reader = (p.file_to_load != NULL) ? indigoReadFile(p.file_to_load) : indigoReadString(p.string_to_load); if (p.mode == MODE_SINGLE_MOLECULE) { if (p.id != NULL) ERROR("on single input, setting '-id' is not allowed\n"); if (p.out_ext == OEXT_RXN) ERROR("reaction output specified for molecule input\n"); if (p.smarts_set) obj = indigoLoadSmarts(reader); else if (p.query_set) obj = indigoLoadQueryMolecule(reader); else obj = indigoLoadMolecule(reader); _prepare(obj, p.aromatization); if (p.action == ACTION_LAYOUT) { indigoLayout(obj); if (p.out_ext == OEXT_MOL) indigoSaveMolfileToFile(obj, p.outfile); else indigoSaveCmlToFile(obj, p.outfile); } else { _setComment(obj, &p); renderToFile(obj, p.outfile); } } else if (p.mode == MODE_SINGLE_REACTION) { if (p.id != NULL) ERROR("on single input, setting '-id' is not allowed\n"); if (p.out_ext == OEXT_MOL) ERROR("molecule output specified for reaction input\n"); if (p.smarts_set) obj = indigoLoadReactionSmarts(reader); else if (p.query_set) obj = indigoLoadQueryReaction(reader); else obj = indigoLoadReaction(reader); _prepare(obj, p.aromatization); if (p.action == ACTION_LAYOUT) { indigoLayout(obj); if (p.out_ext == OEXT_CML) indigoSaveCmlToFile(obj, p.outfile); else indigoSaveRxnfileToFile(obj, p.outfile); } else { _setComment(obj, &p); renderToFile(obj, p.outfile); } } else { int item; int have_percent_s = (strstr(p.outfile, "%s") != NULL); if (p.mode == MODE_MULTILINE_SMILES) obj = indigoIterateSmiles(reader); else if (p.mode == MODE_SDF) obj = indigoIterateSDF(reader); else if (p.mode == MODE_MULTIPLE_CML) obj = indigoIterateCML(reader); else if (p.mode == MODE_RDF) obj = indigoIterateRDF(reader); else { fprintf(stderr, "internal error: wrong branch\n"); return -1; } if ((p.out_ext == OEXT_MOL || p.out_ext == OEXT_RXN || p.out_ext == OEXT_OTHER) && !have_percent_s) ERROR("on multiple output, output file name must have '%%s'\n"); if (p.out_ext == OEXT_SDF || p.out_ext == OEXT_RDF || (p.out_ext == OEXT_CML && !have_percent_s)) { writer = indigoWriteFile(p.outfile); if (p.out_ext == OEXT_RDF) indigoRdfHeader(writer); if (p.out_ext == OEXT_CML) indigoCmlHeader(writer); } i = -1; while ((item = indigoNext(obj))) { int rc; ++i; if (writer > 0) printf("saving item #%d... ", i); else { if (p.id) { if (!indigoHasProperty(item, p.id)) { fprintf(stderr, "item #%d does not have %s, skipping\n", i, p.id); continue; } id = indigoGetProperty(item, p.id); snprintf(outfilename, sizeof(outfilename), p.outfile, id); } else { snprintf(number, sizeof(number), "%d", i); snprintf(outfilename, sizeof(outfilename), p.outfile, number); } printf("saving %s... ", outfilename); } indigoSetErrorHandler(0, 0); if (_prepare(item, p.aromatization) < 0) { printf("%s\n", indigoGetLastError()); indigoSetErrorHandler(onError, 0); continue; } if (p.action == ACTION_LAYOUT) { if (indigoLayout(item) < 0) { printf("%s\n", indigoGetLastError()); indigoSetErrorHandler(onError, 0); continue; } } if (writer > 0) { if (p.out_ext == OEXT_SDF) rc = indigoSdfAppend(writer, item); else if (p.out_ext == OEXT_RDF) rc = indigoRdfAppend(writer, item); else rc = indigoCmlAppend(writer, item); } else { if (p.action == ACTION_LAYOUT) { if (p.out_ext == OEXT_MOL) rc = indigoSaveMolfileToFile(item, outfilename); else if (p.out_ext == OEXT_RXN) rc = indigoSaveRxnfileToFile(item, outfilename); else ERROR("extension unexpected"); } else { _setComment(item, &p); rc = indigoRenderToFile(item, outfilename); } } if (rc < 0) { printf("%s\n", indigoGetLastError()); indigoSetErrorHandler(onError, 0); continue; } indigoFree(item); indigoSetErrorHandler(onError, 0); printf("\n"); } if (writer > 0) { if (p.out_ext == OEXT_CML) indigoCmlFooter(writer); indigoFree(writer); } } indigoFree(reader); indigoFree(obj); return 0; }
int StringBuffer_prepare4oracle(T S) { assert(S); return _prepare(S, ':'); }
int StringBuffer_prepare4postgres(T S) { assert(S); return _prepare(S, '$'); }
cocos2d::Scene* prepareWithNoTransition() { _prepare(); _mainModule->start(); _prepared = true; return _mainModule->scene(); }
void prepare(const SceneChanger& sceneChanger) { _prepare(); _mainModule->start(sceneChanger); _prepared = true; }