Skip to content

Commit

Permalink
Merge pull request pi-hole#68 from pi-hole/development
Browse files Browse the repository at this point in the history
FTL v2.8
  • Loading branch information
DL6ER authored Jun 3, 2017
2 parents 31d6f87 + 66ebdef commit 62818c3
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 110 deletions.
1 change: 1 addition & 0 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef struct {
bool include_yesterday;
bool rolling_24h;
bool query_display;
bool analyze_AAAA;
} ConfigStruct;

// Dynamic structs
Expand Down
119 changes: 49 additions & 70 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Once you are used to it, you can skip most of the steps and debugging is actuall

#### Simplified debugging instructions (when `FTL` is running)

`FTL` has been designed such that a debugger can be attached to an already running process to ease debugging. Use `sudo gdb -p $(cat /var/run/pihole-FTL.pid)` to attach to the already running `pihole-FTL` process. You can leave off `sudo` if you are running `pihole-FTL` with the current user. Once loading of the symbols has finished (the `(gdb)` input prompt is shown), run `continue` to continue operation of `pihole-FTL` inside the debugger. All debugger features are now available.
`FTL` has been designed such that a debugger can be attached to an already running process to ease debugging. Use `sudo gdb -p $(pidof pihole-FTL)` to attach to an already running `pihole-FTL` process. You can leave off `sudo` if you are running `pihole-FTL` with the current user. Once loading of the symbols has finished (the `(gdb)` input prompt is shown), run `continue` to continue operation of `pihole-FTL` inside the debugger. All debugger features are now available.

If `pihole-FTL` has crashed, copy&paste the terminal output into a (new) issue. Also type `backtrace` and include its output. We might ask for additional information in order to isolate your particular issue.

Expand Down Expand Up @@ -102,6 +102,7 @@ Possible settings (the first one is the default setting):
- `SOCKET_LISTENING=localonly|all` (listen only for local connections or permit all connections)
- `TIMEFRAME=rolling24h|yesterday|today` (rolling data window, up to 48h (today + yesterday), or up to 24h (only today, as in Pi-hole `v2.x` ))
- `QUERY_DISPLAY=yes|no` (hide queries altogether)
- `analyze_AAAA=yes|no` (do we want `FTL` to analyze AAAA queries from pihole.log?)

### Implemented keywords (starting with `>`, subject to change):

Expand Down
14 changes: 14 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ void read_FTLconf(void)
else
logg(" QUERY_DISPLAY: Hide queries");

// AAAA_QUERY_ANALYSIS
// defaults to: Yes
config.analyze_AAAA = true;
buffer = parse_FTLconf(fp, "AAAA_QUERY_ANALYSIS");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.analyze_AAAA = false;
}
if(config.analyze_AAAA)
logg(" AAAA_QUERY_ANALYSIS: Show AAAA queries");
else
logg(" AAAA_QUERY_ANALYSIS: Hide AAAA queries");

logg("Finished config file parsing");

if(conflinebuffer != NULL)
Expand Down
4 changes: 2 additions & 2 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void *GC_thread(void *val)

// Lock FTL's data structure, since it is likely that it will be changed here
// Requests should not be processed/answered when data is about to change
enable_read_write_lock("GC_thread");
enable_thread_lock("GC_thread");

// Get minimum time stamp to keep
int differencetofullhour = time(NULL) % GCinterval;
Expand Down Expand Up @@ -141,7 +141,7 @@ void *GC_thread(void *val)
}

// Release thread lock
disable_thread_locks("GC_thread");
disable_thread_lock("GC_thread");


return NULL;
Expand Down
10 changes: 8 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void *pihole_log_thread(void *val)
{
// Lock FTL's data structure, since it is likely that it will be changed here
// Requests should not be processed/answered when data is about to change
enable_read_write_lock("pihole_log_thread");
enable_thread_lock("pihole_log_thread");

if(newdata > 0 && !flush)
{
Expand All @@ -123,7 +123,7 @@ void *pihole_log_thread(void *val)
}

// Release thread lock
disable_thread_locks("pihole_log_thread");
disable_thread_lock("pihole_log_thread");
}

// Wait some time before looking again at the log files
Expand Down Expand Up @@ -198,6 +198,12 @@ void process_pihole_log(int file)
continue;
}

if(!config.analyze_AAAA && strstr(readbuffer,"]: query[AAAA]") != NULL)
{
if(debug) logg("Not analyzing AAAA query");
continue;
}

// Get timestamp
int querytimestamp, overTimetimestamp;
extracttimestamp(readbuffer, &querytimestamp, &overTimetimestamp);
Expand Down
5 changes: 2 additions & 3 deletions routines.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ void parse_args(int argc, char* argv[]);

char* find_equals(const char* s);

void enable_read_lock(const char *message);
void enable_read_write_lock(const char *message);
void disable_thread_locks(const char *message);
void enable_thread_lock(const char *message);
void disable_thread_lock(const char *message);

void read_FTLconf(void);

Expand Down
6 changes: 4 additions & 2 deletions setupVars.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ char* find_equals(const char* s)
// actually point to memory addresses
// which we allocate for this buffer.
char * linebuffer = NULL;
size_t linebuffersize = 0;

char * read_setupVarsconf(const char * key)
{
Expand All @@ -63,9 +64,8 @@ char * read_setupVarsconf(const char * key)
}
sprintf(keystr, "%s=", key);

size_t size;
errno = 0;
while(getline(&linebuffer, &size, setupVarsfp) != -1)
while(getline(&linebuffer, &linebuffersize, setupVarsfp) != -1)
{
// Strip (possible) newline
linebuffer[strcspn(linebuffer, "\n")] = '\0';
Expand Down Expand Up @@ -97,6 +97,7 @@ char * read_setupVarsconf(const char * key)
if(linebuffer != NULL)
{
free(linebuffer);
linebuffersize = 0;
linebuffer = NULL;
}

Expand Down Expand Up @@ -141,6 +142,7 @@ void clearSetupVarsArray(void)
if(linebuffer != NULL)
{
free(linebuffer);
linebuffersize = 0;
linebuffer = NULL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ void *connection_handler_thread(void *socket_desc)

// Lock FTL data structure, since it is likely that it will be changed here
// Requests should not be processed/answered when data is about to change
enable_read_lock(threadname);
enable_thread_lock(threadname);

process_request(message, &sock);
free(message);

// Release thread lock
disable_thread_locks("connection_handler_thread");
disable_thread_lock(threadname);

if(sock == 0)
{
Expand Down
37 changes: 9 additions & 28 deletions threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,24 @@
// Logic of the locks:
// Any of the various threads (logparser, GC, client threads) is accessing FTL's data structure. Hence, they should
// never run at the same time since the data can change half-way through, leading to unspecified behavior.
// threadwritelock: The threadwritelock ensures that only one thread with write-access to FTL's data structure can
// be active at any given time
// threadreadlock: An expection to the rule of non-concurrency are the client threads, as they do need read-access
// Therefore, it is no problem to have several of them running concurrently. Accordingly, client
// threads do *not* have to wait at the lock if threadreadlocks is true (i.e. a client listener
// thread has activated this thread lock earlier)
bool threadwritelock = false;
bool threadreadlock = false;
// threadlock: The threadlock ensures that only one thread can be active at any given time
bool threadlock = false;

void enable_read_lock(const char *message)
void enable_thread_lock(const char *message)
{
while(threadwritelock) sleepms(5);
while(threadlock) sleepms(5);

if(debugthreads)
logg("Thread lock enabled (R ): %s", message);
logg("Thread lock enabled: %s", message);

// Set threadwritelock
threadwritelock = false;
// Set threadreadlock (see above)
threadreadlock = true;
// Set threadlock
threadlock = true;
}

void enable_read_write_lock(const char *message)
void disable_thread_lock(const char *message)
{
while(threadwritelock || threadreadlock) sleepms(5);
threadlock = false;

if(debugthreads)
logg("Thread lock enabled (RW): %s", message);

// Set threadwritelock
threadwritelock = true;
}

void disable_thread_locks(const char *message)
{
threadwritelock = false;
threadreadlock = false;
if(debugthreads)
logg("Thread lock disabled: %s", message);
}

0 comments on commit 62818c3

Please sign in to comment.