Merge pull request #130 from lilyinstarlight/fix/get-session-by-pid-race

Fix race condition when getting login session
This commit is contained in:
Jeremy Soller 2024-09-22 15:45:19 -06:00 committed by GitHub
commit 4ddb320dae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,7 +6,7 @@ use logind_zbus::{
manager::{InhibitType, ManagerProxy},
session::SessionProxy,
};
use std::{any::TypeId, error::Error, os::fd::OwnedFd, process, sync::Arc};
use std::{any::TypeId, error::Error, os::fd::OwnedFd, sync::Arc};
use tokio::time;
use zbus::Connection;
@ -68,7 +68,7 @@ pub fn subscription() -> Subscription<Message> {
pub async fn handler(msg_tx: &mut mpsc::Sender<Message>) -> Result<(), Box<dyn Error>> {
let connection = Connection::system().await?;
let manager = ManagerProxy::new(&connection).await?;
let session_path = manager.get_session_by_PID(process::id()).await?;
let session_path = manager.get_session_by_PID(std::os::unix::process::parent_id()).await?;
let session = SessionProxy::builder(&connection)
.path(&session_path)?
.build()