tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: rc.d script style guide



Robert Elz <kre%munnari.OZ.AU@localhost> writes:

>     Date:        Sat, 07 Jan 2023 08:52:15 -0500
>     From:        Greg Troxel <gdt%lexort.com@localhost>
>     Message-ID:  <rmik01yv4ds.fsf%s1.lexort.com@localhost>
>
>   | 1) conditional /etc/rc.subr

The script is designed for systems that can and do run rc.d scripts
which is
  NetBSD
  macOS with rc.subr package
  ?

The idea on not-NetBSD is to hook the pkgsrc rc.d into the native system.
>
>   |   if [ -f /etc/rc.subr -a -f /etc/rc.conf -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]
>   |   then
>
>   | 2) Strange formatting with then on a new line (see above)
>
> What's supposedly strange about that?   That's how I'd usually write
> a sh if statement (unless the code is very small, and the whole thing
> will fit on one line).

I have essentially never seen it, even if it was obviously legal.  On
the system I'm using to modify ups-nut stuff, I find instances in 3 rc.d
scripts, all from pkgsrc.   Plus 6 instances in NetBSD, vs 247 instances
of "; then".

Therefore it seems to me that there is a NetBSD style guide that just
isn't written down.

>   | Is this:
>   |   - just an odd style choice?
>
> Depends upon your definition of odd.   In this case, the if [...]
> ends up being (about, if not exactly) 80 chars wide (with the 'i' from 'if'
> in column 1) so adding more to the end of the line would mean line
> wrapping anyway - in that case, I'd *always* (even if other line wrapping
> is also needed) put the "then" on a line by itself.

Fair point but doesn't explain almost all of what I'm seeing.

> and of those, personally, I prefer the 2nd most of the time, it keeps
> the "if" related syntax all lined up, rather than spread out.

Interesting that this preference seems rare.  If that were the norm I
would not have blinked.

> What ought to be changed in that is the use of -a in the test ('[') command.
> That's obsolete (because it can be ambiguous, and cause problems), so,
> assuming that all those tests are necessary (no opinion on that), I'd

The test manpage (9) lists -a without saying that it is obsolete.  But I
think we're heading to just pruning the entire concept.


Home | Main Index | Thread Index | Old Index