RE: libinit idea

From: <dteske_at_FreeBSD.org>
Date: Sun, 23 Feb 2014 11:51:35 -0800
> -----Original Message-----
> From: David Chisnall [mailto:theraven_at_FreeBSD.org]
> Sent: Sunday, February 23, 2014 10:18 AM
> To: Allan Jude
> Cc: FreeBSD Current
> Subject: Re: libinit idea
> 
> On 23 Feb 2014, at 18:11, Allan Jude <freebsd_at_allanjude.com> wrote:
> 
> > sysrc solves this nicely, it is in base now, and is great for
> > programmatically adding, removing and changing lines in rc.conf style
> > files. It is also in ports for older versions of FreeBSD where it is
> > not in base.
> 
> The problem is, there is no such thing as an rc.conf style file.  rc.conf
is just a
> shell script.  If you only edit it with sysrc, or you are careful to
preserve the
> structure, then it's fine.

Actually, sysrc is well aware that rc.conf is a shell script and sysrc will
actually
make certain that structure is preserved (regardless of whether you've
placed
shell code in rc.conf or not).

> There is absolutely nothing stopping you, however,
> from writing arbitrarily complex shell scripts inside rc.conf.  Sure, it's
a terrible
> idea to do so, but when has that ever stopped anyone?
> 

When sysrc is told to make a change, it first finds where it needs to make
that
change (/etc/rc.conf or /etc/rc.conf.local or one of other paths mentioned
in
rc_conf_files setting), it will refuse to edit the file *IF* the file
doesn't first
(before editing) pass a shell syntax check (using "sh -n FILE"). After
making the
changes in a temporarily file (produced with mktemp(1)), it again performs
yet
another syntax check (also using "sh -n FILE") to make sure that it
continues to
yield clean syntax.

On top of that, it makes certain not to muck with dynamic assignments. So it
will leave-alone an assignment such as "foo=$( bar )" if told to edit the
variable
foo -- instead opting to add a foo=newvalue after the dynamic assignment
(logic
is simple... sysrc wasn't responsible for putting that dynamic assignment
in, so
it is going to leave it as-is and put the new [static] assignment further
below.

So Allan was absolutely correct in stating that sysrc is for editing
"rc.conf style"
files -- shell scripts really. In essence, sysrc is actually a shell script
modifying
utility that takes extreme special care to rely on the fact that rc.conf
*is* a
shell script.

> An rc-replacement could enforce this by only accepting purely declarative
files
> for configuration, guaranteeing that if they were syntactically valid they
would
> also be machine editable, no matter what the user does to them.
> 

sysrc does this for you.
-- 
Devin

_____________
The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
Received on Sun Feb 23 2014 - 18:51:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:47 UTC