Place socket file in runtime directory or cache directory and use names crate for socket file name

This commit is contained in:
Kunal Mohan 2021-04-30 20:22:09 +05:30
parent 93956bdcca
commit 913697b144
6 changed files with 87 additions and 26 deletions

75
Cargo.lock generated
View File

@ -592,6 +592,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "funty"
version = "1.1.0"
@ -1025,6 +1031,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "names"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef320dab323286b50fb5cdda23f61c796a72a89998ab565ca32525c5c556f2da"
dependencies = [
"rand 0.3.23",
]
[[package]]
name = "nb-connect"
version = "1.1.0"
@ -1205,6 +1220,29 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = [
"libc",
"rand 0.4.6",
]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand"
version = "0.8.3"
@ -1213,7 +1251,7 @@ checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_core 0.6.2",
"rand_hc",
]
@ -1224,9 +1262,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core",
"rand_core 0.6.2",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_core"
version = "0.6.2"
@ -1242,7 +1295,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core",
"rand_core 0.6.2",
]
[[package]]
@ -1270,6 +1323,15 @@ dependencies = [
"num_cpus",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "redox_syscall"
version = "0.2.5"
@ -1597,7 +1659,7 @@ checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
dependencies = [
"cfg-if 1.0.0",
"libc",
"rand",
"rand 0.8.3",
"redox_syscall",
"remove_dir_all",
"winapi",
@ -1774,9 +1836,6 @@ name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom",
]
[[package]]
name = "value-bag"
@ -2211,6 +2270,7 @@ dependencies = [
"interprocess",
"lazy_static",
"libc",
"names",
"nix",
"nom",
"serde",
@ -2225,7 +2285,6 @@ dependencies = [
"termios",
"unicode-truncate",
"unicode-width",
"uuid",
"vte 0.8.0",
"wasmer",
"wasmer-wasi",

View File

@ -36,7 +36,7 @@ lazy_static = "1.4.0"
wasmer = "1.0.0"
wasmer-wasi = "1.0.0"
interprocess = "1.1.1"
uuid = { version = "0.8.2", features = ["v4"] }
names = "0.11.0"
zellij-tile = { path = "zellij-tile/", version = "0.5.0" }
[dependencies.async-std]

View File

@ -11,11 +11,12 @@ pub mod wasm_vm;
use crate::panes::PaneId;
use crate::server::ServerInstruction;
use crate::utils::consts::ZELLIJ_IPC_PIPE;
use async_std::task_local;
use directories_next::ProjectDirs;
use errors::{get_current_ctx, ErrorContext};
use lazy_static::lazy_static;
use std::cell::RefCell;
use std::path::PathBuf;
use std::sync::mpsc;
/// An [MPSC](mpsc) asynchronous channel with added error context.
@ -77,6 +78,14 @@ task_local! {
}
lazy_static! {
pub static ref UNIQUE_ZELLIJ_IPC_PIPE: String =
ZELLIJ_IPC_PIPE.to_string() + uuid::Uuid::new_v4().to_string().as_str();
pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
let project_dir = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
let ipc_dir = project_dir
.runtime_dir()
.unwrap_or_else(|| project_dir.cache_dir());
std::fs::create_dir_all(ipc_dir).unwrap();
let session_name = names::Generator::default().next().unwrap();
let x = ipc_dir.join(session_name);
x
};
}

View File

@ -17,7 +17,7 @@ use std::process::{Child, Command};
use std::sync::{Arc, Mutex};
use crate::client::ClientInstruction;
use crate::common::UNIQUE_ZELLIJ_IPC_PIPE;
use crate::common::ZELLIJ_IPC_PIPE;
use crate::errors::{get_current_ctx, ErrorContext};
use crate::panes::PositionAndSize;
use crate::server::ServerInstruction;
@ -386,11 +386,11 @@ impl ClientOsApi for ClientOsInputOutput {
}
}
fn connect_to_server(&self) {
let socket = match LocalSocketStream::connect(UNIQUE_ZELLIJ_IPC_PIPE.as_str()) {
let socket = match LocalSocketStream::connect(ZELLIJ_IPC_PIPE.clone()) {
Ok(sock) => sock,
Err(_) => {
std::thread::sleep(std::time::Duration::from_millis(20));
LocalSocketStream::connect(UNIQUE_ZELLIJ_IPC_PIPE.as_str()).unwrap()
LocalSocketStream::connect(ZELLIJ_IPC_PIPE.clone()).unwrap()
}
};
let sock_fd = socket.as_raw_fd();

View File

@ -3,10 +3,3 @@
pub const ZELLIJ_TMP_DIR: &str = "/tmp/zellij";
pub const ZELLIJ_TMP_LOG_DIR: &str = "/tmp/zellij/zellij-log";
pub const ZELLIJ_TMP_LOG_FILE: &str = "/tmp/zellij/zellij-log/log.txt";
pub const ZELLIJ_IPC_PIPE: &str = "/tmp/zellij/ipc";
pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
// TODO: ${PREFIX} argument in makefile
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";

View File

@ -16,7 +16,7 @@ use zellij_tile::data::{Event, EventType, ModeInfo};
use crate::cli::CliArgs;
use crate::client::ClientInstruction;
use crate::common::UNIQUE_ZELLIJ_IPC_PIPE;
use crate::common::ZELLIJ_IPC_PIPE;
use crate::common::{
errors::{ContextType, PluginContext, PtyContext, ScreenContext, ServerContext},
input::actions::{Action, Direction},
@ -83,8 +83,8 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread::Jo
let sessions = sessions.clone();
let send_server_instructions = send_server_instructions.clone();
move || {
drop(std::fs::remove_file(UNIQUE_ZELLIJ_IPC_PIPE.as_str()));
let listener = LocalSocketListener::bind(UNIQUE_ZELLIJ_IPC_PIPE.as_str()).unwrap();
drop(std::fs::remove_file(ZELLIJ_IPC_PIPE.clone()));
let listener = LocalSocketListener::bind(ZELLIJ_IPC_PIPE.clone()).unwrap();
for stream in listener.incoming() {
match stream {
Ok(stream) => {
@ -132,7 +132,7 @@ pub fn start_server(os_input: Box<dyn ServerOsApi>, opts: CliArgs) -> thread::Jo
ServerInstruction::ClientExit => {
*sessions.write().unwrap() = None;
os_input.send_to_client(ClientInstruction::Exit);
drop(std::fs::remove_file(UNIQUE_ZELLIJ_IPC_PIPE.as_str()));
drop(std::fs::remove_file(ZELLIJ_IPC_PIPE.clone()));
break;
}
ServerInstruction::Render(output) => {