chiark / gitweb /
build-sys: add a number of missing header files to EXTRA_DIST
[elogind.git] / src / logind.c
index d38d7d51c3e21270a528331a2207732fa5a7f7fc..f96ace2315734b4dcd99b14a2d8c6f015cc369e6 100644 (file)
@@ -32,6 +32,8 @@
 #include "logind.h"
 #include "dbus-common.h"
 #include "dbus-loop.h"
+#include "strv.h"
+#include "conf-parser.h"
 
 Manager *manager_new(void) {
         Manager *m;
@@ -54,7 +56,14 @@ Manager *manager_new(void) {
         m->cgroups = hashmap_new(string_hash_func, string_compare_func);
         m->fifo_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
 
-        if (!m->devices || !m->seats || !m->sessions || !m->users) {
+        if (!m->devices || !m->seats || !m->sessions || !m->users || !m->cgroups || !m->fifo_fds) {
+                manager_free(m);
+                return NULL;
+        }
+
+        m->reset_controllers = strv_new("cpu", NULL);
+        m->kill_exclude_users = strv_new("root", NULL);
+        if (!m->reset_controllers || !m->kill_exclude_users) {
                 manager_free(m);
                 return NULL;
         }
@@ -124,6 +133,11 @@ void manager_free(Manager *m) {
         if (m->epoll_fd >= 0)
                 close_nointr_nofail(m->epoll_fd);
 
+        strv_free(m->controllers);
+        strv_free(m->reset_controllers);
+        strv_free(m->kill_only_users);
+        strv_free(m->kill_exclude_users);
+
         free(m->cgroup_path);
         free(m);
 }
@@ -257,11 +271,6 @@ int manager_process_seat_device(Manager *m, struct udev_device *d) {
 
         assert(m);
 
-        /* FIXME: drop this check as soon as libudev's enum support
-         * honours tags and subsystem matches at the same time */
-        if (!streq_ptr(udev_device_get_subsystem(d), "graphics"))
-                return 0;
-
         if (streq_ptr(udev_device_get_action(d), "remove")) {
 
                 /* FIXME: use syspath instead of sysname here, as soon as fb driver is fixed */
@@ -277,7 +286,7 @@ int manager_process_seat_device(Manager *m, struct udev_device *d) {
                 Seat *seat;
 
                 sn = udev_device_get_property_value(d, "ID_SEAT");
-                if (!sn)
+                if (isempty(sn))
                         sn = "seat0";
 
                 if (!seat_name_is_valid(sn)) {
@@ -442,7 +451,6 @@ static int manager_enumerate_users_from_cgroup(Manager *m) {
         return r;
 }
 
-
 static int manager_enumerate_linger_users(Manager *m) {
         DIR *d;
         struct dirent *de;
@@ -555,6 +563,9 @@ static int manager_enumerate_sessions_from_cgroup(Manager *m) {
                 while ((k = cg_read_subgroup(d, &name)) > 0) {
                         Session *session;
 
+                        if (streq(name, "shared"))
+                                continue;
+
                         k = manager_add_session(m, u, name, &session);
                         if (k < 0) {
                                 free(name);
@@ -966,7 +977,7 @@ static int manager_connect_udev(Manager *m) {
         return 0;
 }
 
-void manager_gc(Manager *m) {
+void manager_gc(Manager *m, bool drop_not_started) {
         Seat *seat;
         Session *session;
         User *user;
@@ -977,7 +988,7 @@ void manager_gc(Manager *m) {
                 LIST_REMOVE(Seat, gc_queue, m->seat_gc_queue, seat);
                 seat->in_gc_queue = false;
 
-                if (seat_check_gc(seat) == 0) {
+                if (seat_check_gc(seat, drop_not_started) == 0) {
                         seat_stop(seat);
                         seat_free(seat);
                 }
@@ -987,7 +998,7 @@ void manager_gc(Manager *m) {
                 LIST_REMOVE(Session, gc_queue, m->session_gc_queue, session);
                 session->in_gc_queue = false;
 
-                if (session_check_gc(session) == 0) {
+                if (session_check_gc(session, drop_not_started) == 0) {
                         session_stop(session);
                         session_free(session);
                 }
@@ -997,7 +1008,7 @@ void manager_gc(Manager *m) {
                 LIST_REMOVE(User, gc_queue, m->user_gc_queue, user);
                 user->in_gc_queue = false;
 
-                if (user_check_gc(user) == 0) {
+                if (user_check_gc(user, drop_not_started) == 0) {
                         user_stop(user);
                         user_free(user);
                 }
@@ -1081,6 +1092,9 @@ int manager_startup(Manager *m) {
         manager_enumerate_users(m);
         manager_enumerate_sessions(m);
 
+        /* Remove stale objects before we start them */
+        manager_gc(m, false);
+
         /* And start everything */
         HASHMAP_FOREACH(seat, m->seats, i)
                 seat_start(seat);
@@ -1101,12 +1115,12 @@ int manager_run(Manager *m) {
                 struct epoll_event event;
                 int n;
 
-                manager_gc(m);
+                manager_gc(m, true);
 
                 if (dbus_connection_dispatch(m->bus) != DBUS_DISPATCH_COMPLETE)
                         continue;
 
-                manager_gc(m);
+                manager_gc(m, true);
 
                 n = epoll_wait(m->epoll_fd, &event, 1, -1);
                 if (n < 0) {
@@ -1144,6 +1158,48 @@ int manager_run(Manager *m) {
         return 0;
 }
 
+static int manager_parse_config_file(Manager *m) {
+
+        const ConfigItem items[] = {
+                { "NAutoVTs",          config_parse_unsigned, 0, &m->n_autovts,           "Login" },
+                { "KillUserProcesses", config_parse_bool,     0, &m->kill_user_processes, "Login" },
+                { "KillOnlyUsers",     config_parse_strv,     0, &m->kill_only_users,     "Login" },
+                { "KillExcludeUsers",  config_parse_strv,     0, &m->kill_exclude_users,  "Login" },
+                { "Controllers",       config_parse_strv,     0, &m->controllers,         "Login" },
+                { "ResetControllers",  config_parse_strv,     0, &m->reset_controllers,   "Login" },
+                { NULL, NULL, 0, NULL, NULL }
+        };
+
+        static const char * const sections[] = {
+                "Login",
+                NULL
+        };
+
+        FILE *f;
+        const char *fn;
+        int r;
+
+        assert(m);
+
+        fn = "/etc/systemd/systemd-logind.conf";
+        f = fopen(fn, "re");
+        if (!f) {
+                if (errno == ENOENT)
+                        return 0;
+
+                log_warning("Failed to open configuration file %s: %m", fn);
+                return -errno;
+        }
+
+        r = config_parse(fn, f, sections, items, false, NULL);
+        if (r < 0)
+                log_warning("Failed to parse configuration file: %s", strerror(-r));
+
+        fclose(f);
+
+        return r;
+}
+
 int main(int argc, char *argv[]) {
         Manager *m = NULL;
         int r;
@@ -1167,6 +1223,8 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        manager_parse_config_file(m);
+
         r = manager_startup(m);
         if (r < 0) {
                 log_error("Failed to fully start up daemon: %s", strerror(-r));