summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-08-28 16:05:32 +0200
committerLennart Poettering <lennart@poettering.net>2015-08-31 13:20:43 +0200
commit3f5e811594bcdb25d3aa859cb0be06f6df3a03b9 (patch)
treeafa849b78dd017f164fb5d539d9557bf63154f29 /src
parent3850d0505fb4350dccdd63cf6129db40fe9b5bd0 (diff)
core: don't generate stub unit file for transient units
We store the properties for transient units in drop-ins anyway, and units don't have to have fragment files, hence don't bother with them, and don't create them.
Diffstat (limited to 'src')
-rw-r--r--src/core/load-fragment.c5
-rw-r--r--src/core/unit.c46
2 files changed, 17 insertions, 34 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index b3bf8bdb40..721da3470e 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3603,6 +3603,11 @@ int unit_load_fragment(Unit *u) {
assert(u->load_state == UNIT_STUB);
assert(u->id);
+ if (u->transient) {
+ u->load_state = UNIT_LOADED;
+ return 0;
+ }
+
/* First, try to find the unit under its id. We always look
* for unit files in the default directories, to make it easy
* to override things by placing things in /etc/systemd/system */
diff --git a/src/core/unit.c b/src/core/unit.c
index 43a5ca1064..a6b56e2998 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -405,17 +405,17 @@ static void unit_remove_transient(Unit *u) {
return;
if (u->fragment_path)
- unlink(u->fragment_path);
+ (void) unlink(u->fragment_path);
STRV_FOREACH(i, u->dropin_paths) {
_cleanup_free_ char *p = NULL;
int r;
- unlink(*i);
+ (void) unlink(*i);
r = path_get_parent(*i, &p);
if (r >= 0)
- rmdir(p);
+ (void) rmdir(p);
}
}
@@ -3317,6 +3317,8 @@ ExecRuntime *unit_get_exec_runtime(Unit *u) {
}
static int unit_drop_in_dir(Unit *u, UnitSetPropertiesMode mode, bool transient, char **dir) {
+ assert(u);
+
if (u->manager->running_as == MANAGER_USER) {
int r;
@@ -3324,9 +3326,9 @@ static int unit_drop_in_dir(Unit *u, UnitSetPropertiesMode mode, bool transient,
r = user_config_home(dir);
else
r = user_runtime_dir(dir);
-
if (r == 0)
return -ENOENT;
+
return r;
}
@@ -3340,8 +3342,7 @@ static int unit_drop_in_dir(Unit *u, UnitSetPropertiesMode mode, bool transient,
return 0;
}
-static int unit_drop_in_file(Unit *u,
- UnitSetPropertiesMode mode, const char *name, char **p, char **q) {
+static int unit_drop_in_file(Unit *u, UnitSetPropertiesMode mode, const char *name, char **p, char **q) {
_cleanup_free_ char *dir = NULL;
int r;
@@ -3475,40 +3476,17 @@ int unit_remove_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name) {
}
int unit_make_transient(Unit *u) {
- int r;
-
assert(u);
+ if (!UNIT_VTABLE(u)->can_transient)
+ return -EOPNOTSUPP;
+
u->load_state = UNIT_STUB;
u->load_error = 0;
u->transient = true;
+ u->fragment_path = mfree(u->fragment_path);
- free(u->fragment_path);
- u->fragment_path = NULL;
-
- if (u->manager->running_as == MANAGER_USER) {
- _cleanup_free_ char *c = NULL;
-
- r = user_runtime_dir(&c);
- if (r < 0)
- return r;
- if (r == 0)
- return -ENOENT;
-
- u->fragment_path = strjoin(c, "/", u->id, NULL);
- if (!u->fragment_path)
- return -ENOMEM;
-
- mkdir_p(c, 0755);
- } else {
- u->fragment_path = strappend("/run/systemd/system/", u->id);
- if (!u->fragment_path)
- return -ENOMEM;
-
- mkdir_p("/run/systemd/system", 0755);
- }
-
- return write_string_file_atomic_label(u->fragment_path, "# Transient stub");
+ return 0;
}
int unit_kill_context(