chiark / gitweb /
Prep v234: Eventually fix the cgroup stuff. elogind is not init.
[elogind.git] / src / login / elogind.c
index e76654b6008dd1db0a8319450f150881ff0184b7..30cab4949820a90262b2042d0c3919e9e07e28cd 100644 (file)
 #define CGROUPS_AGENT_RCVBUF_SIZE (8*1024*1024)
 
 
-static int signal_agent_released(sd_bus_message *message, void *userdata, sd_bus_error *error) {
-        _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
-        Manager *m = userdata;
-        const char *cgroup;
-        uid_t sender_uid;
-        int r;
-
-        assert(message);
-        assert(m);
-
-        /* only accept org.freedesktop.elogind.Agent from UID=0 */
-        r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_EUID, &creds);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_creds_get_euid(creds, &sender_uid);
-        if (r < 0 || sender_uid != 0)
-                return 0;
-
-        /* parse 'cgroup-empty' notification */
-        r = sd_bus_message_read(message, "s", &cgroup);
-        if (r < 0) {
-                bus_log_parse_error(r);
-                return 0;
-        }
-
-        manager_notify_cgroup_empty(m, cgroup);
-
-        return 0;
-}
-
-/// Add-On for manager_connect_bus()
-void elogind_bus_setup_system(Manager* m) {
-        int r;
-
-        assert(m);
-        assert(m->bus);
-
-        /* if we are a user instance we get the Released message via the system bus */
-        if (MANAGER_IS_USER(m)) {
-                r = sd_bus_add_match(
-                                m->bus,
-                                NULL,
-                                "type='signal',"
-                                "interface='org.freedesktop.elogind.Agent',"
-                                "member='Released',"
-                                "path='/org/freedesktop/elogind/agent'",
-                                signal_agent_released, m);
-                if (r < 0)
-                        log_warning_errno(r, "Failed to register Released match on system bus: %m");
-        }
-
-        log_debug("Successfully connected to system bus.");
-}
-
-static int bus_forward_agent_released(Manager *m, const char *path) {
-        int r;
-
-        assert(m);
-        assert(path);
-
-        if (!MANAGER_IS_SYSTEM(m))
-                return 0;
-
-        if (!m->bus)
-                return 0;
-
-        /* If we are running a system instance we forward the agent message on the system bus, so that the user
-         * instances get notified about this, too */
-
-        r = sd_bus_emit_signal(m->bus,
-                               "/org/freedesktop/elogind/agent",
-                               "org.freedesktop.elogind.Agent",
-                               "Released",
-                               "s", path);
-        if (r < 0)
-                return log_warning_errno(r, "Failed to propagate agent release message: %m");
-
-        return 1;
-}
-
 static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
         Manager *m = userdata;
         char buf[PATH_MAX+1];
@@ -137,19 +56,19 @@ static int manager_dispatch_cgroups_agent_fd(sd_event_source *source, int fd, ui
         buf[n] = 0;
 
         manager_notify_cgroup_empty(m, buf);
-        bus_forward_agent_released(m, buf);
 
         return 0;
 }
 
 /// Add-On for manager_connect_bus()
+/// Original: src/core/manager.c:manager_setup_cgroups_agent()
 int elogind_setup_cgroups_agent(Manager *m) {
 
         static const union sockaddr_union sa = {
                 .un.sun_family = AF_UNIX,
                 .un.sun_path = "/run/systemd/cgroups-agent",
         };
-        int r;
+        int r = 0;
 
         /* This creates a listening socket we receive cgroups agent messages on. We do not use D-Bus for delivering
          * these messages from the cgroups agent binary to PID 1, as the cgroups agent binary is very short-living, and
@@ -170,7 +89,10 @@ int elogind_setup_cgroups_agent(Manager *m) {
         if (!MANAGER_IS_SYSTEM(m))
                 return 0;
 
-        if (cg_unified() > 0) /* We don't need this anymore on the unified hierarchy */
+        r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER);
+        if (r < 0)
+                return log_error_errno(r, "Failed to determine whether unified cgroups hierarchy is used: %m");
+        if (r > 0) /* We don't need this anymore on the unified hierarchy */
                 return 0;
 
         if (m->cgroups_agent_fd < 0) {
@@ -250,7 +172,7 @@ int elogind_manager_new(Manager* m) {
         m->hybrid_sleep_state = NULL;
 
         /* If elogind should be its own controller, mount its cgroup */
-        if (streq(SYSTEMD_CGROUP_CONTROLLER, "name=elogind")) {
+        if (streq(SYSTEMD_CGROUP_CONTROLLER, "_elogind")) {
                 m->is_system = true;
                 r = mount_setup(true);
         } else