Skip to content

Commit

Permalink
Ensure warnings/errors about invalid env vars are only printed once
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Feb 24, 2025
1 parent 494d27a commit d821b07
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/config/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include "webserver/http-common.h"
struct env_item
{
bool used;
bool valid;
bool used :1;
bool valid :1;
bool error_allocated :1;
char *key;
char *value;
const char *error;
const char *allowed;
char *error;
struct env_item *next;
};

Expand Down Expand Up @@ -79,7 +79,6 @@ void getEnvVars(void)
new_item->key = strdup(key);
new_item->value = strdup(value);
new_item->error = NULL;
new_item->allowed = NULL;
new_item->next = env_list;
env_list = new_item;

Expand Down Expand Up @@ -122,15 +121,15 @@ void printFTLenv(void)
log_info(" %s %s is used", cli_tick(), item->key);
else
{
if(item->error != NULL && item->allowed == NULL)
log_err(" %s %s is invalid (%s)",
cli_cross(), item->key, item->error);
else if(item->error != NULL && item->allowed != NULL)
log_err(" %s %s is invalid (%s, allowed options are: %s)",
cli_cross(), item->key, item->error, item->allowed);
if(item->error != NULL)
log_err(" %s %s %s",
cli_cross(), item->key, item->error);
else
log_err(" %s %s is invalid",
cli_cross(), item->key);

if(item->error_allocated)
free(item->error);
}

continue;
Expand Down Expand Up @@ -186,7 +185,6 @@ void freeEnvVars(void)
static void invalid_enum_item(const char *envvar, struct conf_item *conf_item, struct env_item *item)
{
item->error = "not an allowed option";
item->allowed = conf_item->h;
item->valid = false;

cJSON *allowed_items = cJSON_CreateArray();
Expand All @@ -199,8 +197,10 @@ static void invalid_enum_item(const char *envvar, struct conf_item *conf_item, s
char *allowed_values = cJSON_PrintUnformatted(allowed_items);
char *escaped_value = escape_json(envvar);

log_warn("ENV %s = %s is %s, allowed options are: %s",
conf_item->e, escaped_value, item->error, allowed_values);
// Calculate the size of the error message
asprintf(&item->error, "= %s is %s, allowed options are: %s",
escaped_value, item->error, allowed_values);

free(escaped_value);
free(allowed_values);
}
Expand Down

0 comments on commit d821b07

Please sign in to comment.