Skip to content

Commit 3200144

Browse files
git-f0xwash2
authored andcommitted
chore: migrate to Rust 2024
Removes the use of `set_var`, since it isn't thread safe.
1 parent 4c72d42 commit 3200144

File tree

6 files changed

+40
-44
lines changed

6 files changed

+40
-44
lines changed

.rustfmt.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
edition = "2021"
1+
edition = "2024"
22
hard_tabs = true
3-
merge_derives = true
4-
newline_style = "Unix"
5-
remove_nested_parens = true
6-
reorder_imports = true
7-
reorder_modules = true
83
use_field_init_shorthand = true
94
# Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt`
10-
unstable_features = true
115
format_code_in_doc_comments = true
12-
format_macro_bodies = true
136
format_strings = true
14-
imports_indent = "Block"
157
imports_granularity = "Crate"
168
normalize_comments = true
17-
overflow_delimited_expr = true
189
reorder_impl_items = true
1910
wrap_comments = true

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "cosmic-session"
33
description = "The session manager for the COSMIC desktop environment"
44
version = "0.1.0"
55
license = "GPL-3.0-only"
6-
edition = "2021"
6+
edition = "2024"
77
authors = ["Lucy <[email protected]>"]
88
publish = false
99

@@ -25,20 +25,20 @@ sendfd = { version = "0.4", features = ["tokio"] }
2525
serde = { version = "1", features = ["derive"] }
2626
serde_json = "1"
2727
tokio = { version = "1", features = [
28-
"fs",
29-
"io-util",
30-
"io-std",
31-
"macros",
32-
"net",
33-
"parking_lot",
34-
"process",
35-
"rt",
36-
"signal",
37-
"sync",
38-
"time",
28+
"fs",
29+
"io-util",
30+
"io-std",
31+
"macros",
32+
"net",
33+
"parking_lot",
34+
"process",
35+
"rt",
36+
"signal",
37+
"sync",
38+
"time",
3939
] }
4040
zbus_systemd = { version = "0.25701.0", optional = true, features = [
41-
"systemd1",
41+
"systemd1",
4242
] }
4343
tokio-util = "0.7"
4444
tracing = "0.1"

src/comp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22
use color_eyre::eyre::{Result, WrapErr};
3-
use launch_pad::{process::Process, ProcessManager};
3+
use launch_pad::{ProcessManager, process::Process};
44
use sendfd::SendWithFd;
55
use serde::{Deserialize, Serialize};
66
use std::{collections::HashMap, os::unix::prelude::*};
77
use tokio::{
88
io::{AsyncReadExt, AsyncWriteExt},
99
net::{
10-
unix::{OwnedReadHalf, OwnedWriteHalf},
1110
UnixStream,
11+
unix::{OwnedReadHalf, OwnedWriteHalf},
1212
},
1313
sync::{mpsc, oneshot},
1414
task::JoinHandle,

src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ mod service;
1010
mod systemd;
1111

1212
use async_signals::Signals;
13-
use color_eyre::{eyre::WrapErr, Result};
13+
use color_eyre::{Result, eyre::WrapErr};
1414
use comp::create_privileged_socket;
1515
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
1616
use futures_util::StreamExt;
1717
#[cfg(feature = "autostart")]
1818
use itertools::Itertools;
19-
use launch_pad::{process::Process, ProcessManager};
19+
use launch_pad::{ProcessManager, process::Process};
2020
use service::SessionRequest;
2121
#[cfg(feature = "autostart")]
2222
use std::collections::HashSet;
@@ -35,14 +35,15 @@ use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
3535
use tokio::{
3636
net::UnixStream,
3737
sync::{
38+
Mutex,
3839
mpsc::{self, Receiver, Sender},
39-
oneshot, Mutex,
40+
oneshot,
4041
},
4142
time::Duration,
4243
};
4344
use tokio_util::sync::CancellationToken;
44-
use tracing::{metadata::LevelFilter, Instrument};
45-
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
45+
use tracing::{Instrument, metadata::LevelFilter};
46+
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
4647

4748
use crate::notifications::notifications_process;
4849
const XDP_COSMIC: Option<&'static str> = option_env!("XDP_COSMIC");
@@ -166,7 +167,6 @@ async fn start(
166167
);
167168

168169
// now that cosmic-comp is ready, set XDG_SESSION_TYPE=wayland for new processes
169-
std::env::set_var("XDG_SESSION_TYPE", "wayland");
170170
env_vars.push(("XDG_SESSION_TYPE".to_string(), "wayland".to_string()));
171171
systemd::set_systemd_environment("XDG_SESSION_TYPE", "wayland").await;
172172

@@ -189,7 +189,7 @@ async fn start(
189189
&& systemd_env.key != "SHELL"
190190
&& systemd_env.key != "SHLVL"
191191
{
192-
std::env::set_var(systemd_env.key, systemd_env.value);
192+
env_vars.push((systemd_env.key, systemd_env.value));
193193
}
194194
}
195195
}
@@ -456,8 +456,8 @@ async fn start(
456456
info!("looking for autostart folders");
457457
let mut directories_to_scan = Vec::new();
458458

459-
// we start by taking user specific directories, so that we can deduplicate and ensure
460-
// user overrides are respected
459+
// we start by taking user specific directories, so that we can deduplicate and
460+
// ensure user overrides are respected
461461

462462
// user specific directories
463463
if let Some(user_config_dir) = dirs::config_dir() {

src/notifications.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use color_eyre::{eyre::Context, Result};
1+
use color_eyre::{Result, eyre::Context};
22
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
3-
use launch_pad::{process::Process, ProcessKey};
3+
use launch_pad::{ProcessKey, process::Process};
44
use rustix::fd::AsRawFd;
55
use std::{
66
os::{fd::OwnedFd, unix::net::UnixStream},
77
sync::Arc,
88
};
9-
use tokio::sync::{mpsc, Mutex};
9+
use tokio::sync::{Mutex, mpsc};
1010
use tracing::Instrument;
1111

1212
use crate::comp::create_privileged_socket;

src/systemd.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22

3-
use std::path::Path;
4-
use std::process::{Command, Stdio};
5-
use std::sync::OnceLock;
3+
use std::{
4+
path::Path,
5+
process::{Command, Stdio},
6+
sync::OnceLock,
7+
};
68

7-
use zbus::zvariant::{Array, OwnedValue};
8-
use zbus::Connection;
9+
use zbus::{
10+
Connection,
11+
zvariant::{Array, OwnedValue},
12+
};
913

1014
#[derive(Debug)]
1115
pub struct EnvVar {
@@ -46,7 +50,8 @@ pub fn stop_systemd_target() {
4650
)
4751
}
4852

49-
///Determine if systemd is used as the init system. This should work on all linux distributions.
53+
/// Determine if systemd is used as the init system. This should work on all
54+
/// linux distributions.
5055
pub fn is_systemd_used() -> &'static bool {
5156
static IS_SYSTEMD_USED: OnceLock<bool> = OnceLock::new();
5257
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> {
6873
}
6974

7075
#[cfg(feature = "systemd")]
71-
///Spawn a systemd scope unit with the given name and PIDs.
76+
/// Spawn a systemd scope unit with the given name and PIDs.
7277
pub async fn spawn_scope(mut command: String, pids: Vec<u32>) -> Result<(), zbus::Error> {
7378
let connection = Connection::session().await?;
7479
let systemd_manager = SystemdManagerProxy::new(&connection).await?;

0 commit comments

Comments
 (0)