gint slave_free(Slave* slave) { MAGIC_ASSERT(slave); gint returnCode = (slave->numPluginErrors > 0) ? -1 : 0; /* this launches delete on all the plugins and should be called before * the engine is marked "killed" and workers are destroyed. */ g_hash_table_destroy(slave->hosts); /* we will never execute inside the plugin again */ slave->forceShadowContext = TRUE; if(slave->topology) { topology_free(slave->topology); } if(slave->dns) { dns_free(slave->dns); } g_hash_table_destroy(slave->programs); g_mutex_clear(&(slave->lock)); g_mutex_clear(&(slave->pluginInitLock)); /* join and free spawned worker threads */ //TODO if(slave->cwdPath) { g_free(slave->cwdPath); } if(slave->dataPath) { g_free(slave->dataPath); } if(slave->hostsPath) { g_free(slave->hostsPath); } /* free main worker */ worker_free(slave->mainThreadWorker); MAGIC_CLEAR(slave); g_free(slave); return returnCode; }
void master_free(Master* master) { MAGIC_ASSERT(master); if(master->topology) { topology_free(master->topology); } if(master->dns) { dns_free(master->dns); } if(master->config) { configuration_free(master->config); } if(master->random) { random_free(master->random); } MAGIC_CLEAR(master); g_free(master); message("simulation master destroyed"); }
struct topology *infer_bidi_topology( struct cfg_intern *def, struct inf_context *ctx) { struct cfg_m_str_a_str *layout; layout = inf_get_layout(ctx, def->layout); if(!layout) { return NULL; } struct topology *self = topology_new(); if(!self) return NULL; self->default_port = def->port; struct cfg_a_str *conn; for(conn = layout->val; conn; conn = conn->next) { char bindrole[25]; char connrole[25]; int source; if(sscanf(conn->val, "%24s -> %24s", bindrole, connrole) == 2) { source = 0; } else if(sscanf(conn->val, "%24s <- %24s", bindrole, connrole) == 2) { source = 1; } else { err_add_fatal(&ctx->err, "Bad layout rule \"%s\"\n", conn->val); continue; } struct role *bindr = roleht_get(&self->roles, bindrole); if(!bindr) { bindr = malloc(sizeof(struct role)); if(!bindr) goto memory_error; memcpy(bindr->name, bindrole, sizeof(bindrole)); rrules_init(&bindr->source_rules); rrules_init(&bindr->sink_rules); if(roleht_set(&self->roles, bindr->name, bindr) < 0) { free(bindr); goto memory_error; } } struct role *connr = roleht_get(&self->roles, connrole); if(!connr) { connr = malloc(sizeof(struct role)); if(!connr) goto memory_error; memcpy(connr->name, connrole, sizeof(connrole)); rrules_init(&connr->source_rules); rrules_init(&connr->sink_rules); if(roleht_set(&self->roles, connr->name, connr) < 0) { free(connr); goto memory_error; } } struct role_endpoint *ep1; struct role_endpoint *ep2; if(source == 0) { ep1 = rrules_add_endpoint(&bindr->source_rules, 0); ep2 = rrules_add_endpoint(&connr->sink_rules, 1); } else { ep1 = rrules_add_endpoint(&bindr->sink_rules, 0); ep2 = rrules_add_endpoint(&connr->source_rules, 1); } ep1->peer = ep2; ep2->peer = ep1; } struct cfg_m_str_a_str *roleip; for(roleip = def->ip_addresses; roleip; roleip = roleip->next) { struct role *role = roleht_get(&self->roles, roleip->key); if(!role) { err_add_fatal(&ctx->err, "Assignment for non-existent role \"%s\"\n", roleip->key); continue; } struct cfg_a_str *ip; for(ip = roleip->val; ip; ip = ip->next) { if(role_add_ip(role, ip->val) < 0) goto memory_error; } } /* TODO(tailhook) check that all endpoints to bind are assigned */ return self; memory_error: topology_free(self); return NULL; }