A filename of `-` emits the report to the log at `level` instead of writing
a file (no directory is resolved).
- If the filename begins with `/`, the file is written relative to the
- mount namespace root (`/`) when bees starts up, before any mount
+ If the filename begins with `${HOME}`, the file is written relative to the
+ open `path.home` (`$BEESHOME`) directory. `${HOME}` is not a substitution
+ variable but a prefix bound to the directory fd bees already holds open, so
+ the write targets the same directory as the hash table regardless of later
+ path changes; any remaining substitution variables after the prefix are
+ still expanded. If `path.home` is unavailable (for example
+ `state.persistent = no`), a `${HOME}` report is disabled.
+
+ Otherwise, if the filename begins with `/`, the file is written relative to
+ the mount namespace root (`/`) when bees starts up, before any mount
namespace change inside the bees process; otherwise, the file is
written relative to `path.reports`.
# chown. A leading ':' forces a name lookup (e.g. ':1000').
group =
- # Filename of the report file.
- # A filename of '-' emits the report to the log (at the level above)
- # instead of writing a file.
- # Substitution variables are expanded (${UUID}, ${LABEL}, ${BASENAME}).
- # If the filename begins with '/', all leading slashes are stripped and
- # it is resolved via openat(2) against the filesystem root ('/') opened
- # at startup before any mount namespace change.
- # Otherwise it is resolved via openat(2) against the path.reports directory.
- # Empty after interpolation = this output is disabled even if active = yes.
+ # Filename of the report file. '-' emits to the log instead of
+ # writing a file; empty disables this output. A relative name
+ # resolves under path.reports, '/...' against the filesystem root,
+ # and a leading ${HOME} against path.home. ${UUID}, ${LABEL}, and
+ # ${BASENAME} are expanded.
filename =
# Content tokens written to the file, in order, space- or comma-separated.
BEESLOGINFO("report." << sec_name << ".active = " << (cfg.active ? "yes" : "no")
<< " [report." << sec_name << ".active]");
cfg.interval_s = bc->get_config().get(prefix + "interval", parse_report_interval);
- cfg.filename = bc->get_config().subst(
- bc->get_config().get(prefix + "filename", [](const string &s) { return s; }));
+ {
+ auto raw_filename = bc->get_config().get(prefix + "filename", [](const string &s) { return s; });
+ // A leading ${HOME} selects the open $BEESHOME directory fd at
+ // resolution time rather than expanding to a path. Expanding
+ // to a path would lose the open-fd guarantee (it would re-walk
+ // a possibly-moved path through the mount-root fd); binding the
+ // fd bees already holds matches the legacy beesstats.txt write
+ // exactly. ${HOME} is not a subst variable, so strip it here
+ // before subst; the remainder is still subst-expanded so
+ // ${UUID} etc. work after the prefix.
+ static const string home_prefix = "${HOME}/";
+ if (raw_filename.compare(0, home_prefix.size(), home_prefix) == 0) {
+ cfg.home_relative = true;
+ raw_filename = raw_filename.substr(home_prefix.size());
+ }
+ cfg.filename = bc->get_config().subst(raw_filename);
+ }
cfg.mode = bc->get_config().get(prefix + "mode", [](const string &s) {
return mode_t(stoul(s, nullptr, 8));
});
// Determine which fds are needed based on active report filenames
bool needs_reports_path = false;
bool needs_mount_root = false;
+ bool needs_home = false;
for (const auto &cfg : configs) {
if (!cfg.active || cfg.filename.empty()) continue;
if (cfg.filename == "-") {
// Log sink: emitted via BEESLOG, needs no directory fd.
+ } else if (cfg.home_relative) {
+ needs_home = true;
} else if (cfg.filename.at(0) == '/') {
needs_mount_root = true;
} else {
mount_root_fd = open_or_die("/", FLAGS_OPEN_DIR);
}
+ // The $BEESHOME directory fd, opened here (before any mount namespace
+ // change) so a ${HOME} report writes through the same open fd the
+ // legacy beesstats.txt used. May be empty when path.home is
+ // unavailable (e.g. state.persistent=no); such reports go inert below.
+ Fd home_reports_fd;
+ if (needs_home) {
+ home_reports_fd = bc->home_fd();
+ }
+
auto reporter = make_shared<BeesReporter>(bc);
// Resolve (dir_fd, rel_filename) for each active report before adding
if (cfg.filename == "-") {
// Log sink: no path resolution; write_report emits via
// BEESLOG at cfg.log_level.
+ } else if (cfg.home_relative) {
+ if (!home_reports_fd) {
+ // path.home unavailable: disable this report rather
+ // than fail an openat against an empty fd at write time.
+ BEESLOGINFO("report '" << cfg.name << "' targets ${HOME} but path.home is unavailable; disabling [report." << cfg.name << ".filename, path.home]");
+ cfg.filename.clear();
+ } else {
+ cfg.dir_fd = home_reports_fd;
+ cfg.rel_filename = cfg.filename;
+ }
} else if (cfg.filename.at(0) == '/') {
cfg.dir_fd = mount_root_fd;
cfg.rel_filename = cfg.filename.substr(cfg.filename.find_first_not_of('/'));