/* recursively free a vertree_entry. caller frees entry itself */ static void ct_version_tree_free_entry(struct ct_vertree_entry *entry) { struct ct_vertree_ver *ventry; struct ct_vertree_entry *child; if (entry == NULL) { return; } if (entry->cve_name != NULL) e_free(&entry->cve_name); /* Clean up version entries */ while ((ventry = TAILQ_FIRST(&entry->cve_versions)) != NULL) { TAILQ_REMOVE(&entry->cve_versions, ventry, cvv_link); ct_version_tree_free_version(ventry); } /* Clean up children */ while ((child = RB_ROOT(&entry->cve_children)) != NULL) { RB_REMOVE(ct_vertree_entries, &entry->cve_children, child); ct_version_tree_free_entry(child); e_free(&child); } }
int ct_extract_open_next(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx) { struct ct_extract_stack *next; int ret, s_errno; if (!TAILQ_EMPTY(extract_head)) { next = TAILQ_FIRST(extract_head); CNDBG(CT_LOG_CTFILE, "should start restoring [%s]", next->filename); /* Basedir not needed here because we are done with prevlvl */ if ((ret = ctfile_parse_init(ctx, next->filename, NULL)) != 0) { s_errno = errno; /* chain is broken, clean it up */ ct_extract_cleanup_queue(extract_head); errno = s_errno; return (ret); } TAILQ_REMOVE(extract_head, next, next); if (next->filename) e_free(&next->filename); if (next) e_free(&next); } else { CABORTX("open next with no next archive"); } return (0); }
void ct_cleanup(struct ct_global_state *state) { ct_cleanup_eventloop(state); e_free(&state->ct_stats); e_free(&state); }
void ct_match_unwind(struct ct_match *match) { switch (match->cm_mode) { case CT_MATCH_EVERYTHING: break; case CT_MATCH_REGEX: if (match->cm_regex) { ct_regex_unwind(match->cm_regex); e_free(&match->cm_regex); } break; case CT_MATCH_RB: if (match->cm_rb_head) { ct_rb_unwind(match->cm_rb_head); e_free(&match->cm_rb_head); } break; case CT_MATCH_GLOB: if (match->cm_glob) { ct_glob_unwind(match->cm_glob); e_free(&match->cm_glob); } break; default: CABORTX("invalid match mode"); } e_free(&match); }
int ct_regex_comp(regex_t *re, char **flist) { int i, rv; char *s, *q = NULL, error[1024]; for (i = 0; flist[i] != NULL; i++) { if (flist[i] == NULL) break; if (i == 0) e_asprintf(&s, "%s", flist[i]); else e_asprintf(&s, "%s|%s", q, flist[i]); if (q) e_free(&q); q = s; } if (q == NULL) return (0); if ((rv = regcomp(re, q, REG_EXTENDED | REG_NOSUB)) != 0) { regerror(rv, re, error, sizeof(error) - 1); CNDBG(CT_LOG_FILE, "regcomp failed: %s", error); e_free(&q); return (CTE_REGEX); } e_free(&q); return (0); }
static void ct_version_tree_free_version(struct ct_vertree_ver *entry) { struct ct_vertree_dir *dir; struct ct_vertree_spec *spec; struct ct_vertree_link *flink; struct ct_vertree_file *file; if (C_ISDIR(entry->cvv_type)) { dir = (struct ct_vertree_dir *)entry; e_free(&dir); } else if (C_ISBLK(entry->cvv_type) || C_ISCHR(entry->cvv_type)) { spec = (struct ct_vertree_spec *)entry; e_free(&spec); } else if (C_ISLINK(entry->cvv_type)) { flink = (struct ct_vertree_link *)entry; if (flink->cvl_linkname != NULL) e_free(&flink->cvl_linkname); e_free(&flink); } else if (C_ISREG(entry->cvv_type)) { file = (struct ct_vertree_file *)entry; e_free(&file); } return; }
/* * now the operation has completed we can kick off the next operation knowing * that everything has been set up for it. */ int ctfile_extract_nextop(struct ct_global_state *state, struct ct_op *op) { struct ct_ctfile_find_fileop_args *ccffa = op->op_args; struct ct_ctfileop_args *cca; char *cachename; int ret = 0; /* * If this is an operation that needs the full incremental chain * recursively fetch the next one in the chain till done. */ if (ccffa->ccffa_download_chain) { /* * download_next takes ownership of the pointers it is given, * duplicate our copy. */ cca = e_calloc(1, sizeof(*cca)); if (ccffa->ccffa_base.cca_localname) cca->cca_localname = e_strdup(ccffa->ccffa_base.cca_localname); if (ccffa->ccffa_base.cca_remotename) cca->cca_remotename = e_strdup(ccffa->ccffa_base.cca_remotename); cca->cca_tdir = ccffa->ccffa_base.cca_tdir; cca->cca_ctfile = ccffa->ccffa_base.cca_ctfile; op->op_args = cca; /* we give up ownership of cca here */ if ((ret = ctfile_download_next(state, op)) != 0) goto out; } /* * We now have the name of the file we wish to perform the main * operation on, the nextop callback will add this operation * to the operation list. Ownership of the allocated pointer * passes to the child. */ if (ccffa->ccffa_base.cca_localname != NULL) { cachename = ctfile_get_cachename(ccffa->ccffa_base.cca_localname, ccffa->ccffa_base.cca_tdir); } else { cachename = NULL; } ret = ccffa->ccffa_nextop(state, cachename, ccffa->ccffa_nextop_args); out: if (ccffa->ccffa_base.cca_localname) e_free(&ccffa->ccffa_base.cca_localname); if (ccffa->ccffa_base.cca_remotename) e_free(&ccffa->ccffa_base.cca_remotename); e_free(&ccffa); return (ret); }
int ct_extract_file_cleanup(struct ct_global_state *state, struct ct_op *op) { struct ct_extract_file_args *cefa = op->op_args; e_free(&cefa->cefa_filename); e_free(&cefa->cefa_ctfile); e_free(&cefa); return (0); }
void ct_extract_cleanup_queue(struct ct_extract_head *extract_head) { struct ct_extract_stack *next; while ((next = TAILQ_FIRST(extract_head)) != NULL) { TAILQ_REMOVE(extract_head, next, next); e_free(&next->filename); e_free(&next); } }
void ct_rb_unwind(struct ct_match_tree *head) { struct ct_match_node *n; while ((n = RB_ROOT(head)) != NULL) { RB_REMOVE(ct_match_tree, head, n); e_free(&n->cmn_string); e_free(&n); } }
void ctdb_shutdown(struct ctdb_state *state) { if (state == NULL) return; ctdb_cleanup(state); if (state->ctdb_dbfile) e_free(&state->ctdb_dbfile); e_free(&state); }
int ct_init(struct ct_global_state **statep, struct ct_config *conf, int flags, void (*info_cb)(evutil_socket_t, short, void *)) { struct ct_global_state *state = NULL; extern void ct_reconnect(evutil_socket_t, short, void *); struct stat sb; int ret = 0; /* Run with restricted umask as we create numerous sensitive files. */ umask(S_IRWXG|S_IRWXO); if ((ret = ct_check_expired_certs(conf)) != 0) { CNDBG(CT_LOG_NET, "can't updated expired certificates: %s", ct_strerror(ret)); goto fail; } if ((ret = ct_setup_state(&state, conf)) != 0) goto fail; /* set defaults */ if ((ret = ct_set_log_fns(state, NULL, NULL, NULL, NULL, NULL, NULL)) != 0) goto fail; if ((flags & CT_NEED_SECRETS) != 0) { if (stat(conf->ct_crypto_secrets, &sb) == -1) { ret = CTE_NO_SECRETS_FILE; goto fail; } /* we got crypto */ if ((ret = ct_unlock_secrets(conf->ct_crypto_passphrase, conf->ct_crypto_secrets, state->ct_crypto_key, sizeof(state->ct_crypto_key), state->ct_iv, sizeof(state->ct_iv))) != 0) { goto fail; } } if ((ret = ct_init_eventloop(state, info_cb, flags)) != 0) goto fail; *statep = state; return (0); fail: if (state != NULL) { e_free(&state->ct_stats); e_free(&state); } return (ret); }
int ctfile_nextop_archive_cleanup(struct ct_global_state *state, struct ct_op *op) { struct ct_ctfileop_args *cca = op->op_args; if (cca->cca_localname) e_free(&cca->cca_localname); if (cca->cca_remotename) e_free(&cca->cca_remotename); e_free(&cca); return (0); }
void ct_extract_free_entry(struct ct_pending_files *head, struct ct_pending_file *file) { struct fnode *fnode; RB_REMOVE(ct_pending_files, head, file); while ((fnode = TAILQ_FIRST(&file->cpf_links)) != NULL) { TAILQ_REMOVE(&file->cpf_links, fnode, fn_list); ct_free_fnode(fnode); } e_free(&file->cpf_name); e_free(&file); }
void ct_match_insert_rb(struct ct_match *match, char *string) { struct ct_match_node *n; if (match->cm_mode != CT_MATCH_RB) CABORTX("match mode %d is not rb", match->cm_mode); n = e_calloc(1, sizeof(struct ct_match_node)); n->cmn_string = e_strdup(string); if (RB_INSERT(ct_match_tree, match->cm_rb_head, n)) { /* pattern already exists free it */ e_free(&n->cmn_string); e_free(&n); } }
void ct_cleanup_login_cache(void) { struct ct_login_cache *tmp; while ((tmp = RB_ROOT(&ct_login_cache)) != NULL) { RB_REMOVE(ct_login_cache_tree, &ct_login_cache, tmp); /* may cache negative entries, uid not found, avoid NULL free */ if (tmp->lc_name != NULL) { e_free(&tmp->lc_name); } e_free(&tmp); } ct_login_cache_size = 0; }
/* * return boolean whether or not the last ctfile_list contained * filename. */ int ct_file_on_server(struct ct_global_state *state, char *filename) { struct ctfile_list_tree results; struct ctfile_list_file *file = NULL; char *filelist[2]; int exists = 0; RB_INIT(&results); filelist[0] = filename; filelist[1] = NULL; ctfile_list_complete(&state->ctfile_list_files, CT_MATCH_GLOB, filelist, NULL, &results); /* Check to see if we already have a secrets file on the server */ if (RB_MIN(ctfile_list_tree, &results) != NULL) { exists = 1; } while ((file = RB_ROOT(&results)) != NULL) { RB_REMOVE(ctfile_list_tree, &results, file); e_free(&file); } return (exists); }
int ct_op_complete(struct ct_global_state *state) { struct ct_op *op; int ret, s_errno;; op = TAILQ_FIRST(&state->ct_operations); if (op == NULL) CABORTX("no operation in queue"); if (op->op_complete != NULL && (ret = op->op_complete(state, op)) != 0) { s_errno = errno; state->ct_errno = ret; ct_clear_operation(state); errno = s_errno; return (1); } TAILQ_REMOVE(&state->ct_operations, op, op_link); e_free(&op); if (TAILQ_EMPTY(&state->ct_operations)) return (1); /* set up for the next loop */ ct_set_file_state(state, CT_S_STARTING); ct_wakeup_file(state->event_state); return (0); }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i, j, m, n, k; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; char emsg[_BufSize]; unsigned num; unsigned counter = 0; srand(1); // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. //e_set_host_verbosity(H_D2); //e_set_loader_verbosity(L_D1); e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Allocate a buffer in shared external memory // for message passing from eCore to host. e_alloc(&emem, _BufOffset, _BufSize); // Open a workgroup e_open(&dev, 0, 0, platform.rows, platform.cols); // Load the device program onto core (0,0) e_load("e_mutex_test0.srec", &dev, 0, 0, E_TRUE); usleep(10000); // Load the device program onto all the other eCores e_load_group("e_mutex_test.srec", &dev, 0, 1, 1, 3, E_TRUE); e_load_group("e_mutex_test.srec", &dev, 1, 0, 3, 4, E_TRUE); usleep(100000); // Wait for core program execution to finish // Read message from shared buffer e_read(&dev, 0, 0, 0x6200, &num, sizeof(num)); e_read(&dev, 0, 0, 0x6300, &counter, sizeof(counter)); // Print the message and close the workgroup. fprintf(stderr, "The counter now is %d!\n", counter); fprintf(stderr, "The clock cycle is %d!\n", num); // Close the workgroup e_close(&dev); // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return 0; }
int main(int argc, char **argv) { struct ct_global_state *state = NULL; char *config_file = NULL; uint32_t cflags = CLOG_F_ENABLE | CLOG_F_STDERR; uint64_t debug_mask = 0; int ret; char *ctfile; /* setup arguments */ ct_setup_preinit(CT_INIT_ASSL | CT_INIT_CLOG | CT_INIT_EXUDE, cflags, debug_mask); if (argc < 2) { CFATALX("usage: %s <metadata file tag>", __progname); } ctfile = e_strdup(argv[1]); /* metadata file tag */ ct_setup_config(config_file, &state); ret = ct_do_delete(state, ctfile, CT_MATCH_GLOB); ct_cleanup_all(state, config_file); if (ctfile) e_free(&ctfile); return (ret); }
int ct_ssl_connect(struct ct_global_state *state) { struct ct_assl_io_ctx *ctx; struct assl_context *c; struct assl_connect_opts aco; int ret; ctx = e_calloc(1, sizeof (*ctx)); if ((c = assl_alloc_context(ASSL_M_TLSV1_CLIENT, 0)) == NULL) { e_free(&ctx); return (CTE_ASSL_CONTEXT); } if ((ret = ct_load_certs(state, c)) != 0) { /* free assl thingy */ e_free(&ctx); return (ret); } ct_assl_io_ctx_init(ctx, c, ct_handle_msg, ct_write_done, state, ct_header_alloc, ct_header_free, ct_body_alloc, ct_body_free, ct_ioctx_alloc, ct_ioctx_free); aco.aco_flags = ASSL_F_NONBLOCK|ASSL_F_KEEPALIVE|ASSL_F_THROUGHPUT, aco.aco_rcvbuf = state->ct_config->ct_sock_rcvbuf; aco.aco_sndbuf = state->ct_config->ct_sock_sndbuf; if (ct_assl_connect(ctx, state->ct_config->ct_host, state->ct_config->ct_hostport, &aco, ct_event_get_base(state->event_state))) { ct_assl_disconnect(ctx); e_free(&ctx); ctx = NULL; return (CTE_CONNECT_FAILED); } state->ct_assl_ctx = ctx; if (state->ct_config->ct_io_bw_limit && ctx != NULL) state->bw_limit = ct_ssl_init_bw_lim(ct_event_get_base(state->event_state), ctx, state->ct_config->ct_io_bw_limit); return (0); }
int main() { //counters for row and colum, cored id and loop counter unsigned row_loop,col_loop; // this will contain the epiphany platform configura tion e_platform_t epiphany; e_epiphany_t dev; e_mem_t memory; e_mem_t memory2; int message; int core1; int core2; int message2; e_return_stat_t result; e_init(NULL); // initialise the system establish connection to the Device e_reset_system(); // reset the epiphnay chip e_get_platform_info(&epiphany);//gets the configuration info for the parallella platofrm for(row_loop=0; row_loop <4; row_loop ++) { for(col_loop=0; col_loop <3; col_loop = col_loop+2) { //one core within the parallella work group is 1 x 2 i.e dual core e_open(&dev,row_loop,col_loop,1,2); //reset the group e_reset_group(&dev); //load the group result = e_load("hello_world.srec",&dev,0,0,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 1 %i\n", result); } result = e_load("hello_world2.srec",&dev,0,1,E_FALSE); if (result != E_OK) { fprintf(stderr,"Error Loading the Epiphany Application 2 %i\n", result); } e_start_group(&dev); usleep(10000); e_read(&dev,0,0,0x3000, &message, sizeof(int)); e_read(&dev,0,0,0x3004, &core1,sizeof(int)); e_read(&dev,0,1,0x3000, &message2, sizeof(int)); e_read(&dev,0,1,0x3004, &core2,sizeof(int)); fprintf(stderr,"message from core %d ", core1); fprintf(stderr,"core id = 0x%03x \n", message); fprintf(stderr,"message from core %d ", core2); fprintf(stderr,"core id = 0x%03x \n", message2); e_close(&dev); } } e_free(&memory); e_finalize(); return 0; }
struct ctdb_state * ctdb_setup(const char *path, int crypt_enabled) { struct ctdb_state *state; if (path == NULL) return (NULL); state = e_calloc(1, sizeof(*state)); state->ctdb_genid = -1; state->ctdb_crypt = crypt_enabled; state->ctdb_dbfile = e_strdup(path); if (ctdb_open(state) != 0) { e_free(&state->ctdb_dbfile); e_free(&state); } return (state); }
int main(int argc, char *argv[]) { int result, fail; fd = stderr; pEpiphany = &Epiphany; pERAM = &ERAM; e_set_host_verbosity(H_D0); if ( E_OK != e_init(NULL) ) { fprintf(stderr, "\nERROR: epiphinay initialization failed!\n\n"); exit(1); } if (E_OK != e_reset_system() ) { fprintf(stderr, "\nWARNING: epiphinay system rest failed!\n\n"); } // prepare ERAM if (E_OK != e_alloc(pERAM, 0x00000000, e_platform.emem[0].size)) { fprintf(stderr, "\nERROR: Can't allocate Epiphany DRAM!\n\n"); exit(1); } e_set_host_verbosity(H_D0); if (E_OK != e_open(pEpiphany, 0, 0, e_platform.rows, e_platform.cols)) { fprintf(stderr, "\nERROR: Can't establish connection to Epiphany device!\n\n"); exit(1); } fail = 0; ////////////////////////////// // Test Host-Device throughput SRAM_speed(); ERAM_speed(); DRAM_speed(); ///////////////////////////// // Test eCore-ERAM throughput result = EPI_speed(); //Finalize e_close(pEpiphany); e_free(pERAM); e_finalize(); ///////////////////////////// //For now, always pass return EXIT_SUCCESS; }
int ct_extract_setup(struct ct_extract_head *extract_head, struct ctfile_parse_state *ctx, const char *file, const char *ctfile_basedir, int *is_allfiles) { struct ct_extract_stack *nfile; char *prevlvl; int ret; if ((ret = ctfile_parse_init(ctx, file, ctfile_basedir)) != 0) return (ret); *is_allfiles = (ctx->xs_gh.cmg_flags & CT_MD_MLB_ALLFILES); if (ctx->xs_gh.cmg_prevlvl_filename) { nfile = e_malloc(sizeof(*nfile)); nfile->filename = e_strdup(file); TAILQ_INSERT_HEAD(extract_head, nfile, next); prevlvl = e_strdup(ctx->xs_gh.cmg_prevlvl_filename); ctfile_parse_close(ctx); if ((ret = ct_extract_setup_queue(extract_head, ctx, prevlvl, ctfile_basedir, *is_allfiles)) != 0) { int s_errno = errno; /* unwind */ e_free(&prevlvl); ct_extract_cleanup_queue(extract_head); errno = s_errno; return (ret); } e_free(&prevlvl); if (*is_allfiles) { ctfile_parse_close(ctx); /* reopen first file */ ret = ct_extract_open_next(extract_head, ctx); } } return (ret); }
int ct_rb_match(struct ct_match_tree *head, char *file) { struct ct_match_node *n, nfind; if (RB_EMPTY(head)) return (1); /* no pattern means nothing matches */ nfind.cmn_string = file; n = RB_FIND(ct_match_tree, head, &nfind); if (n == NULL) return (1); RB_REMOVE(ct_match_tree, head, n); e_free(&n->cmn_string); e_free(&n); return (0); }
void ct_matchlist_free(char **flist) { char **tmp = flist; while (*tmp != NULL) free(*(tmp++)); e_free(&flist); }
int ctfile_nextop_list_cleanup(struct ct_global_state *state, struct ct_op *op) { struct ct_extract_args *cea = op->op_args; if (cea->cea_local_ctfile) e_free(&cea->cea_local_ctfile); return (0); }
void ct_version_tree_free(struct ct_version_tree *tree) { /* Clean up children */ ct_version_tree_free_entry(&tree->cvt_head); ct_version_tree_free_ctfile_cache(&tree->cvt_ctfiles); e_free(&tree); }
int main(int argc, char *argv[]) { unsigned row, col, coreid, i; e_platform_t platform; e_epiphany_t dev; e_mem_t emem; char emsg[_BufSize]; srand(1); // initialize system, read platform params from // default HDF. Then, reset the platform and // get the actual system parameters. e_init(NULL); e_reset_system(); e_get_platform_info(&platform); // Allocate a buffer in shared external memory // for message passing from eCore to host. e_alloc(&emem, _BufOffset, _BufSize); for (i=0; i<_SeqLen; i++) { // Draw a random core row = rand() % platform.rows; col = rand() % platform.cols; coreid = (row + platform.row) * 64 + col + platform.col; fprintf(stderr, "%3d: Message from eCore 0x%03x (%2d,%2d): ", i, coreid, row, col); // Open the single-core workgroup and reset the core, in // case a previous process is running. Note that we used // core coordinates relative to the workgroup. e_open(&dev, row, col, 1, 1); e_reset_group(&dev); // Load the device program onto the selected eCore // and launch after loading. e_load("e_hello_world.srec", &dev, 0, 0, E_TRUE); // Wait for core program execution to finish, then // read message from shared buffer. usleep(100000000); e_read(&emem, 0, 0, 0x0, emsg, _BufSize); // Print the message and close the workgroup. fprintf(stderr, "\"%s\"\n", emsg); e_close(&dev); } // Release the allocated buffer and finalize the // e-platform connection. e_free(&emem); e_finalize(); return 0; }