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

@@ -11,6 +11,8 @@ use crate::{
utils::{self, umask},
};
#[cfg(any(target_os = "linux", target_os = "android"))]
use crate::pty::prepare_pty;
#[cfg(any(target_os = "linux", target_os = "android"))]
use rustix::{
process::getuid,
@@ -138,6 +140,7 @@ pub fn root_shell() -> Result<()> {
"Specify a supplementary group. The first specified supplementary group is also used as a primary group if the option -g is not specified.",
"GROUP",
);
opts.optflag("", "no-pty", "Do not allocate a new pseudo terminal.");
// Replace -cn with -z, -mm with -M for supporting getopt_long
let args = args
@@ -265,6 +268,13 @@ pub fn root_shell() -> Result<()> {
command = command.env("ENV", defs::KSURC_PATH);
}
#[cfg(target_os = "android")]
if !matches.opt_present("no-pty") {
if let Err(e) = prepare_pty() {
log::error!("failed to prepare pty: {:?}", e);
}
}
// escape from the current cgroup and become session leader
// WARNING!!! This cause some root shell hang forever!
// command = command.process_group(0);