Repositories / jai.git

jai.git

Clone (read-only): git clone http://git.guha-anderson.com/git/jai.git

Branch

add JAI_NAME and JAI_MODE environment variables

Author
David Mazieres <dm@uun.org>
Date
2026-03-18 19:13:15 -0700
Commit
705b56f564dad2096ad878b7c5836d6f9affc3c3
jai.1.md
index 6933b17..0fef7eb 100644
--- a/jai.1.md
+++ b/jai.1.md
@@ -260,6 +260,13 @@ environment before running the command.
   wish to put your private home directories elsewhere in order to use
   casual mode.
 
+`JAI_NAME`
+: Set to the name of the jai instance (specified by `-n` or `--name`)
+  inside the jail.
+
+`JAI_MODE`
+: Set to the mode (strict, bare, or casual) inside a jail.
+
 # FILES
 
 In the following paths, the location `$HOME/.jai` can be changed by
jai.cc
index 57f6734..3ba0af4 100644
--- a/jai.cc
+++ b/jai.cc
@@ -755,8 +755,6 @@ again:
 void
 Config::exec(int nsfd, char **argv)
 {
-  auto env = make_env();
-
   // This function is a bit annoying because the existing jai process
   // cannot move to a new PID namespace, so we have to fork once.  But
   // the forked process will have PID 1 and behave strangely (such as
@@ -841,6 +839,15 @@ Config::exec(int nsfd, char **argv)
       bashcmd.push_back(nullptr);
       argv = const_cast<char **>(bashcmd.data());
     }
+
+    setenv("JAI_NAME", sandbox_name_.c_str(), 1);
+    setenv("JAI_MODE",
+           mode_ == kStrict ? "strict"
+           : mode_ == kBare ? "bare"
+                            : "casual",
+           1);
+    auto env = make_env();
+
     execvpe(argv0, argv, const_cast<char **>(env.data()));
     perror(argv0);
     _exit(1);
@@ -938,7 +945,8 @@ Config::opt_parser()
       "--command", [this](std::string cmd) { shellcmd_ = std::move(cmd); },
       R"(Bash command line to execute program (default: "$0" "$@"))", "CMD");
   opts(
-      "--storage", [this](std::string_view s) {
+      "--storage",
+      [this](std::string_view s) {
         if (dir_relative_to_home_)
           storagedir_ = homepath_ / s;
         else