chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
logind: introduce a state for session, being one of online, active, closing
[elogind.git]
/
src
/
login
/
logind-session.c
diff --git
a/src/login/logind-session.c
b/src/login/logind-session.c
index 475ebcaa5ea27265ba78839b98ffd0c1308ac054..e438c66332c7443d1250fdf7b5cc5bb213955b81 100644
(file)
--- a/
src/login/logind-session.c
+++ b/
src/login/logind-session.c
@@
-88,7
+88,7
@@
void session_free(Session *s) {
}
if (s->cgroup_path)
}
if (s->cgroup_path)
- hashmap_remove(s->manager->cgroups, s->cgroup_path);
+ hashmap_remove(s->manager->
session_
cgroups, s->cgroup_path);
free(s->cgroup_path);
strv_free(s->controllers);
free(s->cgroup_path);
strv_free(s->controllers);
@@
-116,7
+116,7
@@
int session_save(Session *s) {
if (!s->started)
return 0;
if (!s->started)
return 0;
- r =
safe_mkdir
("/run/systemd/sessions", 0755, 0, 0);
+ r =
mkdir_safe_label
("/run/systemd/sessions", 0755, 0, 0);
if (r < 0)
goto finish;
if (r < 0)
goto finish;
@@
-133,11
+133,13
@@
int session_save(Session *s) {
"UID=%lu\n"
"USER=%s\n"
"ACTIVE=%i\n"
"UID=%lu\n"
"USER=%s\n"
"ACTIVE=%i\n"
+ "STATE=%s\n"
"REMOTE=%i\n"
"KILL_PROCESSES=%i\n",
(unsigned long) s->user->uid,
s->user->name,
session_is_active(s),
"REMOTE=%i\n"
"KILL_PROCESSES=%i\n",
(unsigned long) s->user->uid,
s->user->name,
session_is_active(s),
+ session_state_to_string(session_get_state(s)),
s->remote,
s->kill_processes);
s->remote,
s->kill_processes);
@@
-382,7
+384,7
@@
static int session_link_x11_socket(Session *s) {
c[k] = 0;
if (access(f, F_OK) < 0) {
c[k] = 0;
if (access(f, F_OK) < 0) {
- log_warning("Session %s has display %s with nonexisting socket %s.", s->id, s->display, f);
+ log_warning("Session %s has display %s with non
-
existing socket %s.", s->id, s->display, f);
free(f);
return -ENOENT;
}
free(f);
return -ENOENT;
}
@@
-527,7
+529,7
@@
static int session_create_cgroup(Session *s) {
}
}
}
}
- hashmap_put(s->manager->cgroups, s->cgroup_path, s);
+ hashmap_put(s->manager->
session_
cgroups, s->cgroup_path, s);
return 0;
}
return 0;
}
@@
-646,7
+648,7
@@
static int session_terminate_cgroup(Session *s) {
STRV_FOREACH(k, s->user->manager->controllers)
cg_trim(*k, s->cgroup_path, true);
STRV_FOREACH(k, s->user->manager->controllers)
cg_trim(*k, s->cgroup_path, true);
- hashmap_remove(s->manager->cgroups, s->cgroup_path);
+ hashmap_remove(s->manager->
session_
cgroups, s->cgroup_path);
free(s->cgroup_path);
s->cgroup_path = NULL;
free(s->cgroup_path);
s->cgroup_path = NULL;
@@
-816,7
+818,7
@@
int session_create_fifo(Session *s) {
/* Create FIFO */
if (!s->fifo_path) {
/* Create FIFO */
if (!s->fifo_path) {
- r =
safe_mkdir
("/run/systemd/sessions", 0755, 0, 0);
+ r =
mkdir_safe_label
("/run/systemd/sessions", 0755, 0, 0);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-841,7
+843,7
@@
int session_create_fifo(Session *s) {
zero(ev);
ev.events = 0;
zero(ev);
ev.events = 0;
- ev.data.u32 = FD_
FIFO
_BASE + s->fifo_fd;
+ ev.data.u32 = FD_
OTHER
_BASE + s->fifo_fd;
if (epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_ADD, s->fifo_fd, &ev) < 0)
return -errno;
if (epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_ADD, s->fifo_fd, &ev) < 0)
return -errno;
@@
-913,6
+915,18
@@
void session_add_to_gc_queue(Session *s) {
s->in_gc_queue = true;
}
s->in_gc_queue = true;
}
+SessionState session_get_state(Session *s) {
+ assert(s);
+
+ if (s->fifo_fd < 0)
+ return SESSION_CLOSING;
+
+ if (session_is_active(s))
+ return SESSION_ACTIVE;
+
+ return SESSION_ONLINE;
+}
+
int session_kill(Session *s, KillWho who, int signo) {
int r = 0;
Set *pid_set = NULL;
int session_kill(Session *s, KillWho who, int signo) {
int r = 0;
Set *pid_set = NULL;
@@
-954,6
+968,14
@@
int session_kill(Session *s, KillWho who, int signo) {
return r;
}
return r;
}
+static const char* const session_state_table[_SESSION_TYPE_MAX] = {
+ [SESSION_ONLINE] = "online",
+ [SESSION_ACTIVE] = "active",
+ [SESSION_CLOSING] = "closing"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(session_state, SessionState);
+
static const char* const session_type_table[_SESSION_TYPE_MAX] = {
[SESSION_TTY] = "tty",
[SESSION_X11] = "x11",
static const char* const session_type_table[_SESSION_TYPE_MAX] = {
[SESSION_TTY] = "tty",
[SESSION_X11] = "x11",