kanbrain_core/
platform.rs1use anyhow::{Result, bail};
4
5pub fn ensure_not_root() -> Result<()> {
8 if is_root() && std::env::var_os("KANBRAIN_ALLOW_ROOT").is_none_or(|v| v != "1") {
9 bail!(
10 "kanbrain is a per-user app and doesn't run as root (sudo).\n\
11 Run it as your normal user. Only if root is your only user (e.g. a container), set KANBRAIN_ALLOW_ROOT=1."
12 );
13 }
14 Ok(())
15}
16
17#[cfg(unix)]
19fn is_root() -> bool {
20 rustix::process::geteuid().is_root()
21}
22
23#[cfg(not(unix))]
25fn is_root() -> bool {
26 false
27}