aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrooks Rady <b.j.rady@gmail.com>2020-12-02 14:03:46 +0000
committerGitHub <noreply@github.com>2020-12-02 15:03:46 +0100
commitc3fa9fb40e3cb0146169841e5a8a14f4e6ae2fea (patch)
tree699f8bfb9f3fb3898b449b43bf6bb53278a443ea /src
parentfic(compatibility): htop scrolling issues (#77) (diff)
downloadsl0ppij-c3fa9fb40e3cb0146169841e5a8a14f4e6ae2fea.tar.gz
sl0ppij-c3fa9fb40e3cb0146169841e5a8a14f4e6ae2fea.tar.xz
sl0ppij-c3fa9fb40e3cb0146169841e5a8a14f4e6ae2fea.zip
fix(threads): a race condition, build-times, and warnings (#79)
* Fix a race condition, build-times, and warnings * Yeah, yeah... I know * style(code): add comment to explain race condition Co-authored-by: Aram Drevekenin <aram@poor.dev>
Diffstat (limited to 'src')
-rw-r--r--src/main.rs13
-rw-r--r--src/pty_bus.rs2
-rw-r--r--src/screen.rs10
-rw-r--r--src/utils/logging.rs15
4 files changed, 20 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs
index 0f5fcf06..08bc37c3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,19 +11,15 @@ mod screen;
mod terminal_pane;
mod utils;
-use std::io::{self, Read, Write};
+use std::io::Write;
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use std::sync::mpsc::{channel, Receiver, Sender};
-use std::sync::{Arc, Mutex};
use std::thread;
use serde::{Deserialize, Serialize};
use structopt::StructOpt;
-use wasmer::{Exports, Function, Instance, Module, Store, Value};
-use wasmer_wasi::WasiState;
-
use crate::command_is_executing::CommandIsExecuting;
use crate::input::input_loop;
use crate::layout::Layout;
@@ -257,13 +253,17 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
// Here be dragons! This is very much a work in progress, and isn't quite functional
// yet. It's being left out of the tests because is slows them down massively (by
// recompiling a WASM module for every single test). Stay tuned for more updates!
- #[cfg(not(test))]
+ #[cfg(feature = "wasm-wip")]
active_threads.push(
thread::Builder::new()
.name("wasm".to_string())
.spawn(move || {
// TODO: Clone shared state here
move || -> Result<(), Box<dyn std::error::Error>> {
+ use std::io;
+ use std::sync::{Arc, Mutex};
+ use wasmer::{Exports, Function, Instance, Module, Store, Value};
+ use wasmer_wasi::WasiState;
let store = Store::default();
println!("Compiling module...");
@@ -364,6 +364,7 @@ pub fn start(mut os_input: Box<dyn OsApi>, opts: Opt) {
let _ipc_thread = thread::Builder::new()
.name("ipc_server".to_string())
.spawn({
+ use std::io::Read;
let send_pty_instructions = send_pty_instructions.clone();
let send_screen_instructions = send_screen_instructions.clone();
move || {
diff --git a/src/pty_bus.rs b/src/pty_bus.rs
index 3c8abcff..078e3271 100644
--- a/src/pty_bus.rs
+++ b/src/pty_bus.rs
@@ -11,7 +11,7 @@ use std::path::PathBuf;
use crate::layout::Layout;
use crate::os_input_output::OsApi;
-use crate::utils::logging::{debug_log_to_file, debug_to_file};
+use crate::utils::logging::debug_to_file;
use crate::ScreenInstruction;
pub struct ReadFromPid {
diff --git a/src/screen.rs b/src/screen.rs
index 53655216..56bb82d2 100644
--- a/src/screen.rs
+++ b/src/screen.rs
@@ -380,8 +380,14 @@ impl Screen {
}
}
pub fn handle_pty_event(&mut self, pid: RawFd, event: VteEvent) {
- let terminal_output = self.terminals.get_mut(&pid).unwrap();
- terminal_output.handle_event(event);
+ // if we don't have the terminal in self.terminals it's probably because
+ // of a race condition where the terminal was created in pty_bus but has not
+ // yet been created in Screen. These events are currently not buffered, so
+ // if you're debugging seemingly randomly missing stdout data, this is
+ // the reason
+ if let Some(terminal_output) = self.terminals.get_mut(&pid) {
+ terminal_output.handle_event(event);
+ }
}
pub fn write_to_active_terminal(&mut self, mut bytes: Vec<u8>) {
if let Some(active_terminal_id) = &self.get_active_terminal_id() {
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
index e175050e..fa302b09 100644
--- a/src/utils/logging.rs
+++ b/src/utils/logging.rs
@@ -23,14 +23,9 @@ pub fn atomic_create_dir(dir_name: &str) -> io::Result<()> {
}
}
-pub fn debug_log_to_file(message: String) -> io::Result<()> {
- atomic_create_file(MOSAIC_TMP_LOG_FILE);
- let mut file = fs::OpenOptions::new()
- .append(true)
- .create(true)
- .open(MOSAIC_TMP_LOG_FILE)?;
- file.write_all(message.as_bytes())?;
- file.write_all(b"\n")
+pub fn debug_log_to_file(mut message: String) -> io::Result<()> {
+ message.push('\n');
+ debug_log_to_file_without_newline(message)
}
pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> {
@@ -39,9 +34,7 @@ pub fn debug_log_to_file_without_newline(message: String) -> io::Result<()> {
.append(true)
.create(true)
.open(MOSAIC_TMP_LOG_FILE)?;
- file.write_all(message.as_bytes())?;
-
- Ok(())
+ file.write_all(message.as_bytes())
}
pub fn debug_log_to_file_pid_0(message: String, pid: RawFd) -> io::Result<()> {