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
|
hard_tabs = true
|
||||||
merge_derives = true
|
|
||||||
newline_style = "Unix"
|
|
||||||
remove_nested_parens = true
|
|
||||||
reorder_imports = true
|
|
||||||
reorder_modules = true
|
|
||||||
use_field_init_shorthand = true
|
use_field_init_shorthand = true
|
||||||
# Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt`
|
# 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_code_in_doc_comments = true
|
||||||
format_macro_bodies = true
|
|
||||||
format_strings = true
|
format_strings = true
|
||||||
imports_indent = "Block"
|
|
||||||
imports_granularity = "Crate"
|
imports_granularity = "Crate"
|
||||||
normalize_comments = true
|
normalize_comments = true
|
||||||
overflow_delimited_expr = true
|
|
||||||
reorder_impl_items = true
|
reorder_impl_items = true
|
||||||
wrap_comments = 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"
|
description = "The session manager for the COSMIC desktop environment"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
license = "GPL-3.0-only"
|
license = "GPL-3.0-only"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
authors = ["Lucy <lucy@system76.com>"]
|
authors = ["Lucy <lucy@system76.com>"]
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|
@ -25,20 +25,20 @@ sendfd = { version = "0.4", features = ["tokio"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
tokio = { version = "1", features = [
|
tokio = { version = "1", features = [
|
||||||
"fs",
|
"fs",
|
||||||
"io-util",
|
"io-util",
|
||||||
"io-std",
|
"io-std",
|
||||||
"macros",
|
"macros",
|
||||||
"net",
|
"net",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"process",
|
"process",
|
||||||
"rt",
|
"rt",
|
||||||
"signal",
|
"signal",
|
||||||
"sync",
|
"sync",
|
||||||
"time",
|
"time",
|
||||||
] }
|
] }
|
||||||
zbus_systemd = { version = "0.25701.0", optional = true, features = [
|
zbus_systemd = { version = "0.25701.0", optional = true, features = [
|
||||||
"systemd1",
|
"systemd1",
|
||||||
] }
|
] }
|
||||||
tokio-util = "0.7"
|
tokio-util = "0.7"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
use color_eyre::eyre::{Result, WrapErr};
|
use color_eyre::eyre::{Result, WrapErr};
|
||||||
use launch_pad::{process::Process, ProcessManager};
|
use launch_pad::{ProcessManager, process::Process};
|
||||||
use sendfd::SendWithFd;
|
use sendfd::SendWithFd;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, os::unix::prelude::*};
|
use std::{collections::HashMap, os::unix::prelude::*};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{
|
net::{
|
||||||
unix::{OwnedReadHalf, OwnedWriteHalf},
|
|
||||||
UnixStream,
|
UnixStream,
|
||||||
|
unix::{OwnedReadHalf, OwnedWriteHalf},
|
||||||
},
|
},
|
||||||
sync::{mpsc, oneshot},
|
sync::{mpsc, oneshot},
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -10,13 +10,13 @@ mod service;
|
||||||
mod systemd;
|
mod systemd;
|
||||||
|
|
||||||
use async_signals::Signals;
|
use async_signals::Signals;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{Result, eyre::WrapErr};
|
||||||
use comp::create_privileged_socket;
|
use comp::create_privileged_socket;
|
||||||
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
|
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
#[cfg(feature = "autostart")]
|
#[cfg(feature = "autostart")]
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use launch_pad::{process::Process, ProcessManager};
|
use launch_pad::{ProcessManager, process::Process};
|
||||||
use service::SessionRequest;
|
use service::SessionRequest;
|
||||||
#[cfg(feature = "autostart")]
|
#[cfg(feature = "autostart")]
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
@ -35,14 +35,15 @@ use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
net::UnixStream,
|
net::UnixStream,
|
||||||
sync::{
|
sync::{
|
||||||
|
Mutex,
|
||||||
mpsc::{self, Receiver, Sender},
|
mpsc::{self, Receiver, Sender},
|
||||||
oneshot, Mutex,
|
oneshot,
|
||||||
},
|
},
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{metadata::LevelFilter, Instrument};
|
use tracing::{Instrument, metadata::LevelFilter};
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
||||||
|
|
||||||
use crate::notifications::notifications_process;
|
use crate::notifications::notifications_process;
|
||||||
const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC");
|
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
|
// 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()));
|
env_vars.push(("XDG_SESSION_TYPE".to_string(), "wayland".to_string()));
|
||||||
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
|
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ async fn start(
|
||||||
&& systemd_env.key != "SHELL"
|
&& systemd_env.key != "SHELL"
|
||||||
&& systemd_env.key != "SHLVL"
|
&& 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");
|
info!("looking for autostart folders");
|
||||||
let mut directories_to_scan = Vec::new();
|
let mut directories_to_scan = Vec::new();
|
||||||
|
|
||||||
// we start by taking user specific directories, so that we can deduplicate and ensure
|
// we start by taking user specific directories, so that we can deduplicate and
|
||||||
// user overrides are respected
|
// ensure user overrides are respected
|
||||||
|
|
||||||
// user specific directories
|
// user specific directories
|
||||||
if let Some(user_config_dir) = dirs::config_dir() {
|
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 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 rustix::fd::AsRawFd;
|
||||||
use std::{
|
use std::{
|
||||||
os::{fd::OwnedFd, unix::net::UnixStream},
|
os::{fd::OwnedFd, unix::net::UnixStream},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
use tokio::sync::{mpsc, Mutex};
|
use tokio::sync::{Mutex, mpsc};
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
|
|
||||||
use crate::comp::create_privileged_socket;
|
use crate::comp::create_privileged_socket;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use std::path::Path;
|
use std::{
|
||||||
use std::process::{Command, Stdio};
|
path::Path,
|
||||||
use std::sync::OnceLock;
|
process::{Command, Stdio},
|
||||||
|
sync::OnceLock,
|
||||||
|
};
|
||||||
|
|
||||||
use zbus::zvariant::{Array, OwnedValue};
|
use zbus::{
|
||||||
use zbus::Connection;
|
Connection,
|
||||||
|
zvariant::{Array, OwnedValue},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EnvVar {
|
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 {
|
pub fn is_systemd_used() -> &'static bool {
|
||||||
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
|
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
|
||||||
IS_SYSTEMD_USED.get_or_init(|| Path::new("/run/systemd/system").exists())
|
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")]
|
#[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> {
|
pub async fn spawn_scope(mut command: String, pids: Vec<u32>) -> Result<(), zbus::Error> {
|
||||||
let connection = Connection::session().await?;
|
let connection = Connection::session().await?;
|
||||||
let systemd_manager = SystemdManagerProxy::new(&connection).await?;
|
let systemd_manager = SystemdManagerProxy::new(&connection).await?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue