Add logging for api local simple & pty processes

pull/137/head
Chip Senkbeil 2 years ago
parent 30548cdbfb
commit ec95f573b9
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -6,6 +6,7 @@ use crate::{
constants::{MAX_PIPE_CHUNK_SIZE, READ_PAUSE_MILLIS},
data::Environment,
};
use log::*;
use portable_pty::{CommandBuilder, MasterPty, PtySize as PortablePtySize};
use std::{
ffi::OsStr,
@ -41,6 +42,8 @@ impl PtyProcess {
I: IntoIterator<Item = S2>,
S2: AsRef<OsStr>,
{
let id = rand::random();
// Establish our new pty for the given size
let pty_system = portable_pty::native_pty_system();
let pty_pair = pty_system
@ -111,6 +114,10 @@ impl PtyProcess {
loop {
match (child.try_wait(), kill_rx.try_recv()) {
(Ok(Some(status)), _) => {
trace!(
"Pty process {id} has exited: success = {}",
status.success()
);
// TODO: Keep track of io error
let _ = wait_tx
.send(ExitStatus {
@ -121,11 +128,13 @@ impl PtyProcess {
break;
}
(_, Ok(_)) => {
trace!("Pty process {id} received kill request");
// TODO: Keep track of io error
let _ = wait_tx.kill().await;
break;
}
(Err(x), _) => {
trace!("Pty process {id} failed to wait");
// TODO: Keep track of io error
let _ = wait_tx.send(x).await;
break;
@ -140,7 +149,7 @@ impl PtyProcess {
});
Ok(Self {
id: rand::random(),
id,
pty_master: PtyProcessMaster(Arc::new(Mutex::new(pty_master))),
stdin: Some(Box::new(stdin_tx)),
stdout: Some(Box::new(stdout_rx)),

@ -3,6 +3,7 @@ use super::{
ProcessKiller, WaitRx,
};
use crate::data::Environment;
use log::*;
use std::{ffi::OsStr, path::PathBuf, process::Stdio};
use tokio::{io, process::Command, sync::mpsc, task::JoinHandle};
@ -34,6 +35,7 @@ impl SimpleProcess {
I: IntoIterator<Item = S2>,
S2: AsRef<OsStr>,
{
let id = rand::random();
let mut child = {
let mut command = Command::new(program);
@ -65,15 +67,34 @@ impl SimpleProcess {
tokio::spawn(async move {
tokio::select! {
_ = kill_rx.recv() => {
trace!("Pty process {id} received kill request");
let status = match child.kill().await {
Ok(_) => ExitStatus::killed(),
Err(x) => ExitStatus::from(x),
};
trace!(
"Simple process {id} has exited: success = {}, code = {}",
status.success,
status.code.map(|code| code.to_string())
.unwrap_or_else(|| "<terminated>".to_string()),
);
// TODO: Keep track of io error
let _ = wait_tx.send(status).await;
}
status = child.wait() => {
match &status {
Ok(status) => trace!(
"Simple process {id} has exited: success = {}, code = {}",
status.success(),
status.code()
.map(|code| code.to_string())
.unwrap_or_else(|| "<terminated>".to_string()),
),
Err(_) => trace!("Simple process {id} failed to wait"),
}
// TODO: Keep track of io error
let _ = wait_tx.send(status).await;
}
@ -81,7 +102,7 @@ impl SimpleProcess {
});
Ok(Self {
id: rand::random(),
id,
stdin: Some(Box::new(stdin_ch)),
stdout: Some(Box::new(stdout_ch)),
stderr: Some(Box::new(stderr_ch)),

Loading…
Cancel
Save