예제 #1
0
int main(int argc, char **argv)
{
	unsigned long k;
	struct test_data *td;
	t_set_colors(0);
	t_start("fanout tests");

	run_tests(10, 64);
	run_tests(512, 64);
	run_tests(64, 64);
	run_tests(511, 17);

	destroyed = 0;
	fot = fanout_create(512);
	ok_int(fanout_remove(fot, 12398) == NULL, 1,
	       "remove on empty table must yield NULL");
	ok_int(fanout_get(fot, 123887987) == NULL, 1,
	       "get on empty table must yield NULL");
	for (k = 0; k < 16385; k++) {
		struct test_data *tdata = calloc(1, sizeof(*td));
		tdata->key = k;
		asprintf(&tdata->name, "%lu", k);
		fanout_add(fot, k, tdata);
	}
	td = fanout_get(fot, k - 1);
	ok_int(td != NULL, 1, "get must get what add inserts");
	ok_int(fanout_remove(fot, k + 1) == NULL, 1,
	       "remove on non-inserted key must yield NULL");
	ok_int(fanout_get(fot, k + 1) == NULL, 1,
	       "get on non-inserted must yield NULL");
	fanout_destroy(fot, pdest);
	ok_int((int)destroyed, (int)k, "destroy counter while free()'ing");

	return t_end();
}
예제 #2
0
파일: worker.c 프로젝트: ageric/nagios
static void destroy_job(child_process *cp)
{
	/*
	 * we must remove the job's timeout ticker,
	 * or we'll end up accessing an already free()'d
	 * pointer, or the pointer to a different child.
	 */
	squeue_remove(sq, cp->ei->sq_event);
	running_jobs--;
	fanout_remove(ptab, cp->ei->pid);

	if (cp->outstd.buf) {
		free(cp->outstd.buf);
		cp->outstd.buf = NULL;
	}
	if (cp->outerr.buf) {
		free(cp->outerr.buf);
		cp->outerr.buf = NULL;
	}

	kvvec_destroy(cp->request, KVVEC_FREE_ALL);
	free(cp->cmd);

	free(cp->ei);
	free(cp);
}
예제 #3
0
static void pdest(void *arg_)
{
	struct test_data *td = (struct test_data *)arg_;
	fanout_remove(fot, td->key);
	free(td->name);
	free(td);
	destroyed++;
}
예제 #4
0
void downtime_remove(scheduled_downtime *dt)
{
	fanout_remove(dt_fanout, dt->downtime_id);
	if(scheduled_downtime_list == dt)
		scheduled_downtime_list = dt->next;
	else {
		dt->prev->next = dt->next;
		if (dt->next)
			dt->next->prev = dt->prev;
	}
}
예제 #5
0
파일: workers.c 프로젝트: caidui/nagios4-cn
static void destroy_job(struct wproc_job *job)
{
	if (!job)
		return;

	switch (job->type) {
	case WPJOB_CHECK:
		free_check_result(job->arg);
		free(job->arg);
		break;
	case WPJOB_NOTIFY:
	case WPJOB_OCSP:
	case WPJOB_OCHP:
		free(job->arg);
		break;

	case WPJOB_GLOBAL_SVC_EVTHANDLER:
	case WPJOB_SVC_EVTHANDLER:
	case WPJOB_GLOBAL_HOST_EVTHANDLER:
	case WPJOB_HOST_EVTHANDLER:
	case WPJOB_HOST_PERFDATA:
	case WPJOB_SVC_PERFDATA:
		/* these require nothing special */
		break;
	case WPJOB_CALLBACK:
		/* call with NULL result to make callback clean things up */
		run_job_callback(job, NULL, 0);
		break;
	default:
		logit(NSLOG_RUNTIME_WARNING, TRUE, "wproc: Unknown job type: %d\n", job->type);
		break;
	}

	my_free(job->command);
	if (job->wp) {
		fanout_remove(job->wp->jobs, job->id);
		job->wp->jobs_running--;
	}
	loadctl.jobs_running--;

	free(job);
}
예제 #6
0
static void run_tests(int ntests, int fo_size)
{
	struct tcase *tc;
	unsigned long last_ptr, *ptr;
	int i, added = 0, removed = 0;
	fanout_table *fo;

	last_ptr = ntests;

	fo = fanout_create(fo_size);
	tc = calloc(ntests, sizeof(*tc));
	for (i = 0; i < ntests; i++) {
		tc[i].value = i;
		if (!fanout_add(fo, tc[i].key, &tc[i].value))
			added++;
	}
	ok_int(added, ntests, "Adding stuff must work");

	while ((ptr = (unsigned long *)fanout_remove(fo, 0))) {
		ok_int((int)*ptr, (int)last_ptr - 1, "Removing a bunch of them");
		removed++;
		last_ptr = *ptr;
	}
	ok_int(added, removed, "Removing should work as well as adding");
	fanout_destroy(fo, destructor);
	ok_int(destroyed, 0, "Expected no entries in destructor");

	fo = fanout_create(fo_size);
	for (i = 0; i < ntests; i++) {
		tc[i].value = i;
		if (!fanout_add(fo, tc[i].key, &tc[i].value))
			added++;
	}
	fanout_destroy(fo, destructor);
	ok_int(destroyed, ntests, "Expected ntest entries in destructor");
	destroyed = 0;
	free(tc);
}
예제 #7
0
static struct wproc_job *get_job(struct wproc_worker *wp, int job_id)
{
	return fanout_remove(wp->jobs, job_id);
}