From c016d254d9964e340884f8ded1483b0114ab42a1 Mon Sep 17 00:00:00 2001 From: Ron Waldon-Howe Date: Fri, 12 Jan 2024 10:31:19 +1100 Subject: [PATCH] fix: use tokio Mutex and clear other clippy warnings --- src/main.rs | 13 +++++-------- src/notifications.rs | 12 ++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 65ec667..998ecec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)); } diff --git a/src/notifications.rs b/src/notifications.rs index d6b5bd0..e2baf0d 100644 --- a/src/notifications.rs +++ b/src/notifications.rs @@ -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); } }