Skip to content

Commit f70b99d

Browse files
committed
1 parent b4e6dc7 commit f70b99d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/daemon.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9494

9595
log::debug!("Using config file path: {:#?}", config_file_path);
9696

97-
if !config_file_path.exists() {
98-
log::error!("{:#?} doesn't exist", config_file_path);
99-
exit(1);
100-
}
101-
10297
let hotkeys = match config::load(&config_file_path) {
10398
Err(e) => {
10499
log::error!("Config Error: {}", e);
@@ -319,7 +314,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
319314
}
320315

321316
fn sock_send(command: &str) -> std::io::Result<()> {
322-
let mut stream = UnixStream::connect("/tmp/swhkd.sock")?;
317+
let sock_file_path =
318+
String::from(format!("/run/user/{}/swhkd.sock", env::var("PKEXEC_UID").unwrap()));
319+
let mut stream = UnixStream::connect(sock_file_path)?;
323320
stream.write_all(command.as_bytes())?;
324321
Ok(())
325322
}
@@ -402,11 +399,11 @@ pub fn fetch_xdg_config_path() -> std::path::PathBuf {
402399
}
403400

404401
pub fn seteuid(uid: u32) {
405-
let uid = nix::unistd::Uid::from_raw(uid);
402+
let uid = Uid::from_raw(uid);
406403
match nix::unistd::seteuid(uid) {
407404
Ok(_) => log::debug!("Dropping privileges..."),
408405
Err(e) => {
409-
log::error!("Failed to set UID: {:#?}", e);
406+
log::error!("Failed to set EUID: {:#?}", e);
410407
exit(1);
411408
}
412409
}

src/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use nix::unistd;
12
use std::io::prelude::*;
23
use std::os::unix::net::UnixListener;
34
use std::{
@@ -12,7 +13,7 @@ fn main() -> std::io::Result<()> {
1213
env_logger::init();
1314

1415
let pid_file_path = String::from("/tmp/swhks.pid");
15-
let sock_file_path = String::from("/tmp/swhkd.sock");
16+
let sock_file_path = String::from(format!("/run/user/{}/swhkd.sock", unistd::Uid::current()));
1617

1718
if Path::new(&pid_file_path).exists() {
1819
log::trace!("Reading {} file and checking for running instances.", pid_file_path);

0 commit comments

Comments
 (0)