mirror of
https://gitee.com/openharmony/developtools_hdc
synced 2024-11-23 07:02:43 +00:00
Revert "interactive shell command kill child process"
This reverts commit 60470b232e
.
Signed-off-by: wangtao <wangtao577@huawei.com>
This commit is contained in:
parent
4d36f15dc8
commit
f769913f39
7
BUILD.gn
7
BUILD.gn
@ -183,7 +183,6 @@ if (product_name != "ohos-sdk") {
|
||||
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"hicollie:hicollie_rust",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"lz4:liblz4_static",
|
||||
@ -222,7 +221,6 @@ if (product_name != "ohos-sdk") {
|
||||
features += [ "emulator" ]
|
||||
}
|
||||
external_deps = [
|
||||
"hicollie:hicollie_rust",
|
||||
"hilog:hilog_rust",
|
||||
"ylong_runtime:ylong_runtime",
|
||||
]
|
||||
@ -277,10 +275,7 @@ template("build_hdc") {
|
||||
"//third_party/rust/crates/nix:lib",
|
||||
"//third_party/rust/crates/rust-openssl/openssl:lib",
|
||||
]
|
||||
external_deps = [
|
||||
"hicollie:hicollie_rust",
|
||||
"hilog:hilog_rust",
|
||||
]
|
||||
external_deps = [ "hilog:hilog_rust" ]
|
||||
|
||||
if (product_name != "ohos-sdk") {
|
||||
deps += [
|
||||
|
@ -38,7 +38,6 @@
|
||||
"openssl",
|
||||
"libusb",
|
||||
"libuv",
|
||||
"hicollie",
|
||||
"os_account",
|
||||
"user_auth_framework",
|
||||
"pin_auth"
|
||||
|
@ -35,7 +35,6 @@ ohos_static_library("serialize_structs") {
|
||||
|
||||
external_deps = [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"hicollie:hicollie_rust",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"lz4:liblz4_static",
|
||||
@ -68,7 +67,6 @@ ohos_rust_executable("hdcd") {
|
||||
"//third_party/rust/crates/rust-openssl/openssl:lib",
|
||||
]
|
||||
external_deps = [
|
||||
"hicollie:hicollie_rust",
|
||||
"hilog:hilog_rust",
|
||||
"ylong_runtime:ylong_runtime",
|
||||
]
|
||||
|
@ -53,9 +53,6 @@ use ylong_runtime::net::{TcpListener, TcpStream};
|
||||
#[cfg(not(feature = "emulator"))]
|
||||
use ylong_runtime::sync::mpsc;
|
||||
|
||||
use libc::c_void;
|
||||
type XCollieCallbackRust = extern "C" fn(arg: *mut libc::c_void);
|
||||
|
||||
extern "C" {
|
||||
#[cfg(not(feature = "emulator"))]
|
||||
fn NeedDropRootPrivileges() -> c_int;
|
||||
@ -373,11 +370,6 @@ pub async fn usb_daemon_start() -> io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
pub unsafe extern "C" fn new_session_callback(_ptr: *mut c_void) {
|
||||
crate::error!("new session proc timeout, will restart hdcd");
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "emulator"))]
|
||||
pub async fn usb_handle_client(_config_fd: i32, bulkin_fd: i32, bulkout_fd: i32) -> io::Result<()> {
|
||||
let _rd = transfer::usb::UsbReader { fd: bulkin_fd };
|
||||
@ -389,16 +381,11 @@ pub async fn usb_handle_client(_config_fd: i32, bulkin_fd: i32, bulkout_fd: i32)
|
||||
if msg.command == config::HdcCommand::KernelHandshake {
|
||||
if let Ok(session_id_in_msg) = auth::get_session_id_from_msg(&msg).await {
|
||||
if session_id_in_msg != cur_session_id {
|
||||
let new_session_func: XCollieCallbackRust = unsafe {
|
||||
std::mem::transmute::<*const (), XCollieCallbackRust>(new_session_callback as *const ())
|
||||
};
|
||||
let timer = unsafe { hicollie_rust::set_timer("new session".as_ptr(), 10 /* second */, new_session_func, std::ptr::null_mut() as *mut c_void, 3) };
|
||||
task_manager::free_session(cur_session_id).await;
|
||||
crate::info!("free session(usb) over {:?} and new session is {}", cur_session_id, session_id_in_msg);
|
||||
let wr = transfer::usb::UsbWriter { fd: bulkout_fd };
|
||||
transfer::UsbMap::start(session_id_in_msg, wr).await;
|
||||
cur_session_id = session_id_in_msg;
|
||||
hicollie_rust::cancel_timer(timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ use ylong_runtime::process::{Child, Command, ChildStdin, ChildStdout, ChildStder
|
||||
use ylong_runtime::io::{AsyncReadExt, AsyncWriteExt, AsyncBufReader};
|
||||
use ylong_runtime::sync::{mpsc, Mutex};
|
||||
use ylong_runtime::sync::error::TryRecvError::Closed;
|
||||
use libc::c_int;
|
||||
|
||||
|
||||
// -----inner common functions-----
|
||||
@ -485,43 +484,6 @@ impl PtyMap {
|
||||
}
|
||||
|
||||
// -----noninteractive shell implementation-----
|
||||
type ShellExecuteChildMap_ = std::sync::Mutex<HashMap<(u32, u32), i32>>;
|
||||
pub struct ShellExecuteChildMap {}
|
||||
impl ShellExecuteChildMap {
|
||||
fn get_instance() -> &'static ShellExecuteChildMap_ {
|
||||
static mut SHELLEXECUTECHILD_MAP: MaybeUninit<ShellExecuteChildMap_> = MaybeUninit::uninit();
|
||||
static ONCE: Once = Once::new();
|
||||
|
||||
unsafe {
|
||||
ONCE.call_once(|| {
|
||||
SHELLEXECUTECHILD_MAP = MaybeUninit::new(std::sync::Mutex::new(HashMap::new()));
|
||||
}
|
||||
);
|
||||
&*SHELLEXECUTECHILD_MAP.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn put(session_id: u32, channel_id: u32, childpid: i32) {
|
||||
let shell_execute_child_map = Self::get_instance();
|
||||
let mut map = shell_execute_child_map.lock().unwrap();
|
||||
map.insert((session_id, channel_id), childpid);
|
||||
}
|
||||
|
||||
pub async fn del(session_id: u32, channel_id: u32) {
|
||||
let shell_execute_child_map = Self::get_instance();
|
||||
let mut map = shell_execute_child_map.lock().unwrap();
|
||||
if let Some(childpid) = map.get(&(session_id, channel_id)) {
|
||||
crate::debug!("kill childpid:{:?}", childpid);
|
||||
let childpid_tmp = *childpid;
|
||||
unsafe {
|
||||
libc::kill(childpid_tmp,libc::SIGTERM);
|
||||
let mut status: c_int = 0;
|
||||
libc::waitpid(childpid_tmp, &mut status, 0);
|
||||
};
|
||||
}
|
||||
map.remove(&(session_id, channel_id));
|
||||
}
|
||||
}
|
||||
|
||||
type ShellExecuteMap_ = Mutex<HashMap<(u32, u32), Arc<ShellExecuteTask>>>;
|
||||
pub struct ShellExecuteMap {}
|
||||
@ -561,6 +523,7 @@ impl ShellExecuteMap {
|
||||
if iter.0 .0 != session_id {
|
||||
continue;
|
||||
}
|
||||
iter.1.handle.cancel();
|
||||
channel_vec.push(iter.0 .1);
|
||||
crate::debug!(
|
||||
"Clear shell_execute_map task, session_id: {}, channel_id:{}, task_size: {}",
|
||||
@ -571,7 +534,6 @@ impl ShellExecuteMap {
|
||||
}
|
||||
for channel_id in channel_vec{
|
||||
map.remove(&(session_id, channel_id));
|
||||
ShellExecuteChildMap::del(session_id, channel_id).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -650,7 +612,8 @@ async fn task_for_shell_execute(
|
||||
shell_cmd.args(["-c", &cmd])
|
||||
.stdout(Stdio::piped())
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
.stderr(Stdio::piped())
|
||||
.kill_on_drop(true);
|
||||
|
||||
unsafe {
|
||||
shell_cmd.pre_exec(|| {
|
||||
@ -663,13 +626,6 @@ async fn task_for_shell_execute(
|
||||
}
|
||||
|
||||
if let Ok(mut child) = shell_cmd.spawn() {
|
||||
if let Some(childpid) = child.id() {
|
||||
crate::error!("connection[session:{:?}, channel:{:?}] pid is {:?}", shell_task_id.session_id, shell_task_id.channel_id, childpid);
|
||||
ShellExecuteChildMap::put(shell_task_id.session_id, shell_task_id.channel_id, childpid as i32).await;
|
||||
} else {
|
||||
crate::error!("get child pid error");
|
||||
}
|
||||
|
||||
|
||||
let mut child_in = match child.take_stdin() {
|
||||
Some(child_in_inner) => {
|
||||
|
Loading…
Reference in New Issue
Block a user