chiark / gitweb /
logind: parse configuration file
[elogind.git] / src / logind.c
index 8fa766129096b326fbded4fcf7113ca8bc9ad0c4..fd17d80541e8dbd02fe28d454456dc48292bec7f 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;
@@ -52,7 +54,7 @@ Manager *manager_new(void) {
         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);
+        m->fifo_fds = hashmap_new(trivial_hash_func, trivial_compare_func);
 
         if (!m->devices || !m->seats || !m->sessions || !m->users) {
                 manager_free(m);
@@ -98,7 +100,7 @@ void manager_free(Manager *m) {
         hashmap_free(m->devices);
         hashmap_free(m->seats);
         hashmap_free(m->cgroups);
-        hashmap_free(m->pipe_fds);
+        hashmap_free(m->fifo_fds);
 
         if (m->console_active_fd >= 0)
                 close_nointr_nofail(m->console_active_fd);
@@ -124,6 +126,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);
 }
@@ -729,7 +736,7 @@ int manager_spawn_autovt(Manager *m, int vtnr) {
                 goto finish;
         }
 
-        if (asprintf(&name, "autovt-getty@tty%i.service", vtnr) < 0) {
+        if (asprintf(&name, "autovt@tty%i.service", vtnr) < 0) {
                 log_error("Could not allocate service name.");
                 r = -ENOMEM;
                 goto finish;
@@ -802,9 +809,9 @@ static void manager_pipe_notify_eof(Manager *m, int fd) {
         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);
+        assert_se(s = hashmap_get(m->fifo_fds, INT_TO_PTR(fd + 1)));
+        assert(s->fifo_fd == fd);
+        session_remove_fifo(s);
 
         session_stop(s);
 }
@@ -1081,9 +1088,6 @@ int manager_startup(Manager *m) {
         manager_enumerate_users(m);
         manager_enumerate_sessions(m);
 
-        /* Get rid of objects that are no longer used */
-        manager_gc(m);
-
         /* And start everything */
         HASHMAP_FOREACH(seat, m->seats, i)
                 seat_start(seat);
@@ -1139,14 +1143,56 @@ int manager_run(Manager *m) {
                         break;
 
                 default:
-                        if (event.data.u32 >= FD_PIPE_BASE)
-                                manager_pipe_notify_eof(m, event.data.u32 - FD_PIPE_BASE);
+                        if (event.data.u32 >= FD_FIFO_BASE)
+                                manager_pipe_notify_eof(m, event.data.u32 - FD_FIFO_BASE);
                 }
         }
 
         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;
@@ -1170,6 +1216,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));