summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2021-04-30 20:22:09 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2021-05-04 20:48:17 +0530
commit913697b1442169c5ac20f553b8c255a1114720f5 (patch)
tree654f2ca6bb902d4a19f9f26c9ef3514de69c603d
parent93956bdcca0e2998cf4a914db23051387b4f5841 (diff)
Place socket file in runtime directory or cache directory and use names crate for socket file name
-rw-r--r--Cargo.lock75
-rw-r--r--Cargo.toml2
-rw-r--r--src/common/mod.rs15
-rw-r--r--src/common/os_input_output.rs6
-rw-r--r--src/common/utils/consts.rs7
-rw-r--r--src/server/mod.rs8
6 files changed, 87 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 60cb7d6ba..c71bef9d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -593,6 +593,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1026,6 +1032,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1207,13 +1222,36 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha",
- "rand_core",
+ "rand_core 0.6.2",
"rand_hc",
]
@@ -1224,11 +1262,26 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
@@ -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]]
@@ -1271,6 +1324,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index 4f71667bb..8b8ccc177 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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]
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 4baf503f0..10147a2c0 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -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
+ };
}
diff --git a/src/common/os_input_output.rs b/src/common/os_input_output.rs
index b14b89b89..5dfda2640 100644
--- a/src/common/os_input_output.rs
+++ b/src/common/os_input_output.rs
@@ -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();
diff --git a/src/common/utils/consts.rs b/src/common/utils/consts.rs
index 4bd1b5b12..f031dd386 100644
--- a/src/common/utils/consts.rs
+++ b/src/common/utils/consts.rs
@@ -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";
diff --git a/src/server/mod.rs b/src/server/mod.rs
index 3e0500b04..bcfbd0912 100644
--- a/src/server/mod.rs
+++ b/src/server/mod.rs
@@ -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) => {