bool unit_check_gc(Unit *u) {
assert(u);
- if (u->load_state == UNIT_STUB)
- return true;
-
if (UNIT_VTABLE(u)->no_gc)
return true;
return unit_add_dependency(target, UNIT_AFTER, u, true);
}
-static int unit_add_default_dependencies(Unit *u) {
+static int unit_add_target_dependencies(Unit *u) {
static const UnitDependency deps[] = {
UNIT_REQUIRED_BY,
Unit *target;
Iterator i;
- int r;
unsigned k;
+ int r = 0;
assert(u);
return r;
}
- if (u->default_dependencies && unit_get_cgroup_context(u)) {
- if (UNIT_ISSET(u->slice))
- r = unit_add_two_dependencies(u, UNIT_AFTER, UNIT_WANTS, UNIT_DEREF(u->slice), true);
- else
- r = unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, SPECIAL_ROOT_SLICE, NULL, true);
+ return r;
+}
- if (r < 0)
- return r;
- }
+static int unit_add_slice_dependencies(Unit *u) {
+ assert(u);
- return 0;
+ if (!unit_get_cgroup_context(u))
+ return 0;
+
+ if (UNIT_ISSET(u->slice))
+ return unit_add_two_dependencies(u, UNIT_AFTER, UNIT_WANTS, UNIT_DEREF(u->slice), true);
+
+ return unit_add_two_dependencies_by_name(u, UNIT_AFTER, UNIT_WANTS, SPECIAL_ROOT_SLICE, NULL, true);
}
-static int unit_add_mount_links(Unit *u) {
+static int unit_add_mount_dependencies(Unit *u) {
char **i;
int r;
if (u->load_state == UNIT_LOADED) {
- if (u->default_dependencies) {
- r = unit_add_default_dependencies(u);
- if (r < 0)
- goto fail;
- }
+ r = unit_add_target_dependencies(u);
+ if (r < 0)
+ goto fail;
- r = unit_add_mount_links(u);
+ r = unit_add_slice_dependencies(u);
+ if (r < 0)
+ goto fail;
+
+ r = unit_add_mount_dependencies(u);
if (r < 0)
goto fail;
return NULL;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static void unit_status_print_starting_stopping(Unit *u, JobType t) {
const char *format;
if (!format)
return;
+ DISABLE_WARNING_FORMAT_NONLITERAL;
unit_status_printf(u, "", format);
+ REENABLE_WARNING;
}
-#pragma GCC diagnostic pop
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static void unit_status_log_starting_stopping_reloading(Unit *u, JobType t) {
const char *format;
char buf[LINE_MAX];
if (!format)
return;
+ DISABLE_WARNING_FORMAT_NONLITERAL;
snprintf(buf, sizeof(buf), format, unit_description(u));
char_array_0(buf);
+ REENABLE_WARNING;
mid = t == JOB_START ? SD_MESSAGE_UNIT_STARTING :
t == JOB_STOP ? SD_MESSAGE_UNIT_STOPPING :
"MESSAGE=%s", buf,
NULL);
}
-#pragma GCC diagnostic pop
/* Errors:
* -EBADR: This unit type does not support starting.
if (pid == except1 || pid == except2)
continue;
- if (kill(pid, 0) < 0 && errno == ESRCH)
+ if (!pid_is_unwaited(pid))
set_remove(u->pids, e);
}
}
return 0;
}
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
void unit_status_printf(Unit *u, const char *status, const char *unit_status_msg_format) {
+ DISABLE_WARNING_FORMAT_NONLITERAL;
manager_status_printf(u->manager, false, status, unit_status_msg_format, unit_description(u));
+ REENABLE_WARNING;
}
-#pragma GCC diagnostic pop
bool unit_need_daemon_reload(Unit *u) {
_cleanup_strv_free_ char **t = NULL;
ref->unit = NULL;
}
-int unit_exec_context_defaults(Unit *u, ExecContext *c) {
+int unit_cgroup_context_init_defaults(Unit *u, CGroupContext *c) {
+ assert(u);
+ assert(c);
+
+ /* Copy in the manager defaults into the cgroup context,
+ * _before_ the rest of the settings have been initialized */
+
+ c->cpu_accounting = u->manager->default_cpu_accounting;
+ c->blockio_accounting = u->manager->default_blockio_accounting;
+ c->memory_accounting = u->manager->default_memory_accounting;
+
+ return 0;
+}
+
+int unit_exec_context_patch_defaults(Unit *u, ExecContext *c) {
unsigned i;
int r;
assert(u);
assert(c);
+ /* Patch in the manager defaults into the exec context,
+ * _after_ the rest of the settings have been initialized */
+
/* This only copies in the ones that need memory */
for (i = 0; i < RLIMIT_NLIMITS; i++)
if (u->manager->rlimit[i] && !c->rlimit[i]) {
assert(name);
assert(_p);
assert(_q);
- assert(mode & (UNIT_PERSISTENT|UNIT_RUNTIME));
b = xescape(name, "/.");
if (!b)
return -ENOENT;
p = strjoin(c, "/", u->id, ".d", NULL);
- } else if (mode & UNIT_PERSISTENT)
+ } else if (mode == UNIT_PERSISTENT && !u->transient)
p = strjoin("/etc/systemd/system/", u->id, ".d", NULL);
else
p = strjoin("/run/systemd/system/", u->id, ".d", NULL);
assert(name);
assert(data);
- if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
r = drop_in_file(u, mode, name, &p, &q);
assert(name);
assert(format);
- if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
va_start(ap, format);
if (!UNIT_VTABLE(u)->private_section)
return -EINVAL;
- if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
ndata = strjoin("[", UNIT_VTABLE(u)->private_section, "]\n", data, NULL);
assert(name);
assert(format);
- if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
va_start(ap, format);
assert(u);
- if (!(mode & (UNIT_PERSISTENT|UNIT_RUNTIME)))
+ if (!IN_SET(mode, UNIT_PERSISTENT, UNIT_RUNTIME))
return 0;
r = drop_in_file(u, mode, name, &p, &q);