Files
FTL/structs.c
T

120 lines
3.1 KiB
C

/* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* FTL Engine
* Global variable definitions and memory reallocation handling
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#include "FTL.h"
FTLFileNamesStruct FTLfiles = {
"/var/log/pihole-FTL.log",
"/var/run/pihole-FTL.pid",
"/var/run/pihole-FTL.port"
};
logFileNamesStruct files = {
"/var/log/pihole.log",
"/var/log/pihole.log.1",
"/etc/pihole/list.preEventHorizon",
"/etc/pihole/whitelist.txt",
"/etc/pihole/blacklist.txt",
"/etc/pihole/setupVars.conf",
"/etc/dnsmasq.d/03-pihole-wildcard.conf"
};
countersStruct counters = { 0 };
void memory_check(int which)
{
switch(which)
{
case QUERIES:
if(counters.queries >= counters.queries_MAX)
{
// Have to reallocate memory
counters.queries_MAX += QUERIESALLOCSTEP;
if(debug)
logg_struct_resize("queries",counters.queries_MAX,QUERIESALLOCSTEP);
queries = realloc(queries, counters.queries_MAX*sizeof(*queries));
if(queries == NULL)
{
logg("FATAL: Memory allocation failed! Exiting");
free(queries);
exit(EXIT_FAILURE);
}
}
break;
case FORWARDED:
if(counters.forwarded >= counters.forwarded_MAX)
{
// Have to reallocate memory
counters.forwarded_MAX += FORWARDEDALLOCSTEP;
if(debug)
logg_struct_resize("forwarded",counters.forwarded_MAX,FORWARDEDALLOCSTEP);
forwarded = realloc(forwarded, counters.forwarded_MAX*sizeof(*forwarded));
if(forwarded == NULL)
{
logg("FATAL: Memory allocation failed! Exiting");
free(forwarded);
exit(EXIT_FAILURE);
}
}
break;
case CLIENTS:
if(counters.clients >= counters.clients_MAX)
{
// Have to reallocate memory
counters.clients_MAX += CLIENTSALLOCSTEP;
if(debug)
logg_struct_resize("clients",counters.clients_MAX,CLIENTSALLOCSTEP);
clients = realloc(clients, counters.clients_MAX*sizeof(*clients));
if(clients == NULL)
{
logg("FATAL: Memory allocation failed! Exiting");
free(clients);
exit(EXIT_FAILURE);
}
}
break;
case DOMAINS:
if(counters.domains >= counters.domains_MAX)
{
// Have to reallocate memory
counters.domains_MAX += DOMAINSALLOCSTEP;
if(debug)
logg_struct_resize("domains",counters.domains_MAX,DOMAINSALLOCSTEP);
domains = realloc(domains, counters.domains_MAX*sizeof(*domains));
if(domains == NULL)
{
logg("FATAL: Memory allocation failed! Exiting");
free(domains);
exit(EXIT_FAILURE);
}
}
break;
case OVERTIME:
if(counters.overTime >= counters.overTime_MAX)
{
// Have to reallocate memory
counters.overTime_MAX += OVERTIMEALLOCSTEP;
if(debug)
logg_struct_resize("overTime",counters.overTime_MAX,OVERTIMEALLOCSTEP);
overTime = realloc(overTime, counters.overTime_MAX*sizeof(*overTime));
if(overTime == NULL)
{
logg("FATAL: Memory allocation failed! Exiting");
free(overTime);
exit(EXIT_FAILURE);
}
}
break;
default:
/* That cannot happen */
break;
}
}