Compare commits

..

No commits in common. "495e591dc65987a0327b9dea646126ebdfe8a1db" and "da592cc15eda90accc44b519e2fc02169e9a3111" have entirely different histories.

10 changed files with 999 additions and 693 deletions

View file

@ -4,7 +4,7 @@ use_field_init_shorthand = true
# Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt`
format_code_in_doc_comments = true
format_strings = true
imports_granularity = "Module"
imports_granularity = "Crate"
normalize_comments = true
reorder_impl_items = true
wrap_comments = true

View file

@ -1,15 +0,0 @@
{
"format_on_save": "on",
"lsp": {
"rust-analyzer": {
"initialization_options": {
"check": {
"command": "clippy",
},
"rustfmt": {
"extraArgs": ["+nightly"],
},
},
},
},
}

1471
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,21 +4,25 @@ description = "The session manager for the COSMIC desktop environment"
version = "1.0.0"
license = "GPL-3.0-only"
edition = "2024"
rust-version = "1.93"
rust-version = "1.85"
authors = ["Lucy <lucy@system76.com>"]
publish = false
[dependencies]
async-signals = "0.5"
color-eyre = "0.6"
futures-util = "0.3"
cosmic-dbus-a11y = { git = "https://github.com/pop-os/dbus-settings-bindings" }
freedesktop-desktop-entry = { version = "0.8", optional = true }
shell-words = { version = "1.1.1", optional = true }
freedesktop-desktop-entry = { version = "0.7.14", optional = true }
shell-words = { version = "1.1.0", optional = true }
dirs = { version = "6.0.0", optional = true }
itertools = "0.14"
launch-pad = { git = "https://github.com/pop-os/launch-pad" }
libc = "0.2"
log-panics = { version = "2", features = ["with-backtrace"] }
rustix = "1.1"
rustix = "1.0"
scopeguard = "1"
sendfd = { version = "0.4", features = ["tokio"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = [
@ -34,14 +38,15 @@ tokio = { version = "1", features = [
"sync",
"time",
] }
zbus_systemd = { version = "0.26000.0", optional = true, features = [
zbus_systemd = { version = "0.25701.0", optional = true, features = [
"systemd1",
] }
tokio-util = "0.7"
tracing = "0.1"
tracing-journald = { version = "0.3", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
zbus = { version = "5.14.0", default-features = false, features = ["tokio"] }
zbus = { version = "5.10.0", default-features = false, features = ["tokio"] }
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
logind-zbus = { version = "5.3.2", optional = true }
[features]

View file

@ -29,7 +29,6 @@ if [ -n "${SHELL}" ]; then
fi
export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:=COSMIC}"
export XDG_SESSION_DESKTOP="${XDG_SESSION_DESKTOP:=COSMIC}"
export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:=wayland}"
export _JAVA_AWT_WM_NONREPARENTING=1
export GDK_BACKEND=wayland,x11
@ -39,22 +38,6 @@ export QT_AUTO_SCREEN_SCALE_FACTOR=1
export QT_ENABLE_HIGHDPI_SCALING=1
export DCONF_PROFILE=cosmic
# Set the QT platform theme to CuteCosmic. Fallback to qt6ct if CuteCosmic is not installed.
if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
export QT_QPA_PLATFORMTHEME=cosmic
for QT_PLUGIN_PATH in /usr/lib{*,/*}/qt6/plugins; do
if [ -f "${QT_PLUGIN_PATH}/platformthemes/libcutecosmictheme.so" ]; then
# CuteCosmic found, no need for a fallback.
export QT_QPA_PLATFORMTHEME=cosmic
break
elif [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt6ct.so" ] || [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt5ct.so" ]; then
# Fallback to qt6ct, but keep looking for CuteCosmic.
# Note that "qt5ct" is compatible with both qt5ct and qt6ct.
export QT_QPA_PLATFORMTHEME=qt5ct
fi
done
fi
# Start gnome keyring components if the daemon is active
# -> check if /run/user/$UID/keyring exists
if [ -d "/run/user/$(id -u)/keyring" ]; then
@ -86,23 +69,16 @@ if command -v systemctl >/dev/null; then
# environment, update it.
mapfile -t existing_env_vars < <(systemctl --user show-environment)
for env_var in "${existing_env_vars[@]}"; do
env_var_name="${env_var%%=*}"
env_var_value=${!env_var_name:-}
env_var_name="$(echo "${env_var}" | awk -F '=' '{print $1}')"
env_var_val_str_to_compare="${env_var_name}=${!env_var_name:-}"
# Skip current iteration if the environment variable's value
# in the current envionment is unset.
if [[ -z "${env_var_value}" ]]; then
continue
if [[ "${env_var}" != "${env_var_val_str_to_compare}" ]]; then
# Update only if the value in current environment is non-empty
env_var_unassigned_str="${env_var_name}="
if [[ "${env_var_val_str_to_compare}" != "${env_var_unassigned_str}" ]]; then
systemctl --user import-environment "${env_var_name}" ||:
fi
fi
env_var_val_str_to_compare="${env_var_name}=${env_var_value}"
env_var_val_str_to_compare_ansi_c_quoted="${env_var_name}=\$'$(printf '%q' "${env_var_value}")'"
if [[ "${env_var}" == "${env_var_val_str_to_compare}" ]]; then
continue
elif [[ "${env_var}" == "${env_var_val_str_to_compare_ansi_c_quoted}" ]]; then
continue
fi
systemctl --user import-environment "${env_var_name}" ||:
done
fi

1
debian/control vendored
View file

@ -12,7 +12,6 @@ Homepage: https://github.com/pop-os/cosmic-session
Package: cosmic-session
Architecture: amd64 arm64
Conflicts: seatd
Depends:
${misc:Depends},
${shlibs:Depends},

View file

@ -1,19 +1,17 @@
// SPDX-License-Identifier: GPL-3.0-only
use color_eyre::eyre::{Result, WrapErr};
use launch_pad::ProcessManager;
use launch_pad::process::Process;
use launch_pad::{ProcessManager, process::Process};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::os::unix::prelude::*;
use tokio::io::AsyncReadExt;
use tokio::net::UnixStream;
use tokio::net::unix::OwnedReadHalf;
use tokio::sync::{mpsc, oneshot};
use tokio::task::JoinHandle;
use std::{collections::HashMap, os::unix::prelude::*};
use tokio::{
io::AsyncReadExt,
net::{UnixStream, unix::OwnedReadHalf},
sync::{mpsc, oneshot},
task::JoinHandle,
};
use tokio_util::sync::CancellationToken;
use crate::process::mark_as_not_cloexec;
use crate::service::SessionRequest;
use crate::{process::mark_as_not_cloexec, service::SessionRequest};
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "message")]

View file

@ -9,36 +9,36 @@ mod process;
mod service;
mod systemd;
use color_eyre::Result;
use color_eyre::eyre::WrapErr;
use launch_pad::ProcessManager;
use launch_pad::process::Process;
use async_signals::Signals;
use color_eyre::{Result, eyre::WrapErr};
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
use futures_util::StreamExt;
#[cfg(feature = "autostart")]
use itertools::Itertools;
use launch_pad::{ProcessManager, process::Process};
use service::SessionRequest;
use std::borrow::Cow;
#[cfg(feature = "autostart")]
use std::collections::HashSet;
use std::env;
use std::os::fd::AsRawFd;
#[cfg(feature = "autostart")]
use std::path::PathBuf;
#[cfg(feature = "autostart")]
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::{borrow::Cow, env, os::fd::AsRawFd, sync::Arc};
#[cfg(feature = "systemd")]
use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
use tokio::signal::unix::{SignalKind, signal};
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::{Mutex, oneshot};
use tokio::time::Duration;
use tokio_util::sync::CancellationToken;
use tracing::Instrument;
use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{EnvFilter, fmt};
use crate::notifications::{
DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD, notifications_process,
use tokio::{
sync::{
Mutex,
mpsc::{Receiver, Sender},
oneshot,
},
time::Duration,
};
use tokio_util::sync::CancellationToken;
use tracing::{Instrument, metadata::LevelFilter};
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
use crate::notifications::notifications_process;
#[cfg(feature = "autostart")]
const AUTOSTART_DIR: &'static str = "autostart";
#[cfg(feature = "autostart")]
@ -165,7 +165,7 @@ async fn start(
Ok(env) => {
for systemd_env in env {
// Only update the envvar if unset
if std::env::var_os(&systemd_env.key).is_none() {
if std::env::var_os(&systemd_env.key) == None {
// Blacklist of envvars that we shouldn't touch (taken from KDE)
if (!systemd_env.key.starts_with("XDG_")
|| systemd_env.key == "XDG_DATA_DIRS"
@ -244,8 +244,10 @@ async fn start(
.instrument(stderr_span)
})
.with_on_exit(move |_, _, _, will_restart| {
if !will_restart && let Some(tx) = settings_exit_tx.lock().unwrap().take() {
_ = tx.send(());
if !will_restart {
if let Some(tx) = settings_exit_tx.lock().unwrap().take() {
_ = tx.send(());
}
}
async {}
}),
@ -413,9 +415,7 @@ async fn start(
if let Some(program_name) = exec_words.next() {
// filter out any placeholder args, since we might not be able to deal with them
let filtered_args = exec_words
.filter(|s| !s.starts_with("%"))
.collect::<Vec<_>>();
let filtered_args = exec_words.filter(|s| !s.starts_with("%")).collect_vec();
// escape them
let escaped_args = shell_words::split(&*filtered_args.join(" "));
@ -457,8 +457,7 @@ async fn start(
info!("started {} programs", dedupe.len());
}
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to bind SIGTERM handler");
let mut sigint = signal(SignalKind::interrupt()).expect("Failed to bind SIGINT handler");
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
let mut status = Status::Exited;
let session_dbus_rx_next = session_rx.recv();
tokio::select! {
@ -476,11 +475,12 @@ async fn start(
}
}
},
_ = sigterm.recv() => {
info!("EXITING: received SIGTERM request to terminate");
},
_ = sigint.recv() => {
info!("EXITING: received SIGINT request to terminate");
signal = signals.next() => match signal {
Some(libc::SIGTERM | libc::SIGINT) => {
info!("EXITING: received request to terminate");
}
Some(signal) => unreachable!("EXITING: received unhandled signal {}", signal),
None => {},
}
}
@ -534,15 +534,17 @@ async fn start_component(
})
.with_on_start(move |pman, pkey, _will_restart| async move {
#[cfg(feature = "systemd")]
if *is_systemd_used()
&& let Ok((innr_cmd, Some(pid))) = pman.get_exe_and_pid(pkey).await
&& let Err(err) = spawn_scope(innr_cmd.clone(), vec![pid]).await
{
warn!(
"Failed to spawn scope for {}. Creating transient unit failed with {}",
innr_cmd, err
);
};
if *is_systemd_used() {
if let Ok((innr_cmd, Some(pid))) = pman.get_exe_and_pid(pkey).await {
if let Err(err) = spawn_scope(innr_cmd.clone(), vec![pid]).await {
warn!(
"Failed to spawn scope for {}. Creating transient unit failed \
with {}",
innr_cmd, err
);
};
}
}
})
.with_on_exit(move |mut _pman, _key, err_code, _will_restart| {
if let Some(err) = err_code {

View file

@ -1,17 +1,14 @@
use color_eyre::Result;
use color_eyre::eyre::Context;
use launch_pad::ProcessKey;
use launch_pad::process::Process;
use color_eyre::{Result, eyre::Context};
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
use launch_pad::{ProcessKey, process::Process};
use rustix::fd::AsRawFd;
use std::os::fd::OwnedFd;
use std::os::unix::net::UnixStream;
use std::sync::Arc;
use std::{
os::{fd::OwnedFd, unix::net::UnixStream},
sync::Arc,
};
use tokio::sync::Mutex;
use tracing::Instrument;
pub const PANEL_NOTIFICATIONS_FD: &str = "PANEL_NOTIFICATIONS_FD";
pub const DAEMON_NOTIFICATIONS_FD: &str = "DAEMON_NOTIFICATIONS_FD";
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
// Create a new pair of unnamed Unix sockets
let (sock_1, sock_2) = UnixStream::pair().wrap_err("failed to create socket pair")?;
@ -29,7 +26,6 @@ pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
Ok((OwnedFd::from(sock_1), OwnedFd::from(sock_2)))
}
#[allow(clippy::too_many_arguments)]
pub fn notifications_process(
span: tracing::Span,
cmd: &'static str,

View file

@ -1,11 +1,15 @@
// SPDX-License-Identifier: GPL-3.0-only
use std::path::Path;
use std::process::{Command, Stdio};
use std::sync::OnceLock;
use std::{
path::Path,
process::{Command, Stdio},
sync::OnceLock,
};
use zbus::Connection;
use zbus::zvariant::{Array, OwnedValue};
use zbus::{
Connection,
zvariant::{Array, OwnedValue},
};
#[derive(Debug)]
pub struct EnvVar {
@ -13,11 +17,11 @@ pub struct EnvVar {
pub value: String,
}
impl From<(&str, &str)> for EnvVar {
fn from(val: (&str, &str)) -> Self {
impl Into<EnvVar> for (&str, &str) {
fn into(self) -> EnvVar {
EnvVar {
key: val.0.to_owned(),
value: val.1.to_owned(),
key: self.0.to_owned(),
value: self.1.to_owned(),
}
}
}