Skip to content

Commit a3df721

Browse files
committed
Revert "su: allocate new pty (#1693)"
This reverts commit 935dc18.
1 parent 98757bc commit a3df721

File tree

7 files changed

+2
-236
lines changed

7 files changed

+2
-236
lines changed

userspace/ksud/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{Ok, Result};
22
use clap::Parser;
3-
use std::path::{Path, PathBuf};
3+
use std::path::PathBuf;
44

55
#[cfg(target_os = "android")]
66
use android_logger::Config;
@@ -283,7 +283,7 @@ pub fn run() -> Result<()> {
283283

284284
// the kernel executes su with argv[0] = "su" and replace it with us
285285
let arg0 = std::env::args().next().unwrap_or_default();
286-
if Path::new(&arg0).file_name().and_then(|f| f.to_str()) == Some("su") {
286+
if arg0 == "su" || arg0 == "/system/bin/su" {
287287
return crate::su::root_shell();
288288
}
289289

userspace/ksud/src/defs.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,3 @@ pub const VERSION_NAME: &str = include_str!(concat!(env!("OUT_DIR"), "/VERSION_N
4343
pub const KSU_BACKUP_DIR: &str = WORKING_DIR;
4444
pub const KSU_BACKUP_FILE_PREFIX: &str = "ksu_backup_";
4545
pub const BACKUP_FILENAME: &str = "stock_image.sha1";
46-
47-
pub const PTS_NAME: &str = "pts";

userspace/ksud/src/init_event.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use anyhow::{bail, Context, Result};
22
use log::{info, warn};
33
use std::{collections::HashMap, path::Path};
44

5-
use crate::defs::PTS_NAME;
65
use crate::module::prune_modules;
76
use crate::{
87
assets, defs, ksucalls, mount, restorecon,
@@ -194,11 +193,6 @@ pub fn on_post_data_fs() -> Result<()> {
194193
// mount temp dir
195194
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
196195
warn!("do temp dir mount failed: {}", e);
197-
} else {
198-
let pts_dir = format!("{}/{PTS_NAME}", utils::get_tmp_path());
199-
if let Err(e) = mount::mount_devpts(pts_dir) {
200-
warn!("do devpts mount failed: {}", e);
201-
}
202196
}
203197

204198
// exec modules post-fs-data scripts

userspace/ksud/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ mod ksucalls;
99
mod module;
1010
mod mount;
1111
mod profile;
12-
#[cfg(any(target_os = "linux", target_os = "android"))]
13-
mod pty;
1412
mod restorecon;
1513
mod sepolicy;
1614
mod su;

userspace/ksud/src/mount.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use anyhow::{anyhow, bail, Ok, Result};
2-
use std::fs::create_dir;
32

43
#[cfg(any(target_os = "linux", target_os = "android"))]
54
use anyhow::Context;
@@ -182,19 +181,6 @@ pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
182181
Ok(())
183182
}
184183

185-
#[cfg(any(target_os = "linux", target_os = "android"))]
186-
pub fn mount_devpts(dest: impl AsRef<Path>) -> Result<()> {
187-
create_dir(dest.as_ref())?;
188-
mount(
189-
KSU_OVERLAY_SOURCE,
190-
dest.as_ref(),
191-
"devpts",
192-
MountFlags::empty(),
193-
"newinstance",
194-
)?;
195-
Ok(())
196-
}
197-
198184
#[cfg(any(target_os = "linux", target_os = "android"))]
199185
pub fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
200186
info!(
@@ -339,8 +325,3 @@ pub fn mount_overlay(
339325
pub fn mount_tmpfs(_dest: impl AsRef<Path>) -> Result<()> {
340326
unimplemented!()
341327
}
342-
343-
#[cfg(not(any(target_os = "linux", target_os = "android")))]
344-
pub fn mount_devpts(_dest: impl AsRef<Path>) -> Result<()> {
345-
unimplemented!()
346-
}

userspace/ksud/src/pty.rs

Lines changed: 0 additions & 195 deletions
This file was deleted.

userspace/ksud/src/su.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use crate::{
1111
utils::{self, umask},
1212
};
1313

14-
#[cfg(any(target_os = "linux", target_os = "android"))]
15-
use crate::pty::prepare_pty;
1614
#[cfg(any(target_os = "linux", target_os = "android"))]
1715
use rustix::{
1816
process::getuid,
@@ -140,7 +138,6 @@ pub fn root_shell() -> Result<()> {
140138
"Specify a supplementary group. The first specified supplementary group is also used as a primary group if the option -g is not specified.",
141139
"GROUP",
142140
);
143-
opts.optflag("", "no-pty", "Do not allocate a new pseudo terminal.");
144141

145142
// Replace -cn with -z, -mm with -M for supporting getopt_long
146143
let args = args
@@ -268,13 +265,6 @@ pub fn root_shell() -> Result<()> {
268265
command = command.env("ENV", defs::KSURC_PATH);
269266
}
270267

271-
#[cfg(target_os = "android")]
272-
if !matches.opt_present("no-pty") {
273-
if let Err(e) = prepare_pty() {
274-
log::error!("failed to prepare pty: {:?}", e);
275-
}
276-
}
277-
278268
// escape from the current cgroup and become session leader
279269
// WARNING!!! This cause some root shell hang forever!
280270
// command = command.process_group(0);

0 commit comments

Comments
 (0)