diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-24 01:07:05 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-24 01:07:05 -0700 |
| commit | d0a03210efd08d2fbf61fa37e000fc1f4622b46a (patch) | |
| tree | 1b1fa64fa85f4a4012816449c67c9bf5bfdf1bc3 /src/facility/i3.rs | |
| parent | eba55e151fbe041217c929a3f8b15c77868701bb (diff) | |
move get_username() into a new file
Force-Push: yes Change-Id: Ied7051c063d5c3380efb2345e6d3889fa1fbe883
Diffstat (limited to 'src/facility/i3.rs')
| -rw-r--r-- | src/facility/i3.rs | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 268d6bd..4b91b02 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -1,19 +1,14 @@ use crate::error::{ Error, Result }; use crate::facility::{ CreatableFacility, Facility, FacilityType }; +use crate::unix::get_username; use crate::xdg::xdg_runtime_directory; use std::any::Any; -use std::ffi::CStr; -use std::mem::{ size_of_val, MaybeUninit }; use std::path::{ Path, PathBuf }; -use std::ptr::null_mut; use async_fs::{ metadata, read_dir, File, OpenOptions }; use async_fs::unix::FileTypeExt; use futures_lite::StreamExt; -use libc::{ getpwuid_r, passwd }; -use rustix::io::Errno; -use rustix::process::{ getuid, Uid }; pub struct I3 { @@ -86,7 +81,7 @@ impl I3 { } /* As before, an absent environment variable is not an error. */ - let username = Self::get_username().await?; + let username = get_username().await?; let tmp_path: PathBuf = "/tmp/".into(); match Self::try_tmp_directory(&tmp_path, &username).await { Ok(Some(socket)) => { return Ok(socket); } @@ -98,30 +93,6 @@ impl I3 { Err(Error::custom("i3 window manager socket not found")) } - async fn get_username() -> Result<String> { - let uid: Uid = getuid(); - - let mut buffer: [i8; 512] = [0; 512]; - let mut entry: MaybeUninit<passwd> = MaybeUninit::uninit(); - let mut result = null_mut(); - - let error = unsafe { - getpwuid_r(uid.as_raw(), - &raw mut entry as *mut passwd, - &raw mut buffer as *mut i8, - size_of_val(&buffer), - &mut result) - }; - if error != 0 { - return Err(Errno::from_raw_os_error(error).into()); - } - - let name = unsafe { entry.assume_init() }.pw_name; - let name = unsafe { CStr::from_ptr(name) }; - - Ok(name.to_string_lossy().into_owned()) - } - /* One of the ways to find an i3 socket is to look within the tmp directory * for subdirectories with names having a specific pattern. Do that. */ |