Given a service script X, check if there is a file path_to_X/../mtree/X
and - if it exists - run mtree on it.
This allows services (including those from ports) to recreate temporary
directory hierarchies on service start.
These mtree files could either come packaged with a port or could be
added manually by a system administrator without altering/patching
a port.
This was inspired by the discussion on the FreeBSD-current mailing list:
https://lists.freebsd.org/archives/freebsd-current/2022-August/002497.html
In the specific example, a user needed to recreate /var/run/clamav.
With this patch, they could create a file
/usr/local/etc/mtree/clamav-clamd with the following content to
address their problem:
/set type=dir . var run clamav mode=0750 uname=clamav gname=clamav
This file could either be adopted by the port maintainer or, if they
don't like it, be placed their by the system administrator.
This is a proof of concept/basis for a discussion. There are certainly
other ways of addressing this issue.