[arch-general] Re: [Bulk] Re:RFC: OpenRC as init system for Arch

Nicolas Sebrecht nsebrecht at piing.fr
Wed May 9 06:30:34 EDT 2012


The 07/05/12, Patrick Lauer wrote:

> So anyway. If you complain about bad shell, fix it, or throw some
> examples at me so I can rewrite them cleanly.

"Patch it yourself" is exactly the opposite of what I would expect. This
is not peace of mind to add patches to already too much stressed code in
pieces of core tools. I'm not talking about you especially and vanilla
OpenRC scripts but those written and tuned by maintainers.

>                                               Don't think rewriting in
> Modula-3 will make it any better, the same people you condemned for not
> writing good shell won't write good INTERCAL either. Educate them, fix
> any bug you find, enjoy.

Traking down what maintainers do with stderr and how error code is
handled in init shell scripts is most of the time a good example of how
educated people can write poor shell code.

As you're asking for it, here is a random example of shell code in sysfs
(a very core script) taken from official repository(1):

  if [ ! -d /sys ]; then
    if ! mkdir -m 0755 /sys; then
      ewarn "Could not create /sys!"
      return 1
    fi
  fi

This code is exposed to race conditions as the directory creation could
happen in a slice between the first condition check and the next mkdir
call. Of course, in this particular case we can sanely expect the
creation of /sys beeing not concurrency at all, but this way of
"checking for conditions and then handle the missing condition after the
facts" is almost everywhere in the code.  This is RACY and plain WRONG.

You should turn them all in things like:

  mkdir /sys 2> /dev/null 2>&1
  cd /sys || {
    ewarn "<the error message>"
    return 1
  }

If this kind of problem was only for creating directories, I wouldn't
even mention it. But in real life these shell code scripts make
debugging and maintaining init a nightmare. Writing good shell code is
MUCH harder than it looks at a first glance, including for educated
people.

(1) http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=blob_plain;f=init.d/sysfs.in;hb=HEAD

-- 
Nicolas Sebrecht


More information about the arch-general mailing list