zellij/zellij-utils/src/consts.rs
har7an f26e73ce03
Log thread_bus IPC messages only in debug mode (#1800)
* zellij: Add global `DEBUG_MODE` variable

that tells us whether zellij was started with the `--debug` CLI flag.

* utils/errors: Only log thread_bus message in debug

mode, and discard the message otherwise.

* utils/logging: Increase logsize to 16 MiB

per logfile, totaling 32 MiB of logs at most (in two files).

* zellij: Set global `DEBUG` variable in server

thread and make sure the value of the `--debug` CLI flag is propagated
to the server, too.

This means that to enable debug mode, the server must be started with
the `--debug` flag. This happens when the first client that starts the
zellij session has the `--debug` flag set, because it will be forwarded
to the server. Subsequent clients attaching to the same session with the
`--debug` flag specified **do not** override the value of the `DEBUG`
variable. Hence, if the server wasn't started in debug mode, this cannot
be changed.
2022-10-17 15:34:06 +00:00

75 lines
2.5 KiB
Rust

//! Zellij program-wide constants.
use directories_next::ProjectDirs;
use lazy_static::lazy_static;
use once_cell::sync::OnceCell;
use std::path::PathBuf;
pub const ZELLIJ_CONFIG_FILE_ENV: &str = "ZELLIJ_CONFIG_FILE";
pub const ZELLIJ_CONFIG_DIR_ENV: &str = "ZELLIJ_CONFIG_DIR";
pub const ZELLIJ_LAYOUT_DIR_ENV: &str = "ZELLIJ_LAYOUT_DIR";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const DEFAULT_SCROLL_BUFFER_SIZE: usize = 10_000;
pub static SCROLL_BUFFER_SIZE: OnceCell<usize> = OnceCell::new();
pub static DEBUG_MODE: OnceCell<bool> = OnceCell::new();
pub const SYSTEM_DEFAULT_CONFIG_DIR: &str = "/etc/zellij";
pub const SYSTEM_DEFAULT_DATA_DIR_PREFIX: &str = system_default_data_dir();
const fn system_default_data_dir() -> &'static str {
if let Some(data_dir) = std::option_env!("PREFIX") {
data_dir
} else {
"/usr"
}
}
lazy_static! {
pub static ref ZELLIJ_PROJ_DIR: ProjectDirs =
ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
pub static ref ZELLIJ_CACHE_DIR: PathBuf = ZELLIJ_PROJ_DIR.cache_dir().to_path_buf();
}
pub const FEATURES: &[&str] = &[
#[cfg(feature = "disable_automatic_asset_installation")]
"disable_automatic_asset_installation",
];
#[cfg(unix)]
pub use unix_only::*;
#[cfg(unix)]
mod unix_only {
use super::*;
use crate::envs;
use crate::shared::set_permissions;
use lazy_static::lazy_static;
use nix::unistd::Uid;
use std::fs;
lazy_static! {
static ref UID: Uid = Uid::current();
pub static ref ZELLIJ_IPC_PIPE: PathBuf = {
let mut sock_dir = ZELLIJ_SOCK_DIR.clone();
fs::create_dir_all(&sock_dir).unwrap();
set_permissions(&sock_dir, 0o700).unwrap();
sock_dir.push(envs::get_session_name().unwrap());
sock_dir
};
pub static ref ZELLIJ_TMP_DIR: PathBuf = PathBuf::from(format!("/tmp/zellij-{}", *UID));
pub static ref ZELLIJ_TMP_LOG_DIR: PathBuf = ZELLIJ_TMP_DIR.join("zellij-log");
pub static ref ZELLIJ_TMP_LOG_FILE: PathBuf = ZELLIJ_TMP_LOG_DIR.join("zellij.log");
pub static ref ZELLIJ_SOCK_DIR: PathBuf = {
let mut ipc_dir = envs::get_socket_dir().map_or_else(
|_| {
ZELLIJ_PROJ_DIR
.runtime_dir()
.map_or_else(|| ZELLIJ_TMP_DIR.clone(), |p| p.to_owned())
},
PathBuf::from,
);
ipc_dir.push(VERSION);
ipc_dir
};
}
}