Add support to option enable_multiple_session

This commit is contained in:
DL
2026-03-26 14:07:06 +01:00
parent 0b7d78c948
commit 2ab3f50ad0
4 changed files with 46 additions and 5 deletions

View File

@@ -21,6 +21,11 @@ default_session_command = "/usr/bin/diyac -x /usr/bin/diya-login-shell"
# if this setting is not set
default_session_user = "xdg"
# if false keep only one session at a time
# open a new session will close any previously opened session
# default true, optional
enable_multiple_session = false
# User session command
# The command to run to start a user session after the
# login session is successful

View File

@@ -23,6 +23,8 @@ pub struct Configuration {
default_session_user: String, // optional (default root)
/// The command to execute for user sessions (required).
user_session_command: String,
/// flag to enable multiple session
enable_multiple_session: bool,
}
impl Configuration {
@@ -71,6 +73,10 @@ impl Configuration {
.and_then(Value::as_str)
.ok_or("Missing user session command")?
.to_string(),
enable_multiple_session: table
.get("enable_multiple_session")
.and_then(Value::as_bool)
.unwrap_or(true),
})
}
@@ -106,6 +112,14 @@ impl Configuration {
pub fn user_session_command(&self) -> &str {
&self.user_session_command
}
/// Is multiple session enabled
///
/// # Returns
/// * bool value
pub fn enable_multiple_session(&self) -> bool {
self.enable_multiple_session
}
}
impl fmt::Display for Configuration {
@@ -122,6 +136,11 @@ impl fmt::Display for Configuration {
)?;
writeln!(f, " - Default Session User: {}", self.default_session_user)?;
writeln!(f, " - User Session Command: {}", self.user_session_command)?;
writeln!(
f,
" - Enable multiple session: {}",
self.enable_multiple_session
)?;
Ok(())
}
}

View File

@@ -402,7 +402,11 @@ impl SessionManager {
};
match session.authenticate() {
Ok(()) => {
DEBUG!("Authenticate success");
invocation.return_value(Some(&Variant::tuple_from_iter([true.to_variant()])));
if ! self.config.enable_multiple_session() {
self.drop_all_sessions();
}
match self.open_session(self.config.user_session_command(), &session) {
Ok(pid) => self.pids.push(pid),
Err(error) => CRITICAL!("Failed to run user session: {}", error),
@@ -485,11 +489,26 @@ impl SessionManager {
Err(error) => {
CRITICAL!("Unable to get session PID={} status: {}", pid, error);
let _ = kill(*pid, Signal::SIGKILL);
let _ = waitpid(*pid, Some(WaitPidFlag::WNOHANG));
let _ = waitpid(*pid, None);
false
}
});
}
/// Drop all opened session (including the default one)
///
/// # Arguments
///
/// - `&mut self` (`SessionManager`) - SessionManager
///
fn drop_all_sessions(&mut self) {
DEBUG!("Dropping all running sessions");
// kill all running session
for pid in self.pids.drain(..) {
let _ = kill(pid, Signal::SIGKILL);
let _ = waitpid(pid, None);
}
}
}
impl Drop for SessionManager {
@@ -509,10 +528,7 @@ impl Drop for SessionManager {
DEBUG!("Releasing acquired D-Bus name");
gio::bus_unown_name(bus_owner_id);
}
// kill all running session
for pid in self.pids.drain(..) {
let _ = kill(pid, Signal::SIGINT);
}
self.drop_all_sessions();
DEBUG!("Removing signal handlers");
for signal_id in self.signals.drain(..) {
signal_id.remove();

View File

@@ -19,4 +19,5 @@ fn test_configuration_loading() {
config.user_session_command(),
"/usr/bin/diyac -x /usr/bin/diya-shell"
);
assert_eq!(config.enable_multiple_session(), false);
}