Repositories / jai.git

jai.git

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

Branch

make dir relative to home in configuration file

Author
David Mazieres <dm@uun.org>
Date
2026-03-15 23:25:12 -0700
Commit
5b4d8bf5372069d67832f848d73b3daacea0508d
jai.1.md
index 43982da..29d819d 100644
--- a/jai.1.md
+++ b/jai.1.md
@@ -123,7 +123,9 @@ virtual environment before running the command.
 `-d` *dir*, `--dir `*dir*
 : Grant full access to directory *dir* and everything below in the
   jail.  You must own the directory.  You can supply this option
-  multiple times.
+  multiple times.  Note that on the command line, relative paths are
+  relative to the current working directory, while in configuration
+  files, they are relative to your home directory.
 
 `-D`, `--nocwd`
 : By default, `jai` grants access to the current working directory
jai.cc
index 418ddb0..067a43b 100644
--- a/jai.cc
+++ b/jai.cc
@@ -29,7 +29,8 @@ struct Config {
   path cwd_;
   std::string shellcmd_;
   PathSet mask_files_;
-  bool mask_warn_{false};
+  bool mask_warn_{};
+  bool dir_relative_to_home_{};
 
   std::string user_;
   path homepath_;
@@ -111,7 +112,12 @@ Config::parse_config_file(path file, Options *opts)
   auto ld = (slash ? cwd() : homepath_ / ".jai") / file;
   if (auto [_it, ok] = config_loop_detect_.insert(ld); !ok)
     err<Options::Error>("configuration loop");
-  Defer _clear{[this, ld = std::move(ld)] { config_loop_detect_.erase(ld); }};
+  Defer _clear{[this, ld = std::move(ld), drh = dir_relative_to_home_] {
+    config_loop_detect_.erase(ld);
+    if (!drh)
+      dir_relative_to_home_ = false;
+  }};
+  dir_relative_to_home_ = true;
 
   auto r = try_read_file(slash ? AT_FDCWD : home_jai(), file);
   if (!r) {
@@ -691,7 +697,10 @@ Config::opt_parser()
                   kUnstrustedUser));
   opts(
       "-d", "--dir",
-      [this](path d) { grant_directories_.emplace(canonical(d)); },
+      [this](path d) {
+        grant_directories_.emplace(
+            canonical(dir_relative_to_home_ ? homepath_ / d : d));
+      },
       "Grant full access to DIR", "DIR");
   opts(
       "-D", "--nocwd", [this] { grant_cwd_ = false; },