summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 1b55c8f..73cd9b0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,20 +27,25 @@ fn create_and_open_dir<P: AsRef<Path> + Copy>(
struct SessionError;
+impl From<std::io::Error> for SessionError {
+ fn from(_: std::io::Error) -> Self {
+ SessionError
+ }
+}
+
fn open_session(h: &mut PamHandle) -> Result<(), SessionError> {
let user = h.get_user(None).or(Err(SessionError))?;
let user = users::get_user_by_name(&user).ok_or(SessionError)?;
let aa = cap_std::ambient_authority();
- let d = Dir::open_ambient_dir(CG_MOUNT, aa).or(Err(SessionError))?;
- let d = create_and_open_dir(&d, "user").or(Err(SessionError))?;
- let d = create_and_open_dir(&d, &user.uid().to_string())
- .or(Err(SessionError))?;
- let d = create_and_open_dir(&d, "leaf").or(Err(SessionError))?;
+ let d = Dir::open_ambient_dir(CG_MOUNT, aa)?;
+ let d = create_and_open_dir(&d, "user")?;
+ let d = create_and_open_dir(&d, &user.uid().to_string())?;
+ let d = create_and_open_dir(&d, "leaf")?;
let pid = process::id().to_string();
let mut options = OpenOptions::new();
options.write(true);
- let mut procs = d.open_with("cgroup.procs", &options).or(Err(SessionError))?;
- procs.write_all(pid.as_bytes()).or(Err(SessionError))?;
+ let mut procs = d.open_with("cgroup.procs", &options)?;
+ procs.write_all(pid.as_bytes())?;
Ok(())
}