From 9c7da53854872cd82e3025efda0fda0e31fda487 Mon Sep 17 00:00:00 2001 From: r0chd Date: Thu, 20 Aug 2026 21:06:51 +0200 Subject: [PATCH] deps(sessiond): update session management protocol --- protocols/session_management_v2.xml | 55 ++------------------ src/main.rs | 80 +++++++++++------------------ 2 files changed, 36 insertions(+), 99 deletions(-) diff --git a/protocols/session_management_v2.xml b/protocols/session_management_v2.xml index 65b4866..096d9cf 100644 --- a/protocols/session_management_v2.xml +++ b/protocols/session_management_v2.xml @@ -31,7 +31,7 @@ Returns a session_management_session object bound to the calling connection. The client may stage optional fields before creating the - session directly or through a delegated cgroup object. + session directly or with a delegated cgroup. @@ -99,56 +99,11 @@ - - Must be sent while staged. Creates the cgroup that will contain the - session and returns an independent cgroup control object. The object - exposes the path for a session supervisor such as dinit to pass to its - --cgroup-path option and manage directly. The object owns the cgroup and - its destruction destroys the cgroup. + + Must be sent while staged. The daemon will create and delegate the + session cgroup when the session is committed. The requesting process is + placed in it and may discover its path through /proc/self/cgroup. - - - - - - - Control object for the cgroup created for a staged session. The object is - usable independently by a session supervisor such as dinit, which can - manage the cgroup using the delegated path. Destroying this object - destroys the delegated cgroup. - - - - Reports the exact path of the cgroup created for this object. The client - may use this path to edit the cgroup directly. - - - - - - - - - - - Must be sent before the session is committed. May be sent repeatedly. - The requested controller name is made available to the delegated manager - when supported by the kernel and permitted by daemon policy. The daemon - does not enable the controller in the delegated cgroup; the delegated - manager may enable it for its own child cgroups. - - - - - - Must be sent after all controller requests and before the owning session - is committed. After this request, no further controller requests are - allowed. The daemon creates and delegates the cgroup when the owning - session is committed, then responds with path or error. - - - - diff --git a/src/main.rs b/src/main.rs index 3df04f8..4536466 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,7 @@ use calloop::{generic, timer}; use clap::{Parser, ValueEnum}; use hyprwire::client; use session_core_v1::{session_core_manager, session_core_session}; -use session_management_v2::{ - session_management_cgroup, session_management_session, session_manager, -}; +use session_management_v2::{session_management_session, session_manager}; use std::collections::BTreeMap; use std::os::fd::AsRawFd; use std::os::unix::process::CommandExt; @@ -57,9 +55,6 @@ struct PendingManagedSession { uid: u32, object: session_management_session::SessionManagementSession, envs: BTreeMap, - hook: Option, - cgroup_delegate: Option, - delegated_cgroup_path: Option, } struct ManagedSession { @@ -69,7 +64,6 @@ struct ManagedSession { envs: BTreeMap, hook: Option, config: config::Config, - _cgroup_delegate: Option, } impl ManagedSession { @@ -235,6 +229,15 @@ impl ManagedSession { } } +fn current_cgroup_path() -> anyhow::Result { + let cgroup = std::fs::read_to_string("/proc/self/cgroup")?; + cgroup + .lines() + .find_map(|line| line.strip_prefix("0::")) + .map(str::to_owned) + .ok_or_else(|| anyhow::anyhow!("unified cgroup path not found in /proc/self/cgroup")) +} + struct SessiondHooks { pending_managed_sessions: Vec, managed_sessions: Vec, @@ -333,14 +336,28 @@ impl hyprwire::Dispatch fo return; }; + let cgroup_path = if self.delegate_cgroup { + match current_cgroup_path() { + Ok(path) => path, + Err(err) => { + log::error!( + uid = session.uid, + error:% = err; + "failed to determine delegated cgroup path" + ); + String::new() + } + } + } else { + String::new() + }; + let ctx = config::SessionContext { uid: session.uid, user: user.name().to_string_lossy().into_owned(), home: user.home_dir().to_string_lossy().into_owned(), shell: user.shell().to_string_lossy().into_owned(), - cgroup_path: session - .delegated_cgroup_path - .map_or_else(String::new, |path| path.to_string_lossy().into_owned()), + cgroup_path, }; let config = match config::Config::load(&self.config_path, &ctx) { Ok(config) => config, @@ -359,9 +376,8 @@ impl hyprwire::Dispatch fo uid: session.uid, _object: session.object, envs: session.envs, - hook: session.hook, + hook: None, config, - _cgroup_delegate: session.cgroup_delegate, }; managed_session.envs.extend(BTreeMap::from([ ( @@ -456,23 +472,15 @@ impl hyprwire::Dispatch for SessiondHo .send_create_session::(session.uid) .unwrap(); - let mut pending_managed_session = PendingManagedSession { + let pending_managed_session = PendingManagedSession { id: 0, uid: session.uid, object: session_object, envs: BTreeMap::new(), - hook: None, - cgroup_delegate: None, - delegated_cgroup_path: None, }; - if self.delegate_cgroup - && let Some(cgroup_delegate) = pending_managed_session - .object - .send_delegate_cgroup::() - { - cgroup_delegate.send_commit(); - pending_managed_session.cgroup_delegate = Some(cgroup_delegate); + if self.delegate_cgroup { + pending_managed_session.object.send_delegate_cgroup(); } pending_managed_session .object @@ -586,32 +594,6 @@ impl hyprwire::Dispatch for SessiondHo } } -impl hyprwire::Dispatch for SessiondHooks { - fn event( - &mut self, - object: &session_management_cgroup::SessionManagementCgroup, - event: ::Event<'_>, - ) { - match event { - session_management_cgroup::Event::Path { path } => { - let Some(session) = self.pending_managed_sessions.iter_mut().find(|session| { - session - .cgroup_delegate - .as_ref() - .is_some_and(|delegate| delegate == object) - }) else { - return; - }; - session.delegated_cgroup_path = Some(path.into()); - } - session_management_cgroup::Event::Error { - code: _, - message: _, - } => {} - } - } -} - fn main() -> anyhow::Result<()> { let cli = Cli::parse(); let config_path = cli -- 2.54.0