service jails and precmd make ntpd (and nfsd) sad

From: Lexi Winter <lexi_at_hemlock.eden.le-fay.org>
Date: Fri, 21 Mar 2025 09:18:45 UTC
hello,

while investigating how to support ntpd in a service jail[0], i ran into
a problem with rc(8) which i think is more architectural in nature.

the problem: several rc.d scripts, including ntpd and nfsd, assume that
you can set $command_args in ${svc}_start_precmd and this change will be
reflected in ${svc}_start when the service is started.  for non-svcj
services, this assumption is correct.  for svcj services, it is not,
because ${svc}_start_precmd is run outside the jail, then ${svc}_start is
run inside the jail in a separate shell process.

this cannot be fixed by simply running ${svc}_start_precmd in the svcj,
because ntpd's rc script needs to load a kernel module in its precmd.

i think the correct fix here is to split precmd into two things, one of
which is run outside the jail (to load kernel modules, etc.) and one of
which is run before ${svc}_start (or other actions) in the same shell
that the action will run in.

i would propose 'setup' as the thing which is run outside the jail, and
'precmd' as the thing which is run inside the jail.

am i on the right track here, or have i missed something?

[0] as a follow-up to https://github.com/freebsd/freebsd-src/pull/1619