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

Fix fork shared memory access #2121

Merged
merged 2 commits into from
Nov 18, 2024
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
15 changes: 12 additions & 3 deletions src/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ static void remap_shm(void)
realloc_shm(&shm_strings, counters->strings_MAX, sizeof(char), false);
// strings are not exposed by a global pointer

realloc_shm(&shm_domains_lookup, counters->domains_lookup_MAX, sizeof(struct lookup_table), false);
domains_lookup = (struct lookup_table*)shm_domains_lookup.ptr;

realloc_shm(&shm_clients_lookup, counters->clients_lookup_MAX, sizeof(struct lookup_table), false);
clients_lookup = (struct lookup_table*)shm_clients_lookup.ptr;

realloc_shm(&shm_dns_cache_lookup, counters->dns_cache_lookup_MAX, sizeof(struct lookup_table), false);
dns_cache_lookup = (struct lookup_table*)shm_dns_cache_lookup.ptr;

// Update local counter to reflect that we absorbed this change
local_shm_counter = shmSettings->global_shm_counter;
}
Expand Down Expand Up @@ -1010,7 +1019,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->clients >= counters->clients_lookup_MAX-1)
if(counters->clients_lookup_size >= counters->clients_lookup_MAX-1)
{
// Have to reallocate shared memory
clients_lookup = enlarge_shmem_struct(CLIENTS_LOOKUP);
Expand All @@ -1020,7 +1029,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->domains >= counters->domains_lookup_MAX-1)
if(counters->domains_lookup_size >= counters->domains_lookup_MAX-1)
{
// Have to reallocate shared memory
domains_lookup = enlarge_shmem_struct(DOMAINS_LOOKUP);
Expand All @@ -1030,7 +1039,7 @@ void shm_ensure_size(void)
exit(EXIT_FAILURE);
}
}
if(counters->dns_cache_size >= counters->dns_cache_lookup_MAX-1)
if(counters->dns_cache_lookup_size >= counters->dns_cache_lookup_MAX-1)
{
// Have to reallocate shared memory
dns_cache_lookup = enlarge_shmem_struct(DNS_CACHE_LOOKUP);
Expand Down
2 changes: 1 addition & 1 deletion src/shmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static bool create_shm(const char *name, SharedMemory *sharedMemory, const size_
/// \param sharedMemory the shared memory struct
/// \param size1 the new size (factor 1)
/// \param size2 the new size (factor 2)
/// \param resize whether the object should be resized or only remapped
/// \param resize whether the object should be resized (true) or only remapped (false)
/// \return if reallocation was successful
static bool realloc_shm(SharedMemory *sharedMemory, const size_t size1, const size_t size2, const bool resize);

Expand Down
Loading