/* * When a client needs to be terminated then the file descriptors for * its input/output are simply closed. This leads to a graceful * degradation, but may take some time when the client is busy. A more * forcefull method is to kill the client thread, but this may leave * locks and semaphores in an undesirable state. * * The routine freeClient ends a single client session, but through side * effects of sharing IO descriptors, also its children. Conversely, a * child can not close a parent. */ void MCfreeClient(Client c) { c->mode = FINISHCLIENT; #ifdef MAL_CLIENT_DEBUG fprintf(stderr,"# Free client %d\n", c->idx); #endif MCexitClient(c); /* scope list and curprg can not be removed, because the client may * reside in a quit() command. Therefore the scopelist is re-used. */ c->scenario = NULL; if (c->prompt) GDKfree(c->prompt); c->prompt = NULL; c->promptlength = -1; if (c->errbuf) { /* no client threads in embedded mode */ #ifndef HAVE_EMBEDDED GDKsetbuf(0); #endif if (c->father == NULL) GDKfree(c->errbuf); c->errbuf = 0; } if (c->usermodule) freeModule(c->usermodule); c->usermodule = c->curmodule = 0; c->father = 0; c->login = c->lastcmd = 0; //c->active = 0; c->qtimeout = 0; c->stimeout = 0; c->user = oid_nil; if( c->username){ GDKfree(c->username); c->username = 0; } c->mythread = 0; if (c->glb) { freeStack(c->glb); c->glb = NULL; } if( c->error_row){ BBPrelease(c->error_row->batCacheid); BBPrelease(c->error_fld->batCacheid); BBPrelease(c->error_msg->batCacheid); BBPrelease(c->error_input->batCacheid); c->error_row = c->error_fld = c->error_msg = c->error_input = NULL; } if( c->wlc) freeMalBlk(c->wlc); c->wlc_kind = 0; c->wlc = NULL; MT_sema_destroy(&c->s); c->mode = MCshutdowninprogress()? BLOCKCLIENT: FREECLIENT; }
Client MCinitClientRecord(Client c, oid user, bstream *fin, stream *fout) { str prompt; c->user = user; c->username = 0; c->scenario = NULL; c->oldscenario = NULL; c->srcFile = NULL; c->blkmode = 0; c->fdin = fin ? fin : bstream_create(GDKin, 0); c->yycur = 0; c->bak = NULL; c->listing = 0; c->fdout = fout ? fout : GDKstdout; c->mdb = 0; c->history = 0; c->curprg = c->backup = 0; c->glb = 0; /* remove garbage from previous connection */ if (c->nspace) { freeModule(c->nspace); c->nspace = 0; } c->father = NULL; c->login = c->lastcmd = time(0); //c->active = 0; c->session = GDKusec(); c->qtimeout = 0; c->stimeout = 0; c->stage = 0; c->itrace = 0; c->debugOptimizer = c->debugScheduler = 0; c->flags = MCdefault; c->errbuf = 0; prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1; c->prompt = GDKstrdup(prompt); c->promptlength = strlen(prompt); c->actions = 0; c->totaltime = 0; /* create a recycler cache */ c->exception_buf_initialized = 0; c->error_row = c->error_fld = c->error_msg = c->error_input = NULL; (void) AUTHgetUsername(&c->username, c); MT_sema_init(&c->s, 0, "Client->s"); return c; }
Client MCinitClientRecord(Client c, oid user, bstream *fin, stream *fout) { str prompt; c->user = user; c->scenario = NULL; c->oldscenario = NULL; c->srcFile = NULL; c->blkmode = 0; c->fdin = fin ? fin : bstream_create(GDKin, 0); c->yycur = 0; c->bak = NULL; c->listing = 0; c->fdout = fout ? fout : GDKstdout; c->mdb = 0; c->history = 0; c->curprg = c->backup = 0; c->glb = 0; /* remove garbage from previous connection */ if (c->nspace) { freeModule(c->nspace); c->nspace = 0; } c->father = NULL; c->login = c->lastcmd = time(0); c->qtimeout = 0; c->stimeout = 0; c->stage = 0; c->itrace = 0; c->debugOptimizer = c->debugScheduler = 0; c->flags = MCdefault; c->timer = 0; c->memory = 0; c->errbuf = 0; prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1; c->prompt = GDKstrdup(prompt); c->promptlength = strlen(prompt); c->actions = 0; c->totaltime = 0; c->rcc = (RecPtr) GDKzalloc(sizeof(RecStat)); c->rcc->curQ = -1; c->exception_buf_initialized = 0; MT_sema_init(&c->s, 0, "MCinitClient"); return c; }
/* Remove all globally known functions */ void mal_module_reset(void) { int i; Module m; #ifdef _DEBUG_MODULE_ fprintf(stderr,"#et the globale module structure \n"); #endif for(i = 0; i < MODULE_HASH_SIZE; i++) { m= moduleIndex[i]; moduleIndex[i] = 0; while(m) { Module next = m->link; freeModule(m); m = next; } } }
void unloadEIOSClient(EIOSClient *client) { freeModule(client->libHandle); memset(client, 0, sizeof(EIOSClient)); }
static rpmRC processPolicies(rpmSpec spec, Package pkg, int test) { const char *path = NULL; char *name = NULL; char *types = NULL; uint32_t flags = 0; poptContext optCon = NULL; rpmRC rc = RPMRC_FAIL; struct poptOption optionsTable[] = { {"name", 'n', POPT_ARG_STRING, &name, 'n', NULL, NULL}, {"types", 't', POPT_ARG_STRING, &types, 't', NULL, NULL}, {"base", 'b', POPT_ARGFLAG_OR, &flags, RPMPOL_FLAG_BASE, NULL, NULL}, POPT_TABLEEND }; if (!spec || !pkg) { goto exit; } for (ARGV_const_t pol = pkg->policyList; *pol != NULL; pol++) { ModuleRec mod; const char *line = *pol; const char **argv = NULL; int argc = 0; int err; if ((err = poptParseArgvString(line, &argc, &argv))) { rpmlog(RPMLOG_ERR, _("Error parsing %s: %s\n"), line, poptStrerror(err)); goto exit; } if (!rstreq(argv[0], "%semodule")) { rpmlog(RPMLOG_ERR, _("Expecting %%semodule tag: %s\n"), line); goto exit; } optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while (poptGetNextOpt(optCon) > 0) { } path = poptGetArg(optCon); if (!path) { rpmlog(RPMLOG_ERR, _("Missing module path in line: %s\n"), line); goto exit; } if (poptPeekArg(optCon)) { rpmlog(RPMLOG_ERR, _("Too many arguments in line: %s\n"), line); goto exit; } mod = newModule(path, name, types, flags); if (!mod) { goto exit; } if (writeModuleToHeader(mod, pkg) != RPMRC_OK) { freeModule(mod); goto exit; } freeModule(mod); } rc = RPMRC_OK; exit: return rc; }
static ModuleRec newModule(const char *path, const char *name, const char *types, uint32_t flags) { ModuleRec mod; uint8_t *raw = NULL; ssize_t rawlen = 0; const char *buildDir = "%{_builddir}/%{?buildsubdir}/"; if (!path) { rpmlog(RPMLOG_ERR, _("%%semodule requires a file path\n")); return NULL; } mod = xcalloc(1, sizeof(*mod)); mod->path = rpmGenPath(buildDir, NULL, path); if ((rpmioSlurp(mod->path, &raw, &rawlen)) != 0 || raw == NULL) { rpmlog(RPMLOG_ERR, _("Failed to read policy file: %s\n"), mod->path); goto err; } mod->data = b64encode(raw, rawlen, -1); if (!mod->data) { rpmlog(RPMLOG_ERR, _("Failed to encode policy file: %s\n"), mod->path); goto err; } if (name) { mod->name = xstrdup(name); } else { /* assume base name (minus extension) if name is not given */ char *tmp = xstrdup(mod->path); char *bname = basename(tmp); char *end = strchr(bname, '.'); if (end) *end = '\0'; if (strlen(bname) > 0) { mod->name = xstrdup(bname); } else { rpmlog(RPMLOG_ERR, _("Failed to determine a policy name: %s\n"), mod->path); _free(tmp); goto err; } _free(tmp); } if (types) { mod->types = argvSplitString(types, ",", ARGV_SKIPEMPTY); argvSort(mod->types, NULL); if (argvSearch(mod->types, RPMPOL_TYPE_DEFAULT, NULL) && argvCount(mod->types) > 1) { rpmlog(RPMLOG_WARNING, _("'%s' type given with other types in %%semodule %s. Compacting types to '%s'.\n"), RPMPOL_TYPE_DEFAULT, mod->path, RPMPOL_TYPE_DEFAULT); mod->types = argvFree(mod->types); argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT); } } else { argvAdd(&mod->types, RPMPOL_TYPE_DEFAULT); } mod->flags = flags; return mod; err: freeModule(mod); return NULL; }
~SysModule() { if(hLib) freeModule(); }