chiark / gitweb /
logind: move default reset controller/kill exclude list into logind
[elogind.git] / src / logind.c
index d38d7d51c3e21270a528331a2207732fa5a7f7fc..28ba58bf5481bab8c29445c1ab957ab143cb4ed7 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 */
@@ -1144,6 +1153,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" },
+                { "KilOnlyUsers",      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 +1218,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));