int main(int argc, char *argv[]) { #if HAVE_LIBCAP pthread_t t1, t2; assert (geteuid () == 0); diod_log_init (argv[0]); _prtcap ("task0", CAP_DAC_OVERRIDE); /* root, expect set */ _prtcap ("task0", CAP_CHOWN); msg ("task0: setfsuid 1"); setfsuid (1); _prtcap ("task0", CAP_DAC_OVERRIDE); /* non-root, expect clr */ _prtcap ("task0", CAP_CHOWN); msg ("task0: setfsuid 0"); /* root, expect set */ setfsuid (0); _prtcap ("task0", CAP_DAC_OVERRIDE); _prtcap ("task0", CAP_CHOWN); msg ("task0: setfsuid 1"); setfsuid (1); _prtcap ("task0", CAP_DAC_OVERRIDE); /* non-root, expect clr */ _prtcap ("task0", CAP_CHOWN); msg ("task0: set cap"); _setcap ("task0", CAP_DAC_OVERRIDE); _setcap ("task0", CAP_CHOWN); _prtcap ("task0", CAP_DAC_OVERRIDE); /* root with cap explicitly set, */ _prtcap ("task0", CAP_CHOWN); /* expect set */ msg ("task0: setfsuid 2"); setfsuid (2); _prtcap ("task0", CAP_DAC_OVERRIDE);/* non-root with cap explicitly set, */ _prtcap ("task0", CAP_CHOWN); /* (as root) expect set */ msg ("task0: clr cap"); _clrcap ("task0", CAP_DAC_OVERRIDE); _clrcap ("task0", CAP_CHOWN); _prtcap ("task0", CAP_DAC_OVERRIDE);/* non-root with cap explicitly clr, */ _prtcap ("task0", CAP_CHOWN); /* (as non-root) expect clr */ _create (&t1, proc1, NULL); _create (&t2, proc2, NULL); _join (t2, NULL); _join (t1, NULL); _prtcap ("task0", CAP_DAC_OVERRIDE); /* after threads, expect clr */ _prtcap ("task0", CAP_CHOWN); #else fprintf (stderr, "libcap unavailable\n"); exit (77); #endif exit (0); }
list * list_remove(list * x, list * y) { list * z = 0; if(!x) { return 0; } if(x != y) { while(x != y && x->next) { x = x->next; } if(x != y && !x->next) { return x; } } if(x->next) { z = list_head(_join((x->prev) ? x->prev : 0, x->next)); x->next = 0; } else if(x->prev) { z = list_head(_join(x->prev, 0)); } list_del(x); return z; }
types::str join(T &&head, Types &&... tail) { types::str p = head; p.reserve(sizeof_string(tail...)); _join(p, std::forward<Types>(tail)...); return p; }
void scheduler_delete(struct scheduler *sched) { if (!sched) { return; } // shut everyone down pthread_mutex_lock(&sched->run_state.lock); sched->run_state.state = SCHED_SHUTDOWN; pthread_cond_broadcast(&sched->run_state.running); pthread_mutex_unlock(&sched->run_state.lock); worker_t *worker = NULL; for (int i = 1; i < sched->n_workers; ++i) { worker = scheduler_get_worker(sched, i); _join(worker); } log_sched("joined worker threads.\n"); // unbind this thread's worker self = NULL; system_barrier_destroy(&sched->barrier); if (sched->workers) { for (int i = 0, e = sched->n_workers; i < e; ++i) { worker_t *worker = scheduler_get_worker(sched, i); worker_fini(worker); } free(sched->workers); } free(sched); }
int scheduler_startup(struct scheduler *sched, const config_t *cfg) { worker_t *worker = NULL; int status = LIBHPX_OK; // start all of the other worker threads for (int i = 1, e = sched->n_workers; i < e; ++i) { worker = scheduler_get_worker(sched, i); status = _create(worker, cfg); if (status != LIBHPX_OK) { dbg_error("could not start worker %d.\n", i); for (int j = 1; j < i; ++j) { worker = scheduler_get_worker(sched, j); _cancel(worker); } for (int j = 1; j < i; ++j) { worker = scheduler_get_worker(sched, j); _join(worker); } return status; } } // wait for the other slave worker threads to launch system_barrier_wait(&sched->barrier); return status; }
const String& Path::getFullPath() const { if ( mIsDirtyPath ) { mFullPath = _join(); mIsDirtyPath = false; } return mFullPath; }
void av::NetNode::joined(const std::string& myeid) { #ifdef AVANGO_DEBUG logger.debug()<< "av::NetNode::joined: " << "called"; #endif // add a slot for ourselfes mObjectMap.addSlot(myeid); // tell our clients we joined _join(myeid); }
void _join(types::str &buffer, T &&head, Types &&... tail) { if (head[0] == '/') buffer = std::forward<T>(head); else if (not buffer or *buffer.rbegin() == OS_SEP or *buffer.rbegin() == '/') buffer += std::forward<T>(head); else { buffer += OS_SEP; buffer += std::forward<T>(head); } _join(buffer, std::forward<Types>(tail)...); }
int main(int argc, char *argv[]) { pthread_t t1, t2; diod_log_init (argv[0]); assert (geteuid () == 0); msg ("task0: setgroups (NULL)"); _setgroups (0, NULL); show_groups ("task0"); _create (&t1, proc1, NULL); _create (&t2, proc2, NULL); _join (t2, NULL); _join (t1, NULL); show_groups ("task0"); exit (0); }
int cue_code_generator_generate(CueCodeGenerator *cg, CueAstRoot *ast) { int nsdepth = 0; CueList *body = ast->v.module.body; CueList *package = ast->v.module.package; CueList *package_str = cue_list_new(cg->pool); CueListNode *cur = cue_list_head(package); prelude(cg); while (cur != NULL) { CueAstExpr *name = cur->data; enter_namespace(cg, name->v.name.id); cue_list_push(package_str, name->v.name.id); cur = cur->next; nsdepth++; } _fmt(cg, "// enter package %s\n\n", _join(cg->pool, ".", package_str)); cur = body->head; while (cur != NULL) { compile_stmt(cg, (CueAstStmt*)cur->data); cur = cur->next; } while (nsdepth > 0) { leave_namespace(cg); nsdepth--; } _fmt(cg, "// leave package %s\n\n", _join(cg->pool, ".", package_str)); prologue(cg); return 0; }
static void _fmt_call(CueCodeGenerator *cg, const char *fn, ...) { va_list args; const char *s; CueList *arglist = cue_list_new(cg->pool); va_start(args, fn); while ((s = va_arg(args, const char *)) != NULL) { cue_list_push(arglist, s); } va_end(args); _fmt(cg, "%s(%s)", fn, _join(cg->pool, ", ", arglist)); }
static void compile_stmt(CueCodeGenerator *cg, CueAstStmt *stmt) { switch (stmt->type) { case CUE_AST_STMT_USE: { break; } case CUE_AST_STMT_EXPR: { compile_expr(cg, stmt->v.expr.value); _fmt(cg, ";\n"); break; } case CUE_AST_STMT_RET: { _fmt(cg, "return"); if (stmt->v.ret.value) { _fmt(cg, " ("); compile_expr(cg, stmt->v.ret.value); _fmt(cg, ")"); } _fmt(cg, ";\n"); break; } case CUE_AST_STMT_FUNC_DECL: { CueListNode *node; _fmt(cg, "int\n"); /* TODO return types :) */ _fmt(cg, "_%s__%s(void)", _join(cg->pool, "_", cg->ns), stmt->v.func_decl.name); _fmt(cg, "{\n"); cg->indent++; node = stmt->v.func_decl.body->head; while (node != NULL) { compile_stmt(cg, (CueAstStmt*)node->data); node = node->next; } cg->indent--; _fmt(cg, "}\n\n"); break; } default: fprintf(stderr, "unknown stmt type: %d\n", stmt->type); }; }
static void enter_func_decl(CueCodeGenerator *cg, const char *name, const char *return_type, ...) { va_list args; int nargs; int i; const char *arg_type; va_start(args, return_type); nargs = 0; while ((arg_type = va_arg(args, const char *)) != NULL) { nargs++; } va_end(args); va_start(args, return_type); _fmt(cg, "%s\n", return_type); _fmt(cg, "_%s__%s(", _join(cg->pool, "_", cg->ns), name); i = 0; while ((arg_type = va_arg(args, const char *)) != NULL) { char buf[4096]; sprintf(buf, "arg%d", i++); if (strcmp(arg_type, "...") != 0) { _fmt(cg, "%s %s", arg_type, buf); } else { _fmt(cg, "..."); } if (i < nargs) _fmt(cg, ", "); } va_end(args); _fmt(cg, ")\n"); _fmt(cg, "{\n"); cg->indent++; }
inline Path operator/(char const* a, Path const& b) { return _join(Path(a), b); }
inline Path operator/(Path const& a, Path const& b) { return _join(a, b); }
void ARPA2WFST::arpa_to_wfst( ) { /* Convert an ARPA format Statistical Language Model to WFST format suitable for use with phonetisaurus-g2p. In this implementation we adopt the Google convention where the the sentence-begin (<s>) and sentence-end (</s>) tokens are represented *implicitly*, without arcs, and the model has multiple final states. This simplifies downstream processing for pronunciation generation, and has the added desirable side-effect of achieving a significant reduction in the number of transitions in the resulting WFST model. The model is expected to be in the following standardized format: \data\ ngram 1=M ngram 2=M ... ngram N=M \1-grams: p(w) w bow(w) ... \2-grams: p(v,w) v w bow(v,w) ... \3-grams: p(u,v,w) u v w \end\ where M refers to the number of unique NGrams for this order, and N refers to the maximum NGram order of the model. Similarly, p(w) refers to the probability of NGram 'w', and bow(w) refers to the back-off weight for NGram 'w'. The highest order of the model does not have back-off weights. Back-off weights equal to 0.0 in log-base 10 may be omitted to save space, and NGrams ending in sentence-end (</s>) naturally do not have back-off weights. The NGram columns are separated by a single tab (\t). */ if( arpa_lm_fp.is_open() ){ while( arpa_lm_fp.good() ){ getline( arpa_lm_fp, line ); if( current_order > 0 && line.compare("") != 0 && line.compare(0,1,"\\") != 0 ){ //Split the input using '\s+' as a delimiter vector<string> ngram; istringstream iss(line); copy( istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(ngram) ); double prob = atof(ngram.front().c_str()); ngram.erase(ngram.begin()); double bow = 0.0; if(ngram.size()>current_order){ bow = atof(ngram.back().c_str()); ngram.pop_back(); } //We have a unigram model if( max_order==1 ){ //Assume unigram ARPA model has a <s> // sentence-begin line. Is this true? if( ngram.front().compare(sb)==0 ) continue; else if( ngram.front().compare(se)==0 ) _make_final( sb, log10_2tropical(prob) ); else _make_arc( sb, sb, ngram.at(0), prob ); //We have a higher order model }else if( current_order==1 ){ if( ngram.front().compare(sb)==0 ){ _make_arc( sb, eps, eps, bow ); }else if( ngram.back().compare(se)==0 ){ _make_final( eps, prob ); }else{ _make_arc( eps, ngram.front(), ngram.front(), prob ); _make_arc( ngram.front(), eps, eps, bow ); } }else if( current_order < max_order ){ string isym = ngram.back(); string s_st = _join(ngram.begin(), ngram.end()-1); if( isym.compare(se)==0 ){ _make_final( s_st, prob ); }else{ string e_st = _join(ngram.begin(), ngram.end()); string b_st = _join(ngram.begin()+1, ngram.end()); _make_arc( s_st, e_st, isym, prob ); _make_arc( e_st, b_st, eps, bow ); } }else if( current_order==max_order ){ string isym = ngram.back(); string s_st = _join(ngram.begin(), ngram.end()-1); if( isym.compare(se)==0 ){ _make_final( s_st, prob ); }else{ string e_st = _join(ngram.begin()+1, ngram.end() ); _make_arc( s_st, e_st, isym, prob ); } } //Parse the header/footer/meta-data. This is not foolproof. //Random header info starting with '\' or 'ngram', etc. may cause problems. }else if( line.size() > 4 && line.compare( 0, 5, "ngram" ) == 0 ){ for( size_t i=0; i<line.size(); i++ ) if( line.compare(i,1,"=")==0 ) line.at(i)=' '; vector<string> parts; istringstream iss(line); copy( istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(parts) ); //Make sure there is at least one n-gram for max order! if( atoi(parts[2].c_str())>0 ) max_order = (size_t)atoi(parts[1].c_str())>max_order ? atoi(parts[1].c_str()) : max_order; //cerr << "MaxOrder: " << max_order << endl; }else if( line.compare( "\\data\\" ) == 0 ){ continue; }else if( line.compare( "\\end\\" ) == 0 ){ break; }else if( line.size() > 0 && line.compare( 0, 1, "\\" ) == 0 ){ line.replace(0, 1, ""); if( line.compare( 1, 1, "-" ) == 0 ) line.replace(1, 7, ""); else //Will work up to N=99. line.replace(2, 7, ""); current_order = atoi(&line[0]); } } arpa_lm_fp.close(); arpafst.SetInputSymbols(isyms); arpafst.SetOutputSymbols(osyms); }else{ cout << "Unable to open file: " << arpa_lm_file << endl; } }
inline Path operator/(Path const& a, char const* b) { return _join(a, Path(b)); }