logind-user.c revision 71161305f191d1fe1242ccca47657f9ab51caad4
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/>.
6c03089c32c251d823173bda4d809a9e643219f0Lennart PoetteringUser* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering if (asprintf(&u->state_file, "/run/systemd/users/"UID_FMT, uid) < 0)
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering if (hashmap_put(m->users, UID_TO_PTR(uid), u) < 0)
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering LIST_REMOVE(gc_queue, u->manager->user_gc_queue, u);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering hashmap_remove(u->manager->user_units, u->slice);
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering hashmap_remove(u->manager->user_units, u->service);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering hashmap_remove(u->manager->users, UID_TO_PTR(u->uid));
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0);
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering r = fopen_temporary(u->state_file, &f, &temp_path);
7027ff61a34a12487712b382a061c654acc3a679Lennart Poettering "# This is private data. Do not parse.\n"
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering user_state_to_string(user_get_state(u)));
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering fprintf(f, "RUNTIME=%s\n", u->runtime_path);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering fprintf(f, "SERVICE_JOB=%s\n", u->service_job);
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering fprintf(f, "SLICE_JOB=%s\n", u->slice_job);
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering fprintf(f, "DISPLAY=%s\n", u->display->id);
ae018d9bc900d6355dea4af05119b49c67945184Lennart Poettering if (dual_timestamp_is_set(&u->timestamp))
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
aff38e74bd776471f15ba54b305a24b0251eb865Lennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
a0ab566574303be1ca12cdb334f284cfd407caa5Lennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
78edb35ab4f4227485cb9ec816b43c37e0d5e62aLennart Poettering if (session_get_state(i) == SESSION_CLOSING)
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering LIST_FOREACH(sessions_by_user, i, u->sessions) {
96cde13ace6406582688028f3df5668a172ba628Zbigniew Jędrzejewski-Szmek if (session_get_state(i) == SESSION_CLOSING || !i->seat)
r = -errno;
assert(u);
if (!u->started)
return user_save_internal (u);
assert(u);
NULL);
if (r == -ENOENT)
if (display)
u->display = s;
if (realtime) {
if (monotonic) {
assert(u);
if (!u->runtime_path) {
return log_oom();
p = u->runtime_path;
if (path_is_mount_point(p, 0) <= 0) {
if (mac_smack_use())
r = asprintf(&t, "mode=0700,smackfsroot=*,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size);
r = asprintf(&t, "mode=0700,uid=" UID_FMT ",gid=" GID_FMT ",size=%zu", u->uid, u->gid, u->manager->runtime_dir_size);
r = log_oom();
goto fail;
goto fail;
goto fail;
u->runtime_path = p;
fail:
(void) rmdir(p);
free(p);
char *job;
assert(u);
if (!u->slice) {
if (u->slice)
char *job;
assert(u);
if (!u->service) {
if (u->service)
assert(u);
if (u->started)
r = user_mkdir_runtime_path(u);
r = user_start_slice(u);
r = user_start_service(u);
u->started = true;
user_save(u);
user_send_signal(u, true);
char *job;
assert(u);
if (!u->slice)
char *job;
assert(u);
if (!u->service)
assert(u);
if (!u->runtime_path)
Session *s;
assert(u);
if (u->stopping) {
user_save(u);
k = user_stop_service(u);
k = user_stop_slice(u);
u->stopping = true;
user_save(u);
Session *s;
assert(u);
if (u->started)
k = session_finalize(s);
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;
char *p = NULL;
if (!cc)
return -ENOMEM;
assert(u);
if (u->sessions)
if (user_check_linger_file(u) > 0)
assert(u);
if (u->in_gc_queue)
u->in_gc_queue = true;
Session *i;
assert(u);
if (u->stopping)
return USER_CLOSING;
return USER_OPENING;
if (u->sessions) {
bool all_closing = true;
return USER_ACTIVE;
all_closing = false;
if (user_check_linger_file(u) > 0)
return USER_LINGERING;
return USER_CLOSING;
assert(u);
if (!u->slice)
return -ESRCH;
assert(s);
[SESSION_UNSPECIFIED] = 0,
Session *s;
assert(u);
if (!elect_display_filter(s)) {
u->display = s;
const char* unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
unsigned long ul;
errno = 0;
if (errno != 0 || f != e) {
log_syntax(unit, LOG_ERR, filename, line, errno ? errno : EINVAL, "Failed to parse percentage value, ignoring: %s", rvalue);
log_syntax(unit, LOG_ERR, filename, line, errno ? errno : EINVAL, "Percentage value out of range, ignoring: %s", rvalue);
off_t o;