]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: disable mounting disconnected private tmpfs on /var/tmp/ when DefaultDependenci...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 1 May 2025 11:58:18 +0000 (20:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 May 2025 18:33:02 +0000 (03:33 +0900)
commit6156bec7a464815084fa5218fe782ea6cb20ad52
tree837ea309664a7bb0b46d77fae4daf3d5a0a80d3d
parent26186503d71837de829c49b29ae29529bf447097
core: disable mounting disconnected private tmpfs on /var/tmp/ when DefaultDependencies=no

If DefaultDependencies=no, /var/ may not be mounted yet when the service
is being started. Previously, In such case, if the service has
PrivateTmp=disconnected, the service manager created /var/tmp/ on the
root filesystem and mounted the disconnected private tmpfs there. That
poluted the root filesystem and disturbed gpt-auto-generator on next
boot, as /var/ would not be empty anymore. See issue #37258.

This changes PrivateTmp=disconnected as the following:
- If DefaultDependencies=no and RootDirectory=/RootImage= are not set,
  then a private tmpfs is mounted _only_ on /tmp/, and set $TMPDIR=/tmp
  environment variable to suggest the service to use /tmp/.
- If DefaultDependencies=yes and RootDirectory=/RootImage= are not set,
  then implies RequiresMountsFor=/var/, though that is typically
  redundant, but anyway. Hence, we can safely mount /var/tmp/.
- Otherwise, i.e. when one of RootDirectory=/RootImage= is set, behaves
  as the same as the previous, as the private root filesystem for the
  service is explicitly prepared by the service manager, and we can
  safely mount a private tmpfs on /var/tmp/ without any extra
  dependencies.

Fixes #37258.

Co-authored-by: Mike Yuan <me@yhndnzj.com>
12 files changed:
src/core/exec-invoke.c
src/core/execute-serialize.c
src/core/execute.c
src/core/execute.h
src/core/fuzz-execute-serialize.c
src/core/namespace.c
src/core/namespace.h
src/core/unit.c
src/test/test-bpf-firewall.c
src/test/test-bpf-foreign-programs.c
src/test/test-bpf-restrict-fs.c
src/test/test-socket-bind.c