chore: migrate to Rust 2024
Removes the use of `set_var`, since it isn't thread safe.
This commit is contained in:
parent
4c72d42731
commit
3200144164
6 changed files with 40 additions and 44 deletions
|
|
@ -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
|
||||
|
|
|
|||
26
Cargo.toml
26
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 <lucy@system76.com>"]
|
||||
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"
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
18
src/main.rs
18
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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<bool> = 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<Vec<EnvVar>, 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<u32>) -> Result<(), zbus::Error> {
|
||||
let connection = Connection::session().await?;
|
||||
let systemd_manager = SystemdManagerProxy::new(&connection).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue