merge: epoch-1.10.0 d'upstream

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lionel DARNIS 2026-10-11 07:00:06 +02:00
commit e8b1ad1da8
11 changed files with 283 additions and 202 deletions

View file

@ -99,6 +99,7 @@ pub fn run_compositor(
process_manager: &ProcessManager,
exec: String,
args: Vec<String>,
env: Vec<(String, String)>,
_token: CancellationToken,
env_tx: oneshot::Sender<HashMap<String, String>>,
session_dbus_tx: mpsc::Sender<SessionRequest>,
@ -119,13 +120,15 @@ pub fn run_compositor(
OwnedFd::from(std_stream)
};
mark_as_not_cloexec(&comp).expect("Failed to mark fd as not cloexec");
Ok(tokio::spawn(async move {
// Create a new process handler for cosmic-comp, with our compositor socket's
// file descriptor as the `COSMIC_SESSION_SOCK` environment variable.
let mut comp_env = vec![(
let mut comp_env = env;
comp_env.push((
"COSMIC_SESSION_SOCK".to_string(),
comp.as_raw_fd().to_string(),
)];
));
// NVIDIA keeps a growing pool of pre-rendered compositor frames
// (smithay#1562 / cosmic-comp#1179). Cap it to a single buffer.
if std::path::Path::new("/proc/driver/nvidia").exists() {

View file

@ -7,6 +7,7 @@ mod comp;
mod notifications;
mod process;
mod service;
#[cfg(feature = "systemd")]
mod systemd;
use color_eyre::Result;
@ -15,16 +16,11 @@ use launch_pad::ProcessManager;
use launch_pad::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 systemd::is_systemd_used;
#[cfg(any(feature = "autostart", feature = "systemd"))]
use std::{path::Path, sync::OnceLock};
#[cfg(feature = "systemd")]
use systemd::{get_systemd_env, spawn_scope};
use tokio::signal::unix::{SignalKind, signal};
@ -36,14 +32,20 @@ use tracing::Instrument;
use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{EnvFilter, fmt};
#[cfg(feature = "autostart")]
use {
std::collections::HashSet,
std::path::PathBuf,
std::process::{Command, Stdio},
};
use crate::notifications::{
DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD, notifications_process,
};
#[cfg(feature = "autostart")]
const AUTOSTART_DIR: &'static str = "autostart";
const AUTOSTART_DIR: &str = "autostart";
#[cfg(feature = "autostart")]
const ENVIRONMENT_NAME: &'static str = "COSMIC";
const ENVIRONMENT_NAME: &str = "COSMIC";
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
@ -143,10 +145,20 @@ async fn start(
.await;
let token = CancellationToken::new();
let (env_tx, env_rx) = oneshot::channel();
#[cfg(feature = "systemd")]
let systemd_env = if *is_systemd_used() {
get_systemd_env().await
} else {
Vec::new()
};
#[cfg(not(feature = "systemd"))]
let systemd_env = Vec::new();
let compositor_handle = comp::run_compositor(
&process_manager,
executable.clone(),
args,
systemd_env.clone(),
token.child_token(),
env_tx,
session_tx,
@ -164,7 +176,12 @@ async fn start(
);
// now that cosmic-comp is ready, set XDG_SESSION_TYPE=wayland for new processes
env_vars.push(("XDG_SESSION_TYPE".to_string(), "wayland".to_string()));
env_vars.extend(
systemd_env
.into_iter()
.chain([("XDG_SESSION_TYPE".to_string(), "wayland".to_string())]),
);
#[cfg(feature = "systemd")]
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
// expose the session version
@ -172,68 +189,36 @@ async fn start(
"COSMIC_VERSION".to_string(),
env!("CARGO_PKG_VERSION").to_string(),
));
#[cfg(feature = "systemd")]
systemd::set_systemd_environment("COSMIC_VERSION", env!("CARGO_PKG_VERSION")).await;
#[cfg(feature = "systemd")]
let _inhibit_fd = if *is_systemd_used() {
match get_systemd_env().await {
Ok(env) => {
for systemd_env in env {
// Only update the envvar if unset
if std::env::var_os(&systemd_env.key).is_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"
|| systemd_env.key == "XDG_CONFIG_DIRS")
&& systemd_env.key != "DISPLAY"
&& systemd_env.key != "XAUTHORITY"
&& systemd_env.key != "WAYLAND_DISPLAY"
&& systemd_env.key != "WAYLAND_SOCKET"
&& systemd_env.key != "_"
&& systemd_env.key != "SHELL"
&& systemd_env.key != "SHLVL"
{
env_vars.push((systemd_env.key, systemd_env.value));
}
}
}
}
Err(err) => {
warn!("Failed to sync systemd environment {}.", err);
}
};
#[cfg(feature = "logind")]
match zbus::Connection::system().await {
Ok(connection) => match logind_zbus::manager::ManagerProxy::new(&connection).await {
Ok(proxy) => match proxy
.inhibit(
logind_zbus::manager::InhibitType::HandlePowerKey,
"Cosmic Session",
"Show confirmation dialog.",
"block",
)
.await
{
Ok(fd) => Some(fd),
Err(err) => {
error!("Failed to inhibit power key {err:?}");
None
}
},
#[cfg(feature = "logind")]
let _inhibit_fd = match zbus::Connection::system().await {
Ok(connection) => match logind_zbus::manager::ManagerProxy::new(&connection).await {
Ok(proxy) => match proxy
.inhibit(
logind_zbus::manager::InhibitType::HandlePowerKey,
"Cosmic Session",
"Show confirmation dialog.",
"block",
)
.await
{
Ok(fd) => Some(fd),
Err(err) => {
error!("Failed to connect to logind manager {err:?}");
error!("Failed to inhibit power key {err:?}");
None
}
},
Err(err) => {
error!("Failed to connect to system dbus {err:?}");
error!("Failed to connect to logind manager {err:?}");
None
}
},
Err(err) => {
error!("Failed to connect to system dbus {err:?}");
None
}
#[cfg(not(feature = "logind"))]
None
} else {
None
};
let (settings_exit_tx, settings_exit_rx) = oneshot::channel();
@ -260,8 +245,10 @@ async fn start(
// - cosmic-comp is ready
// - we've set any related variables
// - cosmic-settings-daemon is ready
#[cfg(feature = "systemd")]
systemd::start_systemd_target().await;
// Always stop the target when the process exits or panics.
#[cfg(feature = "systemd")]
scopeguard::defer! {
systemd::stop_systemd_target();
}
@ -394,17 +381,17 @@ async fn start(
}
// skip if we have an OnlyShowIn entry that doesn't include COSMIC
if let Some(only_show_in) = entry.only_show_in() {
if !only_show_in.contains(&ENVIRONMENT_NAME) {
continue;
}
if let Some(only_show_in) = entry.only_show_in()
&& !only_show_in.contains(&ENVIRONMENT_NAME)
{
continue;
}
// ... OR we have a NotShowIn entry that includes COSMIC
if let Some(not_show_in) = entry.not_show_in() {
if not_show_in.contains(&ENVIRONMENT_NAME) {
continue;
}
if let Some(not_show_in) = entry.not_show_in()
&& not_show_in.contains(&ENVIRONMENT_NAME)
{
continue;
}
info!(
@ -423,7 +410,7 @@ async fn start(
.collect::<Vec<_>>();
// escape them
let escaped_args = shell_words::split(&*filtered_args.join(" "));
let escaped_args = shell_words::split(&filtered_args.join(" "));
if let Ok(args) = escaped_args {
info!("trying to start {} {}", program_name, args.join(" "));
@ -665,3 +652,11 @@ async fn start_component(
error!("failed to start {}: {}", cmd, err);
}
}
/// Determine if systemd is used as the init system. This should work on all
/// linux distributions.
#[cfg(any(feature = "autostart", feature = "systemd"))]
fn is_systemd_used() -> &'static bool {
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists())
}

View file

@ -1,28 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
use std::path::Path;
use std::process::{Command, Stdio};
use std::sync::OnceLock;
use zbus::Connection;
use zbus::zvariant::{Array, OwnedValue};
#[derive(Debug)]
pub struct EnvVar {
pub key: String,
pub value: String,
}
impl From<(&str, &str)> for EnvVar {
fn from(val: (&str, &str)) -> Self {
EnvVar {
key: val.0.to_owned(),
value: val.1.to_owned(),
}
}
}
#[cfg(feature = "systemd")]
use zbus_systemd::systemd1::ManagerProxy as SystemdManagerProxy;
pub async fn set_systemd_environment(key: &str, value: &str) {
@ -46,29 +27,44 @@ pub fn stop_systemd_target() {
)
}
/// Determine if systemd is used as the init system. This should work on all
/// linux distributions.
pub fn is_systemd_used() -> &'static bool {
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists())
}
#[cfg(feature = "systemd")]
pub async fn get_systemd_env() -> Result<Vec<EnvVar>, zbus::Error> {
async fn load_systemd_env() -> zbus::Result<Vec<String>> {
let connection = Connection::session().await?;
let systemd_manager = SystemdManagerProxy::new(&connection).await?;
let systemd_env = systemd_manager.environment().await?;
let mut out: Vec<EnvVar> = Vec::new();
for i in systemd_env {
if let Some(b) = i.split_once("=") {
out.push(b.into());
}
}
Ok(out)
systemd_manager.environment().await
}
/// Get the systemd user manager environment variables.
pub async fn get_systemd_env() -> Vec<(String, String)> {
match load_systemd_env().await {
Ok(env) => {
env.iter()
// split into key value pairs
.filter_map(|var| var.split_once("="))
.filter(|&(key, _value)| {
// Only update the envvar if unset
std::env::var_os(key).is_none()
// Blocklist of envvars that we shouldn't touch (taken from KDE)
&& (!key.starts_with("XDG_")
|| key == "XDG_DATA_DIRS"
|| key == "XDG_CONFIG_DIRS")
&& key != "DISPLAY"
&& key != "XAUTHORITY"
&& key != "WAYLAND_DISPLAY"
&& key != "WAYLAND_SOCKET"
&& key != "_"
&& key != "SHELL"
&& key != "SHLVL"
})
.map(|(key, value)| (key.to_owned(), value.to_owned()))
.collect()
}
Err(err) => {
warn!("Failed to sync systemd environment {}.", err);
Vec::new()
}
}
}
#[cfg(feature = "systemd")]
/// Spawn a systemd scope unit with the given name and PIDs.
pub async fn spawn_scope(mut command: String, pids: Vec<u32>) -> Result<(), zbus::Error> {
let connection = Connection::session().await?;