Ejemplo n.º 1
0
END_TEST

START_TEST(cachestatus_empty)
{
	disable_logprints();
	cachestatus();
}
Ejemplo n.º 2
0
void filldatabaselist(DSTATE *s)
{
	DIR *dir;
	struct dirent *di;

	if ((dir=opendir(s->dirname))==NULL) {
		snprintf(errorstring, 512, "Unable to access database directory \"%s\" (%s), exiting.", s->dirname, strerror(errno));
		printe(PT_Error);

		/* clean daemon stuff before exit */
		if (s->rundaemon && !debug) {
			close(pidfile);
			unlink(cfg.pidfile);
		}
		ibwflush();
		exit(EXIT_FAILURE);
	}

	while ((di=readdir(dir))) {
		if ((di->d_name[0]=='.') || (strcmp(di->d_name, DATABASEFILE)==0)) {
			continue;
		}

		if (debug) {
			printf("\nProcessing file \"%s/%s\"...\n", s->dirname, di->d_name);
		}

		if (!cacheadd(di->d_name, s->sync)) {
			snprintf(errorstring, 512, "Cache memory allocation failed, exiting.");
			printe(PT_Error);

			/* clean daemon stuff before exit */
			if (s->rundaemon && !debug) {
				close(pidfile);
				unlink(cfg.pidfile);
			}
			ibwflush();
			exit(EXIT_FAILURE);
		}
		s->dbcount++;
	}

	closedir(dir);
	s->sync = 0;

	/* disable update interval check for one loop if database list was refreshed */
	/* otherwise increase default update interval since there's nothing else to do */
	if (s->dbcount) {
		s->updateinterval = 0;
		intsignal = 42;
		s->prevdbsave = s->current;
		/* list monitored interfaces to log */
		cachestatus();
	} else {
		s->updateinterval = 120;
	}
}
Ejemplo n.º 3
0
END_TEST

START_TEST(cachestatus_filled)
{
	initdb();
	disable_logprints();
	ck_assert_int_eq(cachecount(), 0);
	ck_assert_int_eq(cacheadd("name4", 0), 1);
	ck_assert_int_eq(cacheadd("name3", 0), 1);
	ck_assert_int_eq(cacheadd("name2", 0), 1);
	ck_assert_int_eq(cacheadd("name1", 0), 1);
	ck_assert_int_eq(cachecount(), 4);
	cachestatus();
}
Ejemplo n.º 4
0
END_TEST

START_TEST(cachestatus_full)
{
	int i;
	char buffer[8];
	initdb();
	defaultcfg();
	disable_logprints();
	ck_assert_int_eq(cachecount(), 0);
	for (i=1; i<=50; i++) {
		snprintf(buffer, 8, "name%d", i);
		ck_assert_int_eq(cacheadd(buffer, 0), 1);
		ck_assert_int_eq(ibwadd(buffer, 50-i), 1);
	}
	ck_assert_int_eq(cachecount(), 50);
	cachestatus();
}
Ejemplo n.º 5
0
void processdatalist(DSTATE *s)
{
	while (s->datalist!=NULL) {

		if (debug) {
			printf("d: processing %s (%d)...\n", s->datalist->data.interface, s->dodbsave);
		}

		/* get data from cache if available */
		if (!datalist_cacheget(s)) {
			s->datalist = s->datalist->next;
			continue;
		}

		/* get info if interface has been marked as active */
		datalist_getifinfo(s);

		/* check that the time is correct */
		if (!datalist_timevalidation(s)) {
			s->datalist = s->datalist->next;
			continue;
		}

		/* write data to file if now is the time for it */
		if (!datalist_writedb(s)) {
			/* remove interface from update list since the database file doesn't exist anymore */
			snprintf(errorstring, 512, "Database for interface \"%s\" no longer exists, removing from update list.", s->datalist->data.interface);
			printe(PT_Info);
			s->datalist = cacheremove(s->datalist->data.interface);
			s->dbcount--;
			cachestatus();
			continue;
		}

		s->datalist = s->datalist->next;
	}
}