return false;
}
+static bool env_entry_has_name(const char *entry, const char *name) {
+ const char *t;
+
+ assert(entry);
+ assert(name);
+
+ t = startswith(entry, name);
+ if (!t)
+ return false;
+
+ return *t == '=';
+}
+
char **strv_env_delete(char **x, unsigned n_lists, ...) {
size_t n, i = 0;
char **k, **r;
int strv_env_replace(char ***l, char *p) {
char **f;
+ const char *t, *name;
assert(p);
/* Replace first occurrence of the env var or add a new one in the
* string list. Drop other occurences. Edits in-place. Does not copy p.
+ * p must be a valid key=value assignment.
*/
+ t = strchr(p, '=');
+ assert(t);
+
+ name = strndupa(p, t - p);
+
for (f = *l; f && *f; f++)
- if (env_match(*f, p)) {
- free(*f);
- *f = p;
- strv_env_unset(f + 1, p);
+ if (env_entry_has_name(*f, name)) {
+ free_and_replace(*f, p);
+ strv_env_unset(f + 1, *f);
return 0;
}
if (r < 0)
return r;
+ if (!env_assignment_is_valid(uce))
+ return -EINVAL;
+
return strv_env_replace(environment, uce);
}
#include "alloc-util.h"
#include "ctype.h"
+#include "env-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
if (r < 0)
return r;
- p = strjoin(key, "=", strempty(value));
+ p = strjoin(key, "=", value);
if (!p)
return -ENOMEM;
- r = strv_consume(m, p);
- if (r < 0)
+ r = strv_env_replace(m, p);
+ if (r < 0) {
+ free(p);
return r;
+ }
if (n_pushed)
(*n_pushed)++;