Skip to content

Commit

Permalink
Merge pull request #2256 from iain-henderson/feature/dev-posix-enviro…
Browse files Browse the repository at this point in the history
…nment

Update config/env.c to accept conventional environment variables in a…
  • Loading branch information
DL6ER authored Feb 24, 2025
2 parents 22175ec + c6d0b80 commit 45d0c8a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/config/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ void printFTLenv(void)

static struct env_item *__attribute__((pure)) getFTLenv(const char *key)
{
// "Normalize" the environment variable to conventional names by using a case insensitive comparison,
// See: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
// Iterate over all known FTLCONF environment variables
for(struct env_item *item = env_list; item != NULL; item = item->next)
{
// Check if this is the requested key
if(strcmp(item->key, key) == 0)
if(strcasecmp(item->key, key) == 0)
return item;
}

Expand Down
5 changes: 3 additions & 2 deletions test/pihole.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@
# By default, FTL warns if the shared-memory usage exceeds 90%. You can set any
# integer limit between 0 to 100 (interpreted as percentages) where 0 means that
# checking of shared-memory usage is disabled.
shmem = 0 ### CHANGED, default = 90
shmem = 91 ### CHANGED (env), default = 90

# FTL stores its long-term history in a database file on disk. Furthermore, FTL stores
# log files. By default, FTL warns if usage of the disk holding any crucial file
Expand Down Expand Up @@ -1178,6 +1178,7 @@
# Configuration statistics:
# 153 total entries out of which 96 entries are default
# --> 57 entries are modified
# 2 entries are forced through environment:
# 3 entries are forced through environment:
# - misc.nice
# - misc.check.shmem
# - debug.api
1 change: 1 addition & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ umask 0022
export FTLCONF_misc_nice="-11"
export FTLCONF_dns_upstrrr="-11"
export FTLCONF_debug_api="not_a_bool"
export FTLCONF_MISC_CHECK_SHMEM=91

# Prepare gdb session
echo "handle SIGHUP nostop SIGPIPE nostop SIGTERM nostop SIG32 nostop SIG33 nostop SIG34 nostop SIG35 nostop SIG41 nostop" > /root/.gdbinit
Expand Down
9 changes: 8 additions & 1 deletion test/test_suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1622,8 +1622,15 @@
[[ ${lines[0]} == " nice = -11 ### CHANGED (env), default = -10" ]]
}

@test "Capitalized Environmental variable is used and favored over config file" {
# The config file has 90 but we set FTLCONF_MISC_CHECK_SHMEM="91"
run bash -c 'grep "shmem = 91" /etc/pihole/pihole.toml'
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == " shmem = 91 ### CHANGED (env), default = 90" ]]
}

@test "Correct number of environmental variables is logged" {
run bash -c 'grep -q "3 FTLCONF environment variables found (1 used, 1 invalid, 1 ignored)" /var/log/pihole/FTL.log'
run bash -c 'grep -q "4 FTLCONF environment variables found (2 used, 1 invalid, 1 ignored)" /var/log/pihole/FTL.log'
printf "%s\n" "${lines[@]}"
[[ $status == 0 ]]
}
Expand Down

0 comments on commit 45d0c8a

Please sign in to comment.