return (CGroupContext*) ((uint8_t*) u + offset);
}
-static int drop_in_file(Unit *u, bool runtime, const char *name, char **_p, char **_q) {
+static int drop_in_file(Unit *u, UnitSetPropertiesMode mode, const char *name, char **_p, char **_q) {
char *p, *q;
int r;
assert(name);
assert(_p);
assert(_q);
+ assert(mode & (UNIT_PERSISTENT|UNIT_RUNTIME));
- if (u->manager->running_as == SYSTEMD_USER && runtime)
+ if (u->manager->running_as == SYSTEMD_USER && !(mode & UNIT_PERSISTENT))
return -ENOTSUP;
if (!filename_is_safe(name))
return -ENOENT;
p = strjoin(c, "/", u->id, ".d", NULL);
- } else if (runtime)
- p = strjoin("/run/systemd/system/", u->id, ".d", NULL);
- else
+ } else if (mode & UNIT_PERSISTENT)
p = strjoin("/etc/systemd/system/", u->id, ".d", NULL);
+ else
+ p = strjoin("/run/systemd/system/", u->id, ".d", NULL);
if (!p)
return -ENOMEM;
- q = strjoin(p, "/50-", name, ".conf", NULL);
+ q = strjoin(p, "/90-", name, ".conf", NULL);
if (!q) {
free(p);
return -ENOMEM;
return 0;
}
-int unit_write_drop_in(Unit *u, bool runtime, const char *name, const char *data) {
+int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
_cleanup_free_ char *p = NULL, *q = NULL;
int r;
assert(u);
+ assert(name);
+ assert(data);
- r = drop_in_file(u, runtime, name, &p, &q);
+ if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ return 0;
+
+ r = drop_in_file(u, mode, name, &p, &q);
if (r < 0)
return r;
return write_string_file_atomic_label(q, data);
}
-int unit_remove_drop_in(Unit *u, bool runtime, const char *name) {
+int unit_write_drop_in_private_section(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
+ _cleanup_free_ char *ndata = NULL;
+
+ assert(u);
+ assert(name);
+ assert(data);
+
+ if (!UNIT_VTABLE(u)->private_section)
+ return -EINVAL;
+
+ ndata = strjoin("[", UNIT_VTABLE(u)->private_section, "]\n", data, NULL);
+ if (!ndata)
+ return -ENOMEM;
+
+ return unit_write_drop_in(u, mode, name, ndata);
+}
+
+int unit_remove_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name) {
_cleanup_free_ char *p = NULL, *q = NULL;
int r;
assert(u);
- r = drop_in_file(u, runtime, name, &p, &q);
+ if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ return 0;
+
+ r = drop_in_file(u, mode, name, &p, &q);
if (unlink(q) < 0)
- r = -errno;
+ r = errno == ENOENT ? 0 : -errno;
else
- r = 0;
+ r = 1;
rmdir(p);
return r;