core: extract exec_context_apply_environment() helper
Extract a small helper exec_context_apply_environment() from the dbus-execute.c file so that it can be re-used in the coming varlink version.
This commit is contained in:
@@ -753,6 +753,41 @@ void exec_context_done(ExecContext *c) {
|
||||
c->private_hostname = mfree(c->private_hostname);
|
||||
}
|
||||
|
||||
int exec_context_apply_environment(
|
||||
Unit *u,
|
||||
ExecContext *c,
|
||||
char **env,
|
||||
UnitWriteFlags flags) {
|
||||
|
||||
assert(u);
|
||||
assert(c);
|
||||
|
||||
if (strv_length(env) > ENVIRONMENT_ASSIGNMENTS_MAX)
|
||||
return -E2BIG;
|
||||
if (!strv_env_is_valid(env))
|
||||
return -EINVAL;
|
||||
|
||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||
if (strv_isempty(env)) {
|
||||
c->environment = strv_free(c->environment);
|
||||
unit_write_setting(u, flags, "Environment", "Environment=");
|
||||
} else {
|
||||
_cleanup_free_ char *joined = unit_concat_strv(env, UNIT_ESCAPE_SPECIFIERS|UNIT_ESCAPE_C);
|
||||
if (!joined)
|
||||
return -ENOMEM;
|
||||
|
||||
char **e = strv_env_merge(c->environment, env);
|
||||
if (!e)
|
||||
return -ENOMEM;
|
||||
|
||||
strv_free_and_replace(c->environment, e);
|
||||
unit_write_settingf(u, flags, "Environment", "Environment=%s", joined);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int exec_context_destroy_runtime_directory(const ExecContext *c, const char *runtime_prefix) {
|
||||
assert(c);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user