chiark / gitweb /
units: set capability bounding set for syslog services
[elogind.git] / src / strv.c
index 0afd9865d9c7316fd35d155d6388182d64065091..71b77c9bbf97d857cce44ac0af1c350463d3ff50 100644 (file)
@@ -525,9 +525,38 @@ char **strv_env_delete(char **x, unsigned n_lists, ...) {
         return r;
 }
 
+char **strv_env_unset(char **l, const char *p) {
+
+        char **f, **t;
+
+        if (!l)
+                return NULL;
+
+        assert(p);
+
+        /* Drops every occurrence of the env var setting p in the
+         * string list. edits in-place. */
+
+        for (f = t = l; *f; f++) {
+
+                if (env_match(*f, p)) {
+                        free(*f);
+                        continue;
+                }
+
+                *(t++) = *f;
+        }
+
+        *t = NULL;
+        return l;
+}
+
 char **strv_env_set(char **x, const char *p) {
 
         char **k, **r;
+        char* m[2] = { (char*) p, NULL };
+
+        /* Overrides the env var setting of p, returns a new copy */
 
         if (!(r = new(char*, strv_length(x)+2)))
                 return NULL;
@@ -536,7 +565,7 @@ char **strv_env_set(char **x, const char *p) {
         if (env_append(r, &k, x) < 0)
                 goto fail;
 
-        if (!(*(k++) = strdup(p)))
+        if (env_append(r, &k, m) < 0)
                 goto fail;
 
         *k = NULL;