static void Apoptosis() { Promise pp = { 0 }; Rlist *signals = NULL, *owners = NULL; char mypid[32]; static char promiser_buf[CF_SMALLBUF]; #if defined(_WIN32) return; #endif CfOut(OUTPUT_LEVEL_VERBOSE, "", " !! Programmed pruning of the scheduler cluster"); #ifdef __MINGW32__ snprintf(promiser_buf, sizeof(promiser_buf), "cf-execd"); // using '\' causes regexp problems #else snprintf(promiser_buf, sizeof(promiser_buf), "%s/bin/cf-execd", CFWORKDIR); #endif pp.promiser = promiser_buf; pp.promisee = (Rval) {"cfengine", RVAL_TYPE_SCALAR}; pp.classes = "any"; pp.offset.line = 0; pp.audit = NULL; pp.conlist = SeqNew(100, ConstraintDestroy); pp.bundletype = "agent"; pp.bundle = "exec_apoptosis"; pp.ref = "Programmed death"; pp.agentsubtype = "processes"; pp.done = false; pp.cache = NULL; pp.inode_cache = NULL; pp.this_server = NULL; pp.donep = &(pp.done); pp.conn = NULL; GetCurrentUserName(mypid, 31); RlistPrepend(&signals, "term", RVAL_TYPE_SCALAR); RlistPrepend(&owners, mypid, RVAL_TYPE_SCALAR); PromiseAppendConstraint(&pp, "signals", (Rval) {signals, RVAL_TYPE_LIST }, "any", false); PromiseAppendConstraint(&pp, "process_select", (Rval) {xstrdup("true"), RVAL_TYPE_SCALAR}, "any", false); PromiseAppendConstraint(&pp, "process_owner", (Rval) {owners, RVAL_TYPE_LIST }, "any", false); PromiseAppendConstraint(&pp, "ifelapsed", (Rval) {xstrdup("0"), RVAL_TYPE_SCALAR}, "any", false); PromiseAppendConstraint(&pp, "process_count", (Rval) {xstrdup("true"), RVAL_TYPE_SCALAR}, "any", false); PromiseAppendConstraint(&pp, "match_range", (Rval) {xstrdup("0,2"), RVAL_TYPE_SCALAR}, "any", false); PromiseAppendConstraint(&pp, "process_result", (Rval) {xstrdup("process_owner.process_count"), RVAL_TYPE_SCALAR}, "any", false); CfOut(OUTPUT_LEVEL_VERBOSE, "", " -> Looking for cf-execd processes owned by %s", mypid); if (LoadProcessTable(&PROCESSTABLE)) { VerifyProcessesPromise(&pp); } DeleteItemList(PROCESSTABLE); SeqDestroy(pp.conlist); CfOut(OUTPUT_LEVEL_VERBOSE, "", " !! Pruning complete"); }
static void KeepAgentPromise(Promise *pp, const ReportContext *report_context) { char *sp = NULL; struct timespec start = BeginMeasure(); if (!IsDefinedClass(pp->classes, pp->ns)) { CfOut(cf_verbose, "", "\n"); CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"); CfOut(cf_verbose, "", "Skipping whole next promise (%s), as context %s is not relevant\n", pp->promiser, pp->classes); CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"); return; } if (pp->done) { return; } if (VarClassExcluded(pp, &sp)) { CfOut(cf_verbose, "", "\n"); CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"); CfOut(cf_verbose, "", "Skipping whole next promise (%s), as var-context %s is not relevant\n", pp->promiser, sp); CfOut(cf_verbose, "", ". . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"); return; } if (MissingDependencies(pp)) { return; } // Record promises examined for efficiency calc if (strcmp("meta", pp->agentsubtype) == 0) { char ns[CF_BUFSIZE]; snprintf(ns,CF_BUFSIZE,"%s_meta",pp->bundle); NewScope(ns); ConvergeVarHashPromise(ns, pp, true); return; } if (strcmp("vars", pp->agentsubtype) == 0) { ConvergeVarHashPromise(pp->bundle, pp, true); return; } if (strcmp("defaults", pp->agentsubtype) == 0) { DefaultVarPromise(pp); return; } if (strcmp("classes", pp->agentsubtype) == 0) { KeepClassContextPromise(pp); return; } if (strcmp("outputs", pp->agentsubtype) == 0) { VerifyOutputsPromise(pp); return; } SetPromiseOutputs(pp); if (strcmp("interfaces", pp->agentsubtype) == 0) { VerifyInterfacesPromise(pp); return; } if (strcmp("processes", pp->agentsubtype) == 0) { VerifyProcessesPromise(pp); return; } if (strcmp("storage", pp->agentsubtype) == 0) { FindAndVerifyStoragePromises(pp, report_context); EndMeasurePromise(start, pp); return; } if (strcmp("packages", pp->agentsubtype) == 0) { VerifyPackagesPromise(pp); EndMeasurePromise(start, pp); return; } if (strcmp("files", pp->agentsubtype) == 0) { if (GetBooleanConstraint("background", pp)) { ParallelFindAndVerifyFilesPromises(pp, report_context); } else { FindAndVerifyFilesPromises(pp, report_context); } EndMeasurePromise(start, pp); return; } if (strcmp("commands", pp->agentsubtype) == 0) { VerifyExecPromise(pp); EndMeasurePromise(start, pp); return; } if (strcmp("databases", pp->agentsubtype) == 0) { VerifyDatabasePromises(pp); EndMeasurePromise(start, pp); return; } if (strcmp("methods", pp->agentsubtype) == 0) { VerifyMethodsPromise(pp, report_context); EndMeasurePromise(start, pp); return; } if (strcmp("services", pp->agentsubtype) == 0) { VerifyServicesPromise(pp, report_context); EndMeasurePromise(start, pp); return; } if (strcmp("guest_environments", pp->agentsubtype) == 0) { VerifyEnvironmentsPromise(pp); EndMeasurePromise(start, pp); return; } if (strcmp("reports", pp->agentsubtype) == 0) { VerifyReportPromise(pp); return; } }