Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not block shared memory when inactive upstreams are skipped #893

Merged
merged 2 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos)
}

// Resolve client host names
void resolveClients(const bool onlynew)
static void resolveClients(const bool onlynew)
{
const time_t now = time(NULL);
// Lock counter access here, we use a copy in the following loop
Expand All @@ -358,6 +358,7 @@ void resolveClients(const bool onlynew)
{
logg("ERROR: Unable to get client pointer (1) with ID %i, skipping...", clientID);
skipped++;
unlock_shm();
continue;
}

Expand Down Expand Up @@ -401,6 +402,7 @@ void resolveClients(const bool onlynew)
{
logg("ERROR: Unable to get client pointer (2) with ID %i, skipping...", clientID);
skipped++;
unlock_shm();
continue;
}

Expand All @@ -419,7 +421,7 @@ void resolveClients(const bool onlynew)
}

// Resolve upstream destination host names
void resolveForwardDestinations(const bool onlynew)
static void resolveUpstreams(const bool onlynew)
{
const time_t now = time(NULL);
// Lock counter access here, we use a copy in the following loop
Expand All @@ -438,6 +440,7 @@ void resolveForwardDestinations(const bool onlynew)
{
logg("ERROR: Unable to get upstream pointer with ID %i, skipping...", upstreamID);
skipped++;
unlock_shm();
continue;
}

Expand All @@ -454,6 +457,7 @@ void resolveForwardDestinations(const bool onlynew)
logg("Skipping upstream %s (%s) because it was inactive for %i seconds",
getstr(ippos), getstr(oldnamepos), (int)(now - upstream->lastQuery));
}
unlock_shm();
continue;
}
unlock_shm();
Expand All @@ -479,6 +483,7 @@ void resolveForwardDestinations(const bool onlynew)
{
logg("ERROR: Unable to get upstream pointer with ID %i, skipping...", upstreamID);
skipped++;
unlock_shm();
continue;
}

Expand Down Expand Up @@ -512,7 +517,7 @@ void *DNSclient_thread(void *val)
// Try to resolve new client host names (onlynew=true)
resolveClients(true);
// Try to resolve new upstream destination host names (onlynew=true)
resolveForwardDestinations(true);
resolveUpstreams(true);
// Prevent immediate re-run of this routine
sleepms(500);
}
Expand All @@ -527,7 +532,7 @@ void *DNSclient_thread(void *val)
// Try to resolve all client host names (onlynew=false)
resolveClients(false);
// Try to resolve all upstream destination host names (onlynew=false)
resolveForwardDestinations(false);
resolveUpstreams(false);
// Try to resolve host names from clients in the network table
// which have empty/undefined host names
resolveNetworkTableNames();
Expand Down
2 changes: 0 additions & 2 deletions src/resolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

void *DNSclient_thread(void *val);
char *resolveHostname(const char *addr);
void resolveClients(const bool onlynew);
void resolveForwardDestinations(const bool onlynew);

// musl does not define MAXHOSTNAMELEN
// If it is not defined, we set the value
Expand Down