session: process environment.d and allow empty variables

1. All '*.env' files in an 'environment.d' directory alongside each
   potential 'environment' file will be parsed and added to the
   environment.

2. For the purposes of configuration merging, an environment definition
   exists at one level if either the 'environment' file is defined or
   its corresponding 'environment.d' contains any valid '*.env' file.

3. Variable declarations of the form "VARIABLE=", with no following
   value, will be written to the environment as empty strings.
This commit is contained in:
Andrew J. Hesford 2024-03-09 12:03:30 -05:00 committed by Johan Malm
parent 52cb643189
commit e837445114
4 changed files with 121 additions and 10 deletions

View file

@ -86,7 +86,7 @@ strdup_printf(const char *fmt, ...)
}
char *
str_join(const char * const parts[],
str_join(const char *const parts[],
const char *restrict fmt, const char *restrict sep)
{
assert(parts);
@ -154,3 +154,19 @@ str_join(const char * const parts[],
return buf;
}
bool
str_endswith(const char *const string, const char *const suffix)
{
size_t len_str = string ? strlen(string) : 0;
size_t len_sfx = suffix ? strlen(suffix) : 0;
if (len_str < len_sfx) {
return false;
}
if (len_sfx == 0) {
return true;
}
return strcmp(string + len_str - len_sfx, suffix) == 0;
}