summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-03-04 03:44:43 +0100
committerLennart Poettering <lennart@poettering.net>2011-03-04 03:44:43 +0100
commit8c7be95e5a80c4bd82d86e9640a071fd98618172 (patch)
treef9f8659f93430ed50da2c677dda705d35df24f69 /src/util.c
parent0595f9a1c182a84581749823ef47c5f292e545f9 (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/util.c')
-rw-r--r--src/util.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 23d7e2211d..b02a77eed8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -683,6 +683,73 @@ fail:
return r;
}
+int load_env_file(
+ const char *fname,
+ char ***rl) {
+
+ FILE *f;
+ char **m = 0;
+ int r;
+
+ assert(fname);
+ assert(rl);
+
+ if (!(f = fopen(fname, "re")))
+ return -errno;
+
+ while (!feof(f)) {
+ char l[LINE_MAX], *p, *u;
+ char **t;
+
+ if (!fgets(l, sizeof(l), f)) {
+ if (feof(f))
+ break;
+
+ r = -errno;
+ 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(m, u);
+ free(u);
+
+ if (!t) {
+ log_error("Out of memory");
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ strv_free(m);
+ m = t;
+ }
+
+ r = 0;
+
+ *rl = m;
+ m = NULL;
+
+finish:
+ if (f)
+ fclose(f);
+
+ strv_free(m);
+
+ return r;
+}
+
char *truncate_nl(char *s) {
assert(s);