diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-02-25 01:13:57 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-04-12 13:43:30 +0200 |
commit | 39591351391de3ef2fd23cc5aea5bdd6ab712db6 (patch) | |
tree | d251464ea9f8e7eb139ee4824a115decb407ed40 /src/shared/path-lookup.c | |
parent | 5f0a41dade626da20000890807bc61f5d4359fb5 (diff) |
core: add a separate unit directory for transient units
Previously, transient units were created below the normal runtime directory
/run/systemd/system. With this change they are created in a special transient
directory /run/systemd/transient, which only contains data for transient units.
This clarifies the life-cycle of transient units, and makes clear they are
distinct from user-provided runtime units. In particular, users may now
extend transient units via /run/systemd/system, without systemd interfering
with the life-cycle of these files.
This change also adds code so that when a transient unit exits only the
drop-ins in this new directory are removed, but nothing else.
Fixes: #2139
Diffstat (limited to 'src/shared/path-lookup.c')
-rw-r--r-- | src/shared/path-lookup.c | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c index 11b9bb6107..f437de370c 100644 --- a/src/shared/path-lookup.c +++ b/src/shared/path-lookup.c @@ -111,7 +111,8 @@ static char** user_dirs( const char *runtime_config, const char *generator, const char *generator_early, - const char *generator_late) { + const char *generator_late, + const char *transient) { const char * const config_unit_paths[] = { USER_CONFIG_UNIT_PATH, @@ -172,6 +173,10 @@ static char** user_dirs( return NULL; /* Now merge everything we found. */ + if (transient) + if (strv_extend(&res, transient) < 0) + return NULL; + if (generator_early) if (strv_extend(&res, generator_early) < 0) return NULL; @@ -305,6 +310,42 @@ static int acquire_generator_dirs( return 0; } +static int acquire_transient_dir(UnitFileScope scope, char **ret) { + char *transient; + + assert(ret); + + switch (scope) { + + case UNIT_FILE_SYSTEM: + transient = strdup("/run/systemd/transient"); + break; + + case UNIT_FILE_USER: { + const char *e; + + e = getenv("XDG_RUNTIME_DIR"); + if (!e) + return -ENXIO; + + transient = strjoin(e, "/systemd/transient", NULL); + break; + } + + case UNIT_FILE_GLOBAL: + return -EOPNOTSUPP; + + default: + assert_not_reached("Hmm, unexpected scope value."); + } + + if (!transient) + return -ENOMEM; + + *ret = transient; + return 0; +} + static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **runtime) { _cleanup_free_ char *a = NULL, *b = NULL; int r; @@ -377,8 +418,9 @@ int lookup_paths_init( _cleanup_free_ char *root = NULL, + *persistent_config = NULL, *runtime_config = NULL, *generator = NULL, *generator_early = NULL, *generator_late = NULL, - *persistent_config = NULL, *runtime_config = NULL; + *transient = NULL; bool append = false; /* Add items from SYSTEMD_UNIT_PATH before normal directories */ char **l = NULL; const char *e; @@ -411,6 +453,10 @@ int lookup_paths_init( if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO) return r; + r = acquire_transient_dir(scope, &transient); + if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO) + return r; + /* First priority is whatever has been passed to us via env * vars */ e = getenv("SYSTEMD_UNIT_PATH"); @@ -449,6 +495,7 @@ int lookup_paths_init( add = strv_new( /* If you modify this you also want to modify * systemdsystemunitpath= in systemd.pc.in! */ + STRV_IFNOTNULL(transient), STRV_IFNOTNULL(generator_early), persistent_config, SYSTEM_CONFIG_UNIT_PATH, @@ -471,6 +518,7 @@ int lookup_paths_init( /* If you modify this you also want to modify * systemduserunitpath= in systemd.pc.in, and * the arrays in user_dirs() above! */ + STRV_IFNOTNULL(transient), STRV_IFNOTNULL(generator_early), persistent_config, USER_CONFIG_UNIT_PATH, @@ -489,7 +537,8 @@ int lookup_paths_init( case UNIT_FILE_USER: add = user_dirs(persistent_config, runtime_config, - generator, generator_early, generator_late); + generator, generator_early, generator_late, + transient); break; default: @@ -526,6 +575,10 @@ int lookup_paths_init( if (r < 0) return r; + r = patch_root_prefix(&transient, root); + if (r < 0) + return r; + if (!path_strv_resolve_uniq(l, root)) return -ENOMEM; @@ -554,6 +607,9 @@ int lookup_paths_init( p->generator_late = generator_late; generator = generator_early = generator_late = NULL; + p->transient = transient; + transient = NULL; + p->root_dir = root; root = NULL; @@ -573,5 +629,7 @@ void lookup_paths_free(LookupPaths *p) { p->generator_early = mfree(p->generator_early); p->generator_late = mfree(p->generator_late); + p->transient = mfree(p->transient); + p->root_dir = mfree(p->root_dir); } |