about summary refs log tree commit diff
path: root/src/facility
diff options
context:
space:
mode:
Diffstat (limited to 'src/facility')
-rw-r--r--src/facility/i3.rs33
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.
    */