slice.c revision be847e82cf95bf8eb589778df2aa2b3d1d7ae99e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include "unit.h"
#include "slice.h"
#include "log.h"
#include "dbus-slice.h"
#include "special.h"
#include "unit-name.h"
[SLICE_DEAD] = UNIT_INACTIVE,
};
assert(t);
log_debug("%s changed %s -> %s",
}
static int slice_add_parent_slice(Slice *s) {
char *a, *dash;
int r;
assert(s);
return 0;
return 0;
if (dash)
else
a = (char*) SPECIAL_ROOT_SLICE;
if (r < 0)
return r;
return 0;
}
static int slice_add_default_dependencies(Slice *s) {
int r;
assert(s);
/* Make sure slices are unloaded on shutdown */
UNIT(s),
SPECIAL_SHUTDOWN_TARGET, NULL, true);
if (r < 0)
return r;
return 0;
}
static int slice_verify(Slice *s) {
assert(s);
return 0;
char *a, *dash;
if (dash)
else
a = (char*) SPECIAL_ROOT_SLICE;
return -EINVAL;
}
}
return 0;
}
static int slice_load(Unit *u) {
int r;
assert(s);
if (r < 0)
return r;
/* This is a new unit? Then let's add in some extras */
if (u->load_state == UNIT_LOADED) {
r = unit_patch_contexts(u);
if (r < 0)
return r;
r = slice_add_parent_slice(s);
if (r < 0)
return r;
if (u->default_dependencies) {
r = slice_add_default_dependencies(s);
if (r < 0)
return r;
}
}
return slice_verify(s);
}
static int slice_coldplug(Unit *u) {
assert(t);
if (t->deserialized_state != t->state)
slice_set_state(t, t->deserialized_state);
return 0;
}
assert(t);
assert(f);
fprintf(f,
"%sSlice State: %s\n",
}
static int slice_start(Unit *u) {
assert(t);
(void) unit_realize_cgroup(u);
(void) unit_reset_cpu_usage(u);
return 1;
}
static int slice_stop(Unit *u) {
assert(t);
/* We do not need to destroy the cgroup explicitly,
* unit_notify() will do that for us anyway. */
return 1;
}
}
assert(s);
assert(f);
return 0;
}
assert(u);
if (state < 0)
else
s->deserialized_state = state;
} else
return 0;
}
assert(u);
}
assert(u);
}
static const char* const slice_state_table[_SLICE_STATE_MAX] = {
[SLICE_DEAD] = "dead",
[SLICE_ACTIVE] = "active"
};
const UnitVTable slice_vtable = {
.object_size = sizeof(Slice),
.sections =
"Unit\0"
"Slice\0"
"Install\0",
.private_section = "Slice",
.no_alias = true,
.no_instances = true,
.load = slice_load,
.dump = slice_dump,
.start = slice_start,
.stop = slice_stop,
.kill = slice_kill,
.bus_interface = "org.freedesktop.systemd1.Slice",
.finished_start_job = {
[JOB_DONE] = "Created slice %s.",
[JOB_DEPENDENCY] = "Dependency failed for %s.",
},
.finished_stop_job = {
[JOB_DONE] = "Removed slice %s.",
},
},
};