summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-01-05 16:06:35 +0100
committerLennart Poettering <lennart@poettering.net>2011-01-05 16:06:35 +0100
commit5f7c426e2a7f72c473f98be9978d243db79d8910 (patch)
treebe5023d062e91526d7394d6624dc0e2d44d6cd5c /src/util.c
parent38752828029e72e72d80519bb6c67354782ddb72 (diff)
fragment: properly handle quotes in assignments in EnvironmentFile= files
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 08bdec223e..21afdceb8c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3326,6 +3326,44 @@ char *unquote(const char *s, const char* quotes) {
return strdup(s);
}
+char *normalize_env_assignment(const char *s) {
+ char *name, *value, *p, *r;
+
+ p = strchr(s, '=');
+
+ if (!p) {
+ if (!(r = strdup(s)))
+ return NULL;
+
+ return strstrip(r);
+ }
+
+ if (!(name = strndup(s, p - s)))
+ return NULL;
+
+ if (!(p = strdup(p+1))) {
+ free(name);
+ return NULL;
+ }
+
+ value = unquote(strstrip(p), QUOTES);
+ free(p);
+
+ if (!value) {
+ free(p);
+ free(name);
+ return NULL;
+ }
+
+ if (asprintf(&r, "%s=%s", name, value) < 0)
+ r = NULL;
+
+ free(value);
+ free(name);
+
+ return r;
+}
+
int wait_for_terminate(pid_t pid, siginfo_t *status) {
assert(pid >= 1);
assert(status);