tmpfiles: v/q/Q: Add env var to skip check for rootfs in subvolume

This commit is contained in:
Adrian Vovk 2021-02-09 16:20:32 -05:00 committed by Lennart Poettering
parent 46a906f414
commit 4368c60c39
2 changed files with 14 additions and 2 deletions

View file

@ -279,3 +279,9 @@ systemd-sysext:
specify API file systems such as `/proc/` or `/sys/` here, or hierarchies
that have them as submounts. In particular, do not specify the root directory
`/` here.
systemd-tmpfiles:
* `SYSTEMD_TMPFILES_FORCE_SUBVOL` - if unset, v/q/Q lines will create subvolumes only if the
OS itself is installed into a subvolume. If set to 1 (or another true value), these lines will always create
subvolumes (if the backing filesystem supports them). If set to 0, these lines will always create directories.

View file

@ -27,6 +27,7 @@
#include "def.h"
#include "dirent-util.h"
#include "dissect-image.h"
#include "env-util.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
@ -1614,8 +1615,13 @@ static int create_directory_or_subvolume(const char *path, mode_t mode, bool sub
return pfd;
if (subvol) {
if (btrfs_is_subvol(empty_to_root(arg_root)) <= 0)
r = getenv_bool("SYSTEMD_TMPFILES_FORCE_SUBVOL");
if (r < 0) {
if (r != -ENXIO) /* env var is unset */
log_warning_errno(r, "Cannot parse value of $SYSTEMD_TMPFILES_FORCE_SUBVOL, ignoring.");
r = btrfs_is_subvol(empty_to_root(arg_root)) > 0;
}
if (!r)
/* Don't create a subvolume unless the root directory is
* one, too. We do this under the assumption that if the
* root directory is just a plain directory (i.e. very