logind-user.c revision 47acb2f15f2319ec0fc341a4271d45067da2ed24
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering This file is part of systemd.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Copyright 2011 Lennart Poettering
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is free software; you can redistribute it and/or modify it
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering under the terms of the GNU Lesser General Public License as published by
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering (at your option) any later version.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering systemd is distributed in the hope that it will be useful, but
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering Lesser General Public License for more details.
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering You should have received a copy of the GNU Lesser General Public License
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
96cde13ace6406582688028f3df5668a172ba628Zbigniew Jędrzejewski-SzmekUser* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering if (asprintf(&u->state_file, "/run/systemd/users/%lu", (unsigned long) uid) < 0) {
6c03089c32c251d823173bda4d809a9e643219f0Lennart Poettering if (hashmap_put(m->users, ULONG_TO_PTR((unsigned long) uid), u) < 0) {
96cde13ace6406582688028f3df5668a172ba628Zbigniew Jędrzejewski-Szmek LIST_REMOVE(User, gc_queue, u->manager->user_gc_queue, u);
96cde13ace6406582688028f3df5668a172ba628Zbigniew Jędrzejewski-Szmek hashmap_remove(u->manager->user_cgroups, u->cgroup_path);
free(u);
FILE *f;
char *temp_path;
assert(u);
if (!u->started)
goto finish;
goto finish;
fprintf(f,
u->name,
if (u->cgroup_path)
fprintf(f,
u->cgroup_path);
if (u->runtime_path)
fprintf(f,
u->runtime_path);
if (u->service)
fprintf(f,
u->service);
if (u->display)
fprintf(f,
if (u->sessions) {
Session *i;
bool first;
first = true;
if (first)
first = false;
first = true;
if (!i->seat)
if (first)
first = false;
first = true;
if (!session_is_active(i))
if (first)
first = false;
first = true;
if (first)
first = false;
fflush(f);
r = -errno;
fclose(f);
assert(u);
NULL);
if (r == -ENOENT)
if (display) {
u->display = s;
assert(u);
if (!u->runtime_path) {
return log_oom();
p = u->runtime_path;
free(p);
u->runtime_path = p;
assert(u);
if (!u->cgroup_path) {
return log_oom();
p = u->cgroup_path;
free(p);
u->cgroup_path = p;
r = cg_create(*k, p);
assert(u);
assert(u);
if (u->started)
r = user_mkdir_runtime_path(u);
r = user_create_cgroup(u);
r = user_start_service(u);
u->started = true;
user_save(u);
user_send_signal(u, true);
assert(u);
if (!u->service)
assert(u);
assert(u);
if (!u->cgroup_path)
if (user_shall_kill(u)) {
r = -EBUSY;
assert(u);
if (!u->runtime_path)
Session *s;
assert(u);
if (u->started)
k = session_stop(s);
k = user_stop_service(u);
k = user_terminate_cgroup(u);
k = user_remove_runtime_path(u);
if (u->started)
user_send_signal(u, false);
u->started = false;
Session *s;
bool idle_hint = true;
assert(u);
int ih;
if (ih < 0)
return ih;
if (!ih) {
if (!idle_hint) {
ts = k;
idle_hint = false;
ts = k;
} else if (idle_hint) {
ts = k;
*t = ts;
return idle_hint;
return -ENOMEM;
free(p);
assert(u);
if (u->sessions)
if (user_check_linger_file(u) > 0)
if (u->cgroup_path) {
assert(u);
if (u->in_gc_queue)
u->in_gc_queue = true;
Session *i;
bool all_closing = true;
assert(u);
if (session_is_active(i))
return USER_ACTIVE;
all_closing = false;
if (u->sessions)
if (user_check_linger_file(u) > 0)
return USER_LINGERING;
return USER_CLOSING;
assert(u);
if (!u->cgroup_path)
return -ESRCH;
if (!pid_set)
return -ENOMEM;
q = cg_kill_recursive(SYSTEMD_CGROUP_CONTROLLER, u->cgroup_path, signo, false, true, false, pid_set);
if (pid_set)