goto fail;
}
- session->pipe_fd = pipe_fds[0];
+ r = session_set_pipe_fd(session, pipe_fds[0]);
+ if (r < 0)
+ goto fail;
pipe_fds[0] = -1;
if (s) {
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <sys/epoll.h>
#include "logind-session.h"
#include "strv.h"
hashmap_remove(s->manager->sessions, s->id);
- if (s->pipe_fd >= 0)
- close_nointr_nofail(s->pipe_fd);
+ session_unset_pipe_fd(s);
free(s->state_file);
free(s);
"IdleSinceHintMonotonic\0");
}
+int session_set_pipe_fd(Session *s, int fd) {
+ struct epoll_event ev;
+ 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;
+
+ zero(ev);
+ ev.events = 0;
+ ev.data.u32 = FD_PIPE_BASE + fd;
+
+ 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;
+ }
+
+ s->pipe_fd = fd;
+ return 0;
+}
+
+void session_unset_pipe_fd(Session *s) {
+ assert(s);
+
+ if (s->pipe_fd < 0)
+ return;
+
+ assert_se(hashmap_remove(s->manager->pipe_fds, INT_TO_PTR(s->pipe_fd + 1)) == s);
+
+ assert_se(epoll_ctl(s->manager->epoll_fd, EPOLL_CTL_DEL, s->pipe_fd, NULL) == 0);
+
+ close_nointr_nofail(s->pipe_fd);
+ s->pipe_fd = -1;
+}
+
int session_check_gc(Session *s) {
int r;
bool session_is_active(Session *s);
int session_get_idle_hint(Session *s, dual_timestamp *t);
void session_set_idle_hint(Session *s, bool b);
+int session_set_pipe_fd(Session *s, int fd);
+void session_unset_pipe_fd(Session *s);
int session_start(Session *s);
int session_stop(Session *s);
int session_save(Session *s);
#include "dbus-common.h"
#include "dbus-loop.h"
-enum {
- FD_UDEV,
- FD_CONSOLE,
- FD_BUS
-};
-
Manager *manager_new(void) {
Manager *m;
m->sessions = hashmap_new(string_hash_func, string_compare_func);
m->users = hashmap_new(trivial_hash_func, trivial_compare_func);
m->cgroups = hashmap_new(string_hash_func, string_compare_func);
+ m->pipe_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
if (!m->devices || !m->seats || !m->sessions || !m->users) {
manager_free(m);
hashmap_free(m->devices);
hashmap_free(m->seats);
hashmap_free(m->cgroups);
+ hashmap_free(m->pipe_fds);
if (m->console_active_fd >= 0)
close_nointr_nofail(m->console_active_fd);
free(p);
}
+static void manager_pipe_notify_eof(Manager *m, int fd) {
+ Session *s;
+
+ assert_se(m);
+ assert_se(fd >= 0);
+
+ assert_se(s = hashmap_get(m->pipe_fds, INT_TO_PTR(fd + 1)));
+ assert(s->pipe_fd == fd);
+ session_unset_pipe_fd(s);
+
+ session_add_to_gc_queue(s);
+}
+
static int manager_connect_bus(Manager *m) {
DBusError error;
int r;
case FD_BUS:
bus_loop_dispatch(m->bus_fd);
break;
+
+ default:
+ if (event.data.u32 >= FD_PIPE_BASE)
+ manager_pipe_notify_eof(m, event.data.u32 - FD_PIPE_BASE);
}
}
* recreate VTs when disallocated
* spawn user systemd
* direct client API
- * subscribe to fd HUP
* D-Bus method: AttachDevice(seat, device);
- * D-Bus method: PermitLinger(user, bool b);
+ * D-Bus method: SetLinger(user, bool b);
*
* non-local X11 server
* reboot/shutdown halt management
unsigned long session_counter;
Hashmap *cgroups;
+ Hashmap *pipe_fds;
+};
+
+enum {
+ FD_UDEV,
+ FD_CONSOLE,
+ FD_BUS,
+ FD_PIPE_BASE
};
Manager *manager_new(void);