diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-03-04 03:44:43 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-03-04 03:44:43 +0100 |
commit | 8c7be95e5a80c4bd82d86e9640a071fd98618172 (patch) | |
tree | f9f8659f93430ed50da2c677dda705d35df24f69 /src/load-fragment.c | |
parent | 0595f9a1c182a84581749823ef47c5f292e545f9 (diff) |
execute: load environment files at time of execution, not when we load the service configuration
https://bugzilla.redhat.com/show_bug.cgi?id=661282
Diffstat (limited to 'src/load-fragment.c')
-rw-r--r-- | src/load-fragment.c | 70 |
1 files changed, 8 insertions, 62 deletions
diff --git a/src/load-fragment.c b/src/load-fragment.c index 2e67eccc00..bd7529ff95 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -1340,79 +1340,25 @@ static int config_parse_env_file( void *data, void *userdata) { - FILE *f; - int r; - char ***env = data; - bool ignore = false; + char ***env = data, **k; assert(filename); assert(lvalue); assert(rvalue); assert(data); - if (rvalue[0] == '-') { - ignore = true; - rvalue++; - } - - if (!path_is_absolute(rvalue)) { + if (!path_is_absolute(rvalue[0] == '-' ? rvalue + 1 : rvalue)) { log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, rvalue); return 0; } - if (!(f = fopen(rvalue, "re"))) { - if (!ignore) - log_error("[%s:%u] Failed to open environment file '%s', ignoring: %m", filename, line, rvalue); - return 0; - } - - while (!feof(f)) { - char l[LINE_MAX], *p, *u; - char **t; - - if (!fgets(l, sizeof(l), f)) { - if (feof(f)) - break; - - log_error("[%s:%u] Failed to read environment file '%s', ignoring: %m", filename, line, rvalue); - r = 0; - goto finish; - } - - p = strstrip(l); - - if (!*p) - continue; - - if (strchr(COMMENTS, *p)) - continue; - - if (!(u = normalize_env_assignment(p))) { - log_error("Out of memory"); - r = -ENOMEM; - goto finish; - } - - t = strv_append(*env, u); - free(u); - - if (!t) { - log_error("Out of memory"); - r = -ENOMEM; - goto finish; - } - - strv_free(*env); - *env = t; - } - - r = 0; + if (!(k = strv_append(*env, rvalue))) + return -ENOMEM; -finish: - if (f) - fclose(f); + strv_free(*env); + *env = k; - return r; + return 0; } static int config_parse_ip_tos( @@ -1803,7 +1749,7 @@ static int load_from_path(Unit *u, const char *path) { { "CPUAffinity", config_parse_cpu_affinity, &(context), section }, \ { "UMask", config_parse_mode, &(context).umask, section }, \ { "Environment", config_parse_strv, &(context).environment, section }, \ - { "EnvironmentFile", config_parse_env_file, &(context).environment, section }, \ + { "EnvironmentFile", config_parse_env_file, &(context).environment_files, section }, \ { "StandardInput", config_parse_input, &(context).std_input, section }, \ { "StandardOutput", config_parse_output, &(context).std_output, section }, \ { "StandardError", config_parse_output, &(context).std_error, section }, \ |