From 32001441645ada12fa1de972d75ad079ba9940a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vuka=C5=A1in=20Vojinovi=C4=87?= <150025636+git-f0x@users.noreply.github.com> Date: Thu, 28 Aug 2025 01:13:23 +0200 Subject: [PATCH] chore: migrate to Rust 2024 Removes the use of `set_var`, since it isn't thread safe. --- .rustfmt.toml | 11 +---------- Cargo.toml | 26 +++++++++++++------------- src/comp.rs | 4 ++-- src/main.rs | 18 +++++++++--------- src/notifications.rs | 6 +++--- src/systemd.rs | 19 ++++++++++++------- 6 files changed, 40 insertions(+), 44 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index a360b99..5d9904b 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,19 +1,10 @@ -edition = "2021" +edition = "2024" hard_tabs = true -merge_derives = true -newline_style = "Unix" -remove_nested_parens = true -reorder_imports = true -reorder_modules = true use_field_init_shorthand = true # Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt` -unstable_features = true format_code_in_doc_comments = true -format_macro_bodies = true format_strings = true -imports_indent = "Block" imports_granularity = "Crate" normalize_comments = true -overflow_delimited_expr = true reorder_impl_items = true wrap_comments = true diff --git a/Cargo.toml b/Cargo.toml index 3851e85..40148b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cosmic-session" description = "The session manager for the COSMIC desktop environment" version = "0.1.0" license = "GPL-3.0-only" -edition = "2021" +edition = "2024" authors = ["Lucy "] publish = false @@ -25,20 +25,20 @@ sendfd = { version = "0.4", features = ["tokio"] } serde = { version = "1", features = ["derive"] } serde_json = "1" tokio = { version = "1", features = [ - "fs", - "io-util", - "io-std", - "macros", - "net", - "parking_lot", - "process", - "rt", - "signal", - "sync", - "time", + "fs", + "io-util", + "io-std", + "macros", + "net", + "parking_lot", + "process", + "rt", + "signal", + "sync", + "time", ] } zbus_systemd = { version = "0.25701.0", optional = true, features = [ - "systemd1", + "systemd1", ] } tokio-util = "0.7" tracing = "0.1" diff --git a/src/comp.rs b/src/comp.rs index 5982a21..86406e7 100644 --- a/src/comp.rs +++ b/src/comp.rs @@ -1,14 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-only use color_eyre::eyre::{Result, WrapErr}; -use launch_pad::{process::Process, ProcessManager}; +use launch_pad::{ProcessManager, process::Process}; use sendfd::SendWithFd; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, os::unix::prelude::*}; use tokio::{ io::{AsyncReadExt, AsyncWriteExt}, net::{ - unix::{OwnedReadHalf, OwnedWriteHalf}, UnixStream, + unix::{OwnedReadHalf, OwnedWriteHalf}, }, sync::{mpsc, oneshot}, task::JoinHandle, diff --git a/src/main.rs b/src/main.rs index 6d04d02..0a7c901 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,13 +10,13 @@ mod service; mod systemd; use async_signals::Signals; -use color_eyre::{eyre::WrapErr, Result}; +use color_eyre::{Result, eyre::WrapErr}; use comp::create_privileged_socket; use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD}; use futures_util::StreamExt; #[cfg(feature = "autostart")] use itertools::Itertools; -use launch_pad::{process::Process, ProcessManager}; +use launch_pad::{ProcessManager, process::Process}; use service::SessionRequest; #[cfg(feature = "autostart")] use std::collections::HashSet; @@ -35,14 +35,15 @@ use systemd::{get_systemd_env, is_systemd_used, spawn_scope}; use tokio::{ net::UnixStream, sync::{ + Mutex, mpsc::{self, Receiver, Sender}, - oneshot, Mutex, + oneshot, }, time::Duration, }; use tokio_util::sync::CancellationToken; -use tracing::{metadata::LevelFilter, Instrument}; -use tracing_subscriber::{fmt, prelude::*, EnvFilter}; +use tracing::{Instrument, metadata::LevelFilter}; +use tracing_subscriber::{EnvFilter, fmt, prelude::*}; use crate::notifications::notifications_process; const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC"); @@ -166,7 +167,6 @@ async fn start( ); // now that cosmic-comp is ready, set XDG_SESSION_TYPE=wayland for new processes - std::env::set_var("XDG_SESSION_TYPE", "wayland"); env_vars.push(("XDG_SESSION_TYPE".to_string(), "wayland".to_string())); systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await; @@ -189,7 +189,7 @@ async fn start( && systemd_env.key != "SHELL" && systemd_env.key != "SHLVL" { - std::env::set_var(systemd_env.key, systemd_env.value); + env_vars.push((systemd_env.key, systemd_env.value)); } } } @@ -456,8 +456,8 @@ async fn start( info!("looking for autostart folders"); let mut directories_to_scan = Vec::new(); - // we start by taking user specific directories, so that we can deduplicate and ensure - // user overrides are respected + // we start by taking user specific directories, so that we can deduplicate and + // ensure user overrides are respected // user specific directories if let Some(user_config_dir) = dirs::config_dir() { diff --git a/src/notifications.rs b/src/notifications.rs index 3052a15..0726e34 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -1,12 +1,12 @@ -use color_eyre::{eyre::Context, Result}; +use color_eyre::{Result, eyre::Context}; use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD}; -use launch_pad::{process::Process, ProcessKey}; +use launch_pad::{ProcessKey, process::Process}; use rustix::fd::AsRawFd; use std::{ os::{fd::OwnedFd, unix::net::UnixStream}, sync::Arc, }; -use tokio::sync::{mpsc, Mutex}; +use tokio::sync::{Mutex, mpsc}; use tracing::Instrument; use crate::comp::create_privileged_socket; diff --git a/src/systemd.rs b/src/systemd.rs index 104d703..6cbfa02 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -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::zvariant::{Array, OwnedValue}; -use zbus::Connection; +use zbus::{ + Connection, + zvariant::{Array, OwnedValue}, +}; #[derive(Debug)] pub struct EnvVar { @@ -46,7 +50,8 @@ pub fn stop_systemd_target() { ) } -///Determine if systemd is used as the init system. This should work on all linux distributions. +/// 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 = OnceLock::new(); IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists()) @@ -68,7 +73,7 @@ pub async fn get_systemd_env() -> Result, zbus::Error> { } #[cfg(feature = "systemd")] -///Spawn a systemd scope unit with the given name and PIDs. +/// Spawn a systemd scope unit with the given name and PIDs. pub async fn spawn_scope(mut command: String, pids: Vec) -> Result<(), zbus::Error> { let connection = Connection::session().await?; let systemd_manager = SystemdManagerProxy::new(&connection).await?;