use Uuid to generate unique server socket names
This commit is contained in:
parent
9110e444b8
commit
1eb732773a
5 changed files with 18 additions and 5 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1774,6 +1774,9 @@ name = "uuid"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "value-bag"
|
name = "value-bag"
|
||||||
|
|
@ -2222,6 +2225,7 @@ dependencies = [
|
||||||
"termios",
|
"termios",
|
||||||
"unicode-truncate",
|
"unicode-truncate",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
|
"uuid",
|
||||||
"vte 0.8.0",
|
"vte 0.8.0",
|
||||||
"wasmer",
|
"wasmer",
|
||||||
"wasmer-wasi",
|
"wasmer-wasi",
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ lazy_static = "1.4.0"
|
||||||
wasmer = "1.0.0"
|
wasmer = "1.0.0"
|
||||||
wasmer-wasi = "1.0.0"
|
wasmer-wasi = "1.0.0"
|
||||||
interprocess = "1.1.1"
|
interprocess = "1.1.1"
|
||||||
|
uuid = { version = "0.8.2", features = ["v4"] }
|
||||||
zellij-tile = { path = "zellij-tile/", version = "0.5.0" }
|
zellij-tile = { path = "zellij-tile/", version = "0.5.0" }
|
||||||
|
|
||||||
[dependencies.async-std]
|
[dependencies.async-std]
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@ pub mod wasm_vm;
|
||||||
|
|
||||||
use crate::panes::PaneId;
|
use crate::panes::PaneId;
|
||||||
use crate::server::ServerInstruction;
|
use crate::server::ServerInstruction;
|
||||||
|
use crate::utils::consts::ZELLIJ_IPC_PIPE;
|
||||||
use async_std::task_local;
|
use async_std::task_local;
|
||||||
use errors::{get_current_ctx, ErrorContext};
|
use errors::{get_current_ctx, ErrorContext};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
|
@ -73,3 +75,8 @@ task_local! {
|
||||||
/// stack in the form of an [`ErrorContext`].
|
/// stack in the form of an [`ErrorContext`].
|
||||||
static ASYNCOPENCALLS: RefCell<ErrorContext> = RefCell::default()
|
static ASYNCOPENCALLS: RefCell<ErrorContext> = RefCell::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref UNIQUE_ZELLIJ_IPC_PIPE: String =
|
||||||
|
ZELLIJ_IPC_PIPE.to_string() + uuid::Uuid::new_v4().to_string().as_str();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ use std::process::{Child, Command};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::client::ClientInstruction;
|
use crate::client::ClientInstruction;
|
||||||
|
use crate::common::UNIQUE_ZELLIJ_IPC_PIPE;
|
||||||
use crate::errors::{get_current_ctx, ErrorContext};
|
use crate::errors::{get_current_ctx, ErrorContext};
|
||||||
use crate::panes::PositionAndSize;
|
use crate::panes::PositionAndSize;
|
||||||
use crate::server::ServerInstruction;
|
use crate::server::ServerInstruction;
|
||||||
use crate::utils::consts::ZELLIJ_IPC_PIPE;
|
|
||||||
|
|
||||||
const IPC_BUFFER_SIZE: usize = 262144;
|
const IPC_BUFFER_SIZE: usize = 262144;
|
||||||
|
|
||||||
|
|
@ -404,7 +404,7 @@ impl ClientOsApi for ClientOsInputOutput {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn connect_to_server(&self) {
|
fn connect_to_server(&self) {
|
||||||
let socket = LocalSocketStream::connect(ZELLIJ_IPC_PIPE).unwrap();
|
let socket = LocalSocketStream::connect(UNIQUE_ZELLIJ_IPC_PIPE.as_str()).unwrap();
|
||||||
let sock_fd = socket.as_raw_fd();
|
let sock_fd = socket.as_raw_fd();
|
||||||
let dup_fd = unistd::dup(sock_fd).unwrap();
|
let dup_fd = unistd::dup(sock_fd).unwrap();
|
||||||
let receiver = unsafe { LocalSocketStream::from_raw_fd(dup_fd) };
|
let receiver = unsafe { LocalSocketStream::from_raw_fd(dup_fd) };
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use zellij_tile::data::{Event, EventType, ModeInfo};
|
||||||
|
|
||||||
use crate::cli::CliArgs;
|
use crate::cli::CliArgs;
|
||||||
use crate::client::ClientInstruction;
|
use crate::client::ClientInstruction;
|
||||||
|
use crate::common::UNIQUE_ZELLIJ_IPC_PIPE;
|
||||||
use crate::common::{
|
use crate::common::{
|
||||||
errors::{ContextType, PluginContext, PtyContext, ScreenContext, ServerContext},
|
errors::{ContextType, PluginContext, PtyContext, ScreenContext, ServerContext},
|
||||||
input::actions::{Action, Direction},
|
input::actions::{Action, Direction},
|
||||||
|
|
@ -29,7 +30,6 @@ use crate::common::{
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
use crate::panes::PaneId;
|
use crate::panes::PaneId;
|
||||||
use crate::panes::PositionAndSize;
|
use crate::panes::PositionAndSize;
|
||||||
use crate::utils::consts::ZELLIJ_IPC_PIPE;
|
|
||||||
|
|
||||||
/// Instructions related to server-side application including the
|
/// Instructions related to server-side application including the
|
||||||
/// ones sent by client to server
|
/// ones sent by client to server
|
||||||
|
|
@ -83,8 +83,8 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread::Jo
|
||||||
let sessions = sessions.clone();
|
let sessions = sessions.clone();
|
||||||
let send_server_instructions = send_server_instructions.clone();
|
let send_server_instructions = send_server_instructions.clone();
|
||||||
move || {
|
move || {
|
||||||
drop(std::fs::remove_file(ZELLIJ_IPC_PIPE));
|
drop(std::fs::remove_file(UNIQUE_ZELLIJ_IPC_PIPE.as_str()));
|
||||||
let listener = LocalSocketListener::bind(ZELLIJ_IPC_PIPE).unwrap();
|
let listener = LocalSocketListener::bind(UNIQUE_ZELLIJ_IPC_PIPE.as_str()).unwrap();
|
||||||
for stream in listener.incoming() {
|
for stream in listener.incoming() {
|
||||||
match stream {
|
match stream {
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
|
|
@ -132,6 +132,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread::Jo
|
||||||
ServerInstruction::ClientExit => {
|
ServerInstruction::ClientExit => {
|
||||||
*sessions.write().unwrap() = None;
|
*sessions.write().unwrap() = None;
|
||||||
os_input.send_to_client(ClientInstruction::Exit);
|
os_input.send_to_client(ClientInstruction::Exit);
|
||||||
|
drop(std::fs::remove_file(UNIQUE_ZELLIJ_IPC_PIPE.as_str()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ServerInstruction::Render(output) => {
|
ServerInstruction::Render(output) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue