X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-user.c;h=b692b533e25f0341dd7f8fc0c02a1c51b9dc31b1;hb=c67fbe4c71977de14ebd09a8c250ef8091dff231;hp=4622812e3c66eda4a2153e13f18f8af9864df5db;hpb=e96cd586c5195b73af74791280d8461510258b48;p=elogind.git diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 4622812e3..b692b533e 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -180,6 +180,20 @@ int user_save(User *u) { fputs(i->id, f); } + fputs("\nONLINE_SESSIONS=", f); + first = true; + LIST_FOREACH(sessions_by_user, i, u->sessions) { + if (session_get_state(i) == SESSION_CLOSING) + continue; + + if (first) + first = false; + else + fputc(' ', f); + + fputs(i->id, f); + } + fputs("\nACTIVE_SEATS=", f); first = true; LIST_FOREACH(sessions_by_user, i, u->sessions) { @@ -189,7 +203,23 @@ int user_save(User *u) { if (first) first = false; else - fputs(i->seat->id, f); + fputc(' ', f); + + fputs(i->seat->id, f); + } + + fputs("\nONLINE_SEATS=", f); + first = true; + LIST_FOREACH(sessions_by_user, i, u->sessions) { + if (session_get_state(i) == SESSION_CLOSING || !i->seat) + continue; + + if (first) + first = false; + else + fputc(' ', f); + + fputs(i->seat->id, f); } fputc('\n', f); } @@ -259,12 +289,8 @@ static int user_mkdir_runtime_path(User *u) { } if (!u->runtime_path) { - p = strappend("/run/user/", u->name); - - if (!p) { - log_error("Out of memory"); - return -ENOMEM; - } + if (asprintf(&p, "/run/user/%lu", (unsigned long) u->uid) < 0) + return log_oom(); } else p = u->runtime_path; @@ -288,10 +314,8 @@ static int user_create_cgroup(User *u) { assert(u); if (!u->cgroup_path) { - if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0) { - log_error("Out of memory"); - return -ENOMEM; - } + if (asprintf(&p, "%s/%s", u->manager->cgroup_path, u->name) < 0) + return log_oom(); } else p = u->cgroup_path; @@ -315,7 +339,9 @@ static int user_create_cgroup(User *u) { log_warning("Failed to create cgroup %s:%s: %s", *k, p, strerror(-r)); } - hashmap_put(u->manager->user_cgroups, u->cgroup_path, u); + r = hashmap_put(u->manager->user_cgroups, u->cgroup_path, u); + if (r < 0) + log_warning("Failed to create mapping between cgroup and user"); return 0; } @@ -574,15 +600,20 @@ void user_add_to_gc_queue(User *u) { UserState user_get_state(User *u) { Session *i; + bool all_closing = true; assert(u); - LIST_FOREACH(sessions_by_user, i, u->sessions) + + LIST_FOREACH(sessions_by_user, i, u->sessions) { if (session_is_active(i)) return USER_ACTIVE; + if (session_get_state(i) != SESSION_CLOSING) + all_closing = false; + } if (u->sessions) - return USER_ONLINE; + return all_closing ? USER_CLOSING : USER_ONLINE; if (user_check_linger_file(u) > 0) return USER_LINGERING;