#include <string.h>
#include <unistd.h>
#include <sys/epoll.h>
+#include <fcntl.h>
#include "logind-session.h"
#include "strv.h"
}
s->manager = m;
- s->pipe_fd = -1;
+ s->fifo_fd = -1;
s->user = u;
LIST_PREPEND(Session, sessions_by_user, u->sessions, s);
hashmap_remove(s->manager->sessions, s->id);
- session_unset_pipe_fd(s);
+ session_remove_fifo(s);
free(s->state_file);
free(s);
"CGROUP=%s\n",
s->cgroup_path);
+ if (s->fifo_path)
+ fprintf(f,
+ "FIFO=%s\n",
+ s->fifo_path);
+
if (s->seat)
fprintf(f,
"SEAT=%s\n",
"REMOTE", &remote,
"KILL_PROCESSES", &kill_processes,
"CGROUP", &s->cgroup_path,
+ "FIFO", &s->fifo_path,
"SEAT", &seat,
"TTY", &s->tty,
"DISPLAY", &s->display,
s->type = t;
}
+ if (s->fifo_path) {
+ int fd;
+
+ /* If we open an unopened pipe for reading we will not
+ get an EOF. to trigger an EOF we hence open it for
+ reading, but close it right-away which then will
+ trigger the EOF. */
+
+ fd = session_create_fifo(s);
+ if (fd >= 0)
+ close_nointr_nofail(fd);
+ }
+
+
finish:
free(remote);
free(kill_processes);
return seat_apply_acls(s->seat, old_active);
}
-
static int session_link_x11_socket(Session *s) {
char *t, *f, *c;
size_t k;
return -ENOENT;
}
- t = strappend(s->user->runtime_path, "/display");
+ t = strappend(s->user->runtime_path, "/X11/display");
if (!t) {
log_error("Out of memory");
free(f);
return -ENOMEM;
}
+ mkdir_parents(t, 0755);
+
if (link(f, t) < 0) {
if (errno == EEXIST) {
unlink(t);
STRV_FOREACH(k, s->manager->controllers) {
if (strv_contains(s->reset_controllers, *k) ||
+ strv_contains(s->manager->reset_controllers, *k) ||
strv_contains(s->controllers, *k))
continue;
log_warning("Failed to reset controller %s: %s", *k, strerror(-r));
}
+
+ STRV_FOREACH(k, s->manager->reset_controllers) {
+
+ if (strv_contains(s->reset_controllers, *k) ||
+ strv_contains(s->controllers, *k))
+ continue;
+
+ r = cg_attach(*k, "/", s->leader);
+ if (r < 0)
+ log_warning("Failed to reset controller %s: %s", *k, strerror(-r));
+
+ }
}
hashmap_put(s->manager->cgroups, s->cgroup_path, s);
/* Save session data */
session_save(s);
+ user_save(s->user);
session_send_signal(s, true);
if (s->seat) {
+ seat_save(s->seat);
+
if (s->seat->active == s)
seat_send_changed(s->seat, "Sessions\0ActiveSession\0");
else
s->user->display = NULL;
- t = strappend(s->user->runtime_path, "/display");
+ t = strappend(s->user->runtime_path, "/X11/display");
if (!t) {
log_error("Out of memory");
return -ENOMEM;
"IdleSinceHintMonotonic\0");
}
-int session_set_pipe_fd(Session *s, int fd) {
- struct epoll_event ev;
+int session_create_fifo(Session *s) {
int r;
assert(s);
- assert(fd >= 0);
- assert(s->pipe_fd < 0);
- r = hashmap_put(s->manager->pipe_fds, INT_TO_PTR(fd + 1), s);
- if (r < 0)
- return r;
+ /* Create FIFO */
+ if (!s->fifo_path) {
+ r = safe_mkdir("/run/systemd/sessions", 0755, 0, 0);
+ if (r < 0)
+ return r;
- zero(ev);
- ev.events = 0;
- ev.data.u32 = FD_PIPE_BASE + fd;
+ if (asprintf(&s->fifo_path, "/run/systemd/sessions/%s.ref", s->id) < 0)
+ return -ENOMEM;
- if (epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
- assert_se(hashmap_remove(s->manager->pipe_fds, INT_TO_PTR(fd + 1)) == s);
- return -errno;
+ if (mkfifo(s->fifo_path, 0600) < 0 && errno != EEXIST)
+ return -errno;
}
- s->pipe_fd = fd;
- return 0;
-}
+ /* Open reading side */
+ if (s->fifo_fd < 0) {
+ struct epoll_event ev;
-void session_unset_pipe_fd(Session *s) {
- assert(s);
+ s->fifo_fd = open(s->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY);
+ if (s->fifo_fd < 0)
+ return -errno;
- if (s->pipe_fd < 0)
- return;
+ r = hashmap_put(s->manager->fifo_fds, INT_TO_PTR(s->fifo_fd + 1), s);
+ if (r < 0)
+ return r;
- assert_se(hashmap_remove(s->manager->pipe_fds, INT_TO_PTR(s->pipe_fd + 1)) == s);
+ zero(ev);
+ ev.events = 0;
+ ev.data.u32 = FD_FIFO_BASE + s->fifo_fd;
- assert_se(epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_DEL, s->pipe_fd, NULL) == 0);
+ if (epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_ADD, s->fifo_fd, &ev) < 0)
+ return -errno;
+ }
- close_nointr_nofail(s->pipe_fd);
- s->pipe_fd = -1;
+ /* Open writing side */
+ r = open(s->fifo_path, O_WRONLY|O_CLOEXEC|O_NDELAY);
+ if (r < 0)
+ return -errno;
+
+ return r;
}
-int session_check_gc(Session *s) {
+void session_remove_fifo(Session *s) {
+ assert(s);
+
+ if (s->fifo_fd >= 0) {
+ assert_se(hashmap_remove(s->manager->fifo_fds, INT_TO_PTR(s->fifo_fd + 1)) == s);
+ assert_se(epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_DEL, s->fifo_fd, NULL) == 0);
+ close_nointr_nofail(s->fifo_fd);
+ s->fifo_fd = -1;
+ }
+
+ if (s->fifo_path) {
+ unlink(s->fifo_path);
+ free(s->fifo_path);
+ s->fifo_path = NULL;
+ }
+}
+
+int session_check_gc(Session *s, bool drop_not_started) {
int r;
assert(s);
- if (s->pipe_fd >= 0) {
+ if (drop_not_started && !s->started)
+ return 0;
+
+ if (s->fifo_fd >= 0) {
- r = pipe_eof(s->pipe_fd);
+ r = pipe_eof(s->fifo_fd);
if (r < 0)
return r;