su: allocate new pty (#1693)

This commit is contained in:
5ec1cff
2024-05-07 19:02:59 +08:00
committed by GitHub
parent f2816653d9
commit 935dc18faa
8 changed files with 233 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
use anyhow::{anyhow, bail, Ok, Result};
use std::fs::create_dir;
#[cfg(any(target_os = "linux", target_os = "android"))]
use anyhow::Context;
@@ -181,6 +182,19 @@ pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
Ok(())
}
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn mount_devpts(dest: impl AsRef<Path>) -> Result<()> {
create_dir(dest.as_ref())?;
mount(
KSU_OVERLAY_SOURCE,
dest.as_ref(),
"devpts",
MountFlags::empty(),
"newinstance",
)?;
Ok(())
}
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
info!(
@@ -325,3 +339,8 @@ pub fn mount_overlay(
pub fn mount_tmpfs(_dest: impl AsRef<Path>) -> Result<()> {
unimplemented!()
}
#[cfg(not(any(target_os = "linux", target_os = "android")))]
pub fn mount_devpts(_dest: impl AsRef<Path>) -> Result<()> {
unimplemented!()
}