Merge pull request #35 from jokeyrhyme/tokio-mutex-and-other-clippy-warnings

fix: use tokio Mutex and clear other clippy warnings
This commit is contained in:
Victoria Brekenfeld 2024-01-16 20:48:14 +01:00 committed by GitHub
commit 662ebce1b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 14 deletions

View file

@ -8,10 +8,7 @@ mod process;
mod service;
mod systemd;
use std::{
os::fd::AsRawFd,
sync::{Arc, Mutex},
};
use std::{os::fd::AsRawFd, sync::Arc};
use async_signals::Signals;
use color_eyre::{eyre::WrapErr, Result};
@ -24,7 +21,7 @@ use tokio::{
net::UnixStream,
sync::{
mpsc::{self, Receiver, Sender},
oneshot,
oneshot, Mutex,
},
time::{sleep, Duration},
};
@ -149,7 +146,7 @@ async fn start(
let notifications_span = info_span!(parent: None, "cosmic-notifications");
let panel_span = info_span!(parent: None, "cosmic-panel");
let mut guard = notif_key.lock().unwrap();
let mut guard = notif_key.lock().await;
*guard = Some(
process_manager
.start(notifications_process(
@ -169,7 +166,7 @@ async fn start(
);
drop(guard);
let mut guard = panel_key.lock().unwrap();
let mut guard = panel_key.lock().await;
*guard = Some(
process_manager
.start(notifications_process(
@ -343,5 +340,5 @@ async fn start_component(
.with_fds(move || vec![fd]),
)
.await
.expect(&format!("failed to start {}", cmd));
.unwrap_or_else(|_| panic!("failed to start {}", cmd));
}

View file

@ -6,8 +6,8 @@ use launch_pad::ProcessKey;
use rustix::fd::AsRawFd;
use std::os::fd::OwnedFd;
use std::os::unix::net::UnixStream;
use std::sync::{Arc, Mutex};
use tokio::sync::mpsc;
use std::sync::Arc;
use tokio::sync::{mpsc, Mutex};
use tracing::Instrument;
use crate::comp::create_privileged_socket;
@ -76,7 +76,7 @@ pub fn notifications_process(
.iter_mut()
.find(|(k, _v)| k == PANEL_NOTIFICATIONS_FD || k == DAEMON_NOTIFICATIONS_FD)
{
*v = format!("{}", my_fd.as_raw_fd().to_string());
*v = my_fd.as_raw_fd().to_string();
}
let mut their_env_vars = restart_env_vars.clone();
@ -84,7 +84,7 @@ pub fn notifications_process(
.iter_mut()
.find(|(k, _v)| k == PANEL_NOTIFICATIONS_FD || k == DAEMON_NOTIFICATIONS_FD)
{
*v = format!("{}", their_fd.as_raw_fd().to_string());
*v = their_fd.as_raw_fd().to_string();
}
let new_process = notifications_process(
@ -122,14 +122,14 @@ pub fn notifications_process(
error!(?why, "Failed to update fds");
}
let Some(old) = restart_key.lock().unwrap().clone() else {
let Some(old) = *restart_key.lock().await else {
error!("Couldn't stop previous invocation of {}", cmd);
return;
};
_ = pman.stop_process(old).await;
if let Ok(new) = pman.start(new_process).await {
let mut guard = restart_key.lock().unwrap();
let mut guard = restart_key.lock().await;
*guard = Some(new);
}
}