X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind.c;h=6b7012ec73f3704cf330288c3877409600e1eaf6;hb=78ff1acdfe6a1f50d4ac62dc354c667999be0508;hp=7fd6515ffd329e80a3163f89696f19a3b9b036a4;hpb=acb14d318b84bda00d1e666d7dab6794d5bbeb3f;p=elogind.git diff --git a/src/login/logind.c b/src/login/logind.c index 7fd6515ff..6b7012ec7 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -6,16 +6,16 @@ Copyright 2011 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -55,10 +55,14 @@ Manager *manager_new(void) { m->seats = hashmap_new(string_hash_func, string_compare_func); m->sessions = hashmap_new(string_hash_func, string_compare_func); m->users = hashmap_new(trivial_hash_func, trivial_compare_func); + m->inhibitors = hashmap_new(string_hash_func, string_compare_func); + m->cgroups = hashmap_new(string_hash_func, string_compare_func); - m->fifo_fds = hashmap_new(trivial_hash_func, trivial_compare_func); + m->session_fds = hashmap_new(trivial_hash_func, trivial_compare_func); + m->inhibitor_fds = hashmap_new(trivial_hash_func, trivial_compare_func); - if (!m->devices || !m->seats || !m->sessions || !m->users || !m->cgroups || !m->fifo_fds) { + if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || + !m->cgroups || !m->session_fds || !m->inhibitor_fds) { manager_free(m); return NULL; } @@ -89,6 +93,7 @@ void manager_free(Manager *m) { User *u; Device *d; Seat *s; + Inhibitor *i; assert(m); @@ -104,12 +109,18 @@ void manager_free(Manager *m) { while ((s = hashmap_first(m->seats))) seat_free(s); - hashmap_free(m->sessions); - hashmap_free(m->users); + while ((i = hashmap_first(m->inhibitors))) + inhibitor_free(i); + hashmap_free(m->devices); hashmap_free(m->seats); + hashmap_free(m->sessions); + hashmap_free(m->users); + hashmap_free(m->inhibitors); + hashmap_free(m->cgroups); - hashmap_free(m->fifo_fds); + hashmap_free(m->session_fds); + hashmap_free(m->inhibitor_fds); if (m->console_active_fd >= 0) close_nointr_nofail(m->console_active_fd); @@ -268,6 +279,30 @@ int manager_add_user_by_uid(Manager *m, uid_t uid, User **_user) { return manager_add_user(m, uid, p->pw_gid, p->pw_name, _user); } +int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **_inhibitor) { + Inhibitor *i; + + assert(m); + assert(id); + + i = hashmap_get(m->inhibitors, id); + if (i) { + if (_inhibitor) + *_inhibitor = i; + + return 0; + } + + i = inhibitor_new(m, id); + if (!i) + return -ENOMEM; + + if (_inhibitor) + *_inhibitor = i; + + return 0; +} + int manager_process_seat_device(Manager *m, struct udev_device *d) { Device *device; int r; @@ -412,10 +447,9 @@ int manager_enumerate_seats(Manager *m) { } static int manager_enumerate_users_from_cgroup(Manager *m) { - int r = 0; + int r = 0, k; char *name; DIR *d; - int k; r = cg_enumerate_subgroups(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_path, &d); if (r < 0) { @@ -641,6 +675,46 @@ int manager_enumerate_sessions(Manager *m) { return r; } +int manager_enumerate_inhibitors(Manager *m) { + DIR *d; + struct dirent *de; + int r = 0; + + assert(m); + + d = opendir("/run/systemd/inhibit"); + if (!d) { + if (errno == ENOENT) + return 0; + + log_error("Failed to open /run/systemd/inhibit: %m"); + return -errno; + } + + while ((de = readdir(d))) { + int k; + Inhibitor *i; + + if (!dirent_is_file(de)) + continue; + + k = manager_add_inhibitor(m, de->d_name, &i); + if (k < 0) { + log_notice("Couldn't add inhibitor %s: %s", de->d_name, strerror(-k)); + r = k; + continue; + } + + k = inhibitor_load(i); + if (k < 0) + r = k; + } + + closedir(d); + + return r; +} + int manager_dispatch_seat_udev(Manager *m) { struct udev_device *d; int r; @@ -853,15 +927,28 @@ void manager_cgroup_notify_empty(Manager *m, const char *cgroup) { static void manager_pipe_notify_eof(Manager *m, int fd) { Session *s; + Inhibitor *i; assert_se(m); assert_se(fd >= 0); - assert_se(s = hashmap_get(m->fifo_fds, INT_TO_PTR(fd + 1))); - assert(s->fifo_fd == fd); - session_remove_fifo(s); + s = hashmap_get(m->session_fds, INT_TO_PTR(fd + 1)); + if (s) { + assert(s->fifo_fd == fd); + session_remove_fifo(s); + session_stop(s); + return; + } - session_stop(s); + i = hashmap_get(m->inhibitor_fds, INT_TO_PTR(fd + 1)); + if (i) { + assert(i->fifo_fd == fd); + inhibitor_stop(i); + inhibitor_free(i); + return; + } + + assert_not_reached("Got EOF on unknown pipe"); } static int manager_connect_bus(Manager *m) { @@ -945,14 +1032,16 @@ static int manager_connect_console(Manager *m) { assert(m); assert(m->console_active_fd < 0); + /* On certain architectures (S390 and Xen, and containers), + /dev/tty0 does not exist, so don't fail if we can't open + it. */ + if (access("/dev/tty0", F_OK) < 0) { + m->console_active_fd = -1; + return 0; + } + m->console_active_fd = open("/sys/class/tty/tty0/active", O_RDONLY|O_NOCTTY|O_CLOEXEC); if (m->console_active_fd < 0) { - - /* On certain architectures (S390 and Xen), /dev/tty0 - does not exist, so don't fail if we can't open it.*/ - if (errno == ENOENT) - return 0; - log_error("Failed to open /sys/class/tty/tty0/active: %m"); return -errno; } @@ -1068,12 +1157,14 @@ void manager_gc(Manager *m, bool drop_not_started) { int manager_get_idle_hint(Manager *m, dual_timestamp *t) { Session *s; - bool idle_hint = true; + bool idle_hint; dual_timestamp ts = { 0, 0 }; Iterator i; assert(m); + idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, t); + HASHMAP_FOREACH(s, m->sessions, i) { dual_timestamp k; int ih; @@ -1108,11 +1199,15 @@ int manager_startup(Manager *m) { Seat *seat; Session *session; User *user; + Inhibitor *inhibitor; Iterator i; assert(m); assert(m->epoll_fd <= 0); + cg_shorten_controllers(m->reset_controllers); + cg_shorten_controllers(m->controllers); + m->epoll_fd = epoll_create1(EPOLL_CLOEXEC); if (m->epoll_fd < 0) return -errno; @@ -1142,6 +1237,7 @@ int manager_startup(Manager *m) { manager_enumerate_seats(m); manager_enumerate_users(m); manager_enumerate_sessions(m); + manager_enumerate_inhibitors(m); /* Remove stale objects before we start them */ manager_gc(m, false); @@ -1156,6 +1252,9 @@ int manager_startup(Manager *m) { HASHMAP_FOREACH(session, m->sessions, i) session_start(session); + HASHMAP_FOREACH(inhibitor, m->inhibitors, i) + inhibitor_start(inhibitor); + return 0; } @@ -1216,7 +1315,7 @@ static int manager_parse_config_file(Manager *m) { assert(m); - fn = "/etc/systemd/systemd-logind.conf"; + fn = "/etc/systemd/logind.conf"; f = fopen(fn, "re"); if (!f) { if (errno == ENOENT) @@ -1240,6 +1339,7 @@ int main(int argc, char *argv[]) { int r; log_set_target(LOG_TARGET_AUTO); + log_set_facility(LOG_AUTH); log_parse_environment(); log_open();