Date: Mon, 15 Aug 2022 17:27:17 +0200 From: Mariusz Zaborski <oshogbo@freebsd.org> To: Colin Percival <cperciva@tarsnap.com> Cc: franco@opnsense.org, src-committers <src-committers@freebsd.org>, "<dev-commits-src-all@freebsd.org>" <dev-commits-src-all@freebsd.org>, dev-commits-src-main@freebsd.org Subject: Re: git: c9be47b34dd8 - main - rc: add ${name}_setup script support Message-ID: <CAGOYWV8v%2Bq=F2rdtHewje_Eh6NrJeNyTX%2BnbLJPwnNa1OzoKYQ@mail.gmail.com> In-Reply-To: <01000182a2168e9f-0a342484-127b-42fc-819a-00ddbf5158db-000000@email.amazonses.com> References: <202208151442.27FEgjSd083060@gitrepo.freebsd.org> <01000182a2168e9f-0a342484-127b-42fc-819a-00ddbf5158db-000000@email.amazonses.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000037d4705e64945bf Content-Type: text/plain; charset="UTF-8" Thats a good point. cc the author On Mon, 15 Aug 2022 at 17:19, Colin Percival <cperciva@tarsnap.com> wrote: > Can we have rc.subr(8) updated to reflect this change? It's not at all > clear > to me how foo_setup is different from start_precmd. > > Colin Percival > > On 8/15/22 07:42, Mariusz Zaborski wrote: > > The branch main has been updated by oshogbo: > > > > URL: > https://cgit.FreeBSD.org/src/commit/?id=c9be47b34dd847da1d4ab0feee4a6100b2c5ea0d > > > > commit c9be47b34dd847da1d4ab0feee4a6100b2c5ea0d > > Author: Franco Fichtner <franco@opnsense.org> > > AuthorDate: 2022-08-15 14:41:31 +0000 > > Commit: Mariusz Zaborski <oshogbo@FreeBSD.org> > > CommitDate: 2022-08-15 14:43:12 +0000 > > > > rc: add ${name}_setup script support > > > > Run a service-based setup script before running the start command. > > Useful for automatic configuration file generation. > > > > Reviewed by: https://reviews.freebsd.org/D36006 > > --- > > libexec/rc/rc.subr | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr > > index 612ee12883ec..9ae93dc391a2 100644 > > --- a/libexec/rc/rc.subr > > +++ b/libexec/rc/rc.subr > > @@ -804,6 +804,8 @@ startmsg() > > # > > # ${name}_prepend n Command added before ${command}. > > # > > +# ${name}_setup n Command executed before ${command}. > > +# > > # ${name}_login_class n Login class to use, else "daemon". > > # > > # ${name}_limits n limits(1) to apply to ${command}. > > @@ -993,8 +995,8 @@ run_rc_command() > > _group=\$${name}_group _groups=\$${name}_groups \ > > _fib=\$${name}_fib _env=\$${name}_env \ > > _prepend=\$${name}_prepend > _login_class=\${${name}_login_class:-daemon} \ > > - _limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \ > > - _env_file=\$${name}_env_file > > + _limits=\$${name}_limits _oomprotect=\$${name}_oomprotect \ > > + _setup=\$${name}_setup _env_file=\$${name}_env_file > > > > if [ -n "$_env_file" ] && [ -r "${_env_file}" ]; then # load env > from file > > set -a > > @@ -1149,6 +1151,12 @@ $command $rc_flags $command_args" > > fi > > fi > > > > + if [ -n "$_setup" ]; then > > + if ! _run_rc_doit "$_setup"; then > > + warn "failed to setup ${name}" > > + fi > > + fi > > + > > # Prepend default limits > > _doit="$_cd limits -C $_login_class $_limits > $_doit" > > > > @@ -2187,7 +2195,7 @@ check_kern_features() > > # check_namevarlist var > > # Return "0" if ${name}_var is reserved in rc.subr. > > > > -_rc_namevarlist="program chroot chdir env flags fib nice user group > groups prepend" > > +_rc_namevarlist="program chroot chdir env flags fib nice user group > groups prepend setup" > > check_namevarlist() > > { > > local _v > > > > -- > Colin Percival > Security Officer Emeritus, FreeBSD | The power to serve > Founder, Tarsnap | www.tarsnap.com | Online backups for the truly paranoid > --000000000000037d4705e64945bf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Thats a good point.<div>cc the author</div></div><br><div = class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, 15 Aug = 2022 at 17:19, Colin Percival <<a href=3D"mailto:cperciva@tarsnap.com">c= perciva@tarsnap.com</a>> wrote:<br></div><blockquote class=3D"gmail_quot= e" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204)= ;padding-left:1ex">Can we have rc.subr(8) updated to reflect this change?= =C2=A0 It's not at all clear<br> to me how foo_setup is different from start_precmd.<br> <br> Colin Percival<br> <br> On 8/15/22 07:42, Mariusz Zaborski wrote:<br> > The branch main has been updated by oshogbo:<br> > <br> > URL: <a href=3D"https://cgit.FreeBSD.org/src/commit/?id=3Dc9be47b34dd8= 47da1d4ab0feee4a6100b2c5ea0d" rel=3D"noreferrer" target=3D"_blank">https://= cgit.FreeBSD.org/src/commit/?id=3Dc9be47b34dd847da1d4ab0feee4a6100b2c5ea0d<= /a><br> > <br> > commit c9be47b34dd847da1d4ab0feee4a6100b2c5ea0d<br> > Author:=C2=A0 =C2=A0 =C2=A0Franco Fichtner <<a href=3D"mailto:franc= o@opnsense.org" target=3D"_blank">franco@opnsense.org</a>><br> > AuthorDate: 2022-08-15 14:41:31 +0000<br> > Commit:=C2=A0 =C2=A0 =C2=A0Mariusz Zaborski <oshogbo@FreeBSD.org>= ;<br> > CommitDate: 2022-08-15 14:43:12 +0000<br> > <br> >=C2=A0 =C2=A0 =C2=A0 rc: add ${name}_setup script support<br> >=C2=A0 =C2=A0 =C2=A0 <br> >=C2=A0 =C2=A0 =C2=A0 Run a service-based setup script before running th= e start command.<br> >=C2=A0 =C2=A0 =C2=A0 Useful for automatic configuration file generation= .<br> >=C2=A0 =C2=A0 =C2=A0 <br> >=C2=A0 =C2=A0 =C2=A0 Reviewed by:=C2=A0 =C2=A0 <a href=3D"https://revie= ws.freebsd.org/D36006" rel=3D"noreferrer" target=3D"_blank">https://reviews= .freebsd.org/D36006</a><br> > ---<br> >=C2=A0 =C2=A0libexec/rc/rc.subr | 14 +++++++++++---<br> >=C2=A0 =C2=A01 file changed, 11 insertions(+), 3 deletions(-)<br> > <br> > diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr<br> > index 612ee12883ec..9ae93dc391a2 100644<br> > --- a/libexec/rc/rc.subr<br> > +++ b/libexec/rc/rc.subr<br> > @@ -804,6 +804,8 @@ startmsg()<br> >=C2=A0 =C2=A0#<br> >=C2=A0 =C2=A0#=C2=A0 =C2=A0${name}_prepend n=C2=A0 =C2=A0 =C2=A0 =C2=A0= Command added before ${command}.<br> >=C2=A0 =C2=A0#<br> > +#=C2=A0 =C2=A0 ${name}_setup=C2=A0 =C2=A0n=C2=A0 =C2=A0 =C2=A0 =C2=A0= Command executed before ${command}.<br> > +#<br> >=C2=A0 =C2=A0#=C2=A0 =C2=A0${name}_login_class n=C2=A0 =C2=A0Login clas= s to use, else "daemon".<br> >=C2=A0 =C2=A0#<br> >=C2=A0 =C2=A0#=C2=A0 =C2=A0${name}_limits=C2=A0 n=C2=A0 =C2=A0 =C2=A0 = =C2=A0limits(1) to apply to ${command}.<br> > @@ -993,8 +995,8 @@ run_rc_command()<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_group=3D\$${name}_group=C2=A0= =C2=A0 =C2=A0 _groups=3D\$${name}_groups \<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_fib=3D\$${name}_fib=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 _env=3D\$${name}_env \<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_prepend=3D\$${name}_prepend= =C2=A0 _login_class=3D\${${name}_login_class:-daemon} \<br> > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_limits=3D\$${name}_limits=C2=A0 = =C2=A0 _oomprotect=3D\$${name}_oomprotect \<br> > -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_env_file=3D\$${name}_env_file<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_limits=3D\$${name}_limits=C2=A0 = =C2=A0 _oomprotect=3D\$${name}_oomprotect \<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0_setup=3D\$${name}_setup=C2=A0 =C2= =A0 =C2=A0 _env_file=3D\$${name}_env_file<br> >=C2=A0 =C2=A0<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0if [ -n "$_env_file" ] && = [ -r "${_env_file}" ]; then=C2=A0 =C2=A0# load env from file<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0set -a<br> > @@ -1149,6 +1151,12 @@ $command $rc_flags $command_args"<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0fi<br> >=C2=A0 =C2=A0<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0if [ -n "$_setup" ]; then<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ! _run_rc_doit "$_setup"; t= hen<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0warn "f= ailed to setup ${name}"<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0fi<br> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0fi<br> > +<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Prep= end default limits<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0_doit=3D"$_cd limits -C $_login_class $_limits $_doit&quo= t;<br> >=C2=A0 =C2=A0<br> > @@ -2187,7 +2195,7 @@ check_kern_features()<br> >=C2=A0 =C2=A0# check_namevarlist var<br> >=C2=A0 =C2=A0#=C2=A0 =C2=A0Return "0" if ${name}_var is reser= ved in rc.subr.<br> >=C2=A0 =C2=A0<br> > -_rc_namevarlist=3D"program chroot chdir env flags fib nice user = group groups prepend"<br> > +_rc_namevarlist=3D"program chroot chdir env flags fib nice user = group groups prepend setup"<br> >=C2=A0 =C2=A0check_namevarlist()<br> >=C2=A0 =C2=A0{<br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0local _v<br> > <br> <br> -- <br> Colin Percival<br> Security Officer Emeritus, FreeBSD | The power to serve<br> Founder, Tarsnap | <a href=3D"http://www.tarsnap.com" rel=3D"noreferrer" ta= rget=3D"_blank">www.tarsnap.com</a> | Online backups for the truly paranoid= <br> </blockquote></div> --000000000000037d4705e64945bf--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGOYWV8v%2Bq=F2rdtHewje_Eh6NrJeNyTX%2BnbLJPwnNa1OzoKYQ>