Menu

#531 rc.d-scripts, start_precmd variable a little bit too global

v0.69x
closed
Volker
5
2012-10-28
2009-03-18
skab
No

I was playing with rc.d-files (embedded, 0.7 4427), and stumbled across some unexpected behaviour.

Let's say I've got the following rc.d file there:

/etc/rc.d/test-rc-file:

...
start_precmd="start_precmd"
...
start_precmd()
{
command_args = "-some -very -bad -arguments"
}
run_rc_command "$1"

Expected result would be that this function will be called once, when "test-rc-file" is run to init/start the daemon. The script is run exactly once, as it should, but the start_precmd function is called a couple times more often. I found out that some other rc.d-files that don't define their own start_precmd will execute that function, like nut_upsmon, nut_upslog, powerd, local...

As long as that function only inits some files or something it wouldn't matter, but in this case the function changes a global variable. Result is e.g. a upsmon running with the following arguments:

/usr/local/sbin/upsmon -u root localhost -some -very -bad -arguments

which is not quite what it should look like.

I tried to globally unset that function in every rc file by hacking rc.subr, which is called by every single rc-script (except "hosts"):

echo "start_precmd=" >>/etc/rc.subr

and that did the trick without any ill side effects as far as I can see, I haven't tested anything in detail yet. Maybe it would be a good idea to reset some other global variables (that actually shouldn't be that global) as well?

Maybe someone with more knowledge about the whole rc.d mechanisms could look into that? This has potential for really hard to diagnose problems. I only noticed the problem when I found a "-some" file with a couple lines of "-very -bad -arguments" in the root dir after booting.

Discussion

  • Volker

    Volker - 2009-03-19

    Did not realize this till now but as you've mentioned it has some bad potential.
    I'll check that issue.

    Regards
    Volker

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.