Init.c, making it chroot

Oliver Fromme olli at lurza.secnetix.de
Thu Jan 4 18:04:01 UTC 2007


John Baldwin wrote:
 > Oliver Fromme wrote:
 > > I've created (and tested!) a new patch.  I've tested on
 > > RELENG_6, but I think init(8) isn't very different on
 > > HEAD, so it should work there, too.
 > > 
 > > Any comments are welcome.  I particularly appreciate
 > > if others test this stuff.
 > 
 > Some things I noticed:
 > 
 > - Why do you have the 'ichroot_name' and 'iscript_name' variables?  I would
 >   just pass the string literal to the kenv() function, e.g.
 > 
 > 	if (kenv(KENV_GET, "init_script", kenv_value, sizeof(kenv_value)) > 0) {
 > 
 >   I think that putting the constant right there is easier for someone who
 >   is reading the code to see what is going on.

In fact that's what I tried first ...  Alas:
warning: passing arg 2 of `kenv' discards qualifiers from pointer target type

 > - Rather than abusing a global runcom_script variable that you change to
 >   get side effects when you invoke runcom(), why not change runcom() to
 >   take a single 'char *script' as an argument and just pass _PATH_RUNCOM
 >   or kenv_value as appropriate and get rid of the global runcom_script
 >   variable?

You are right, the global runcom_script variable does not
look very clean.  However, the problem is that runcom() is
one of the transition action functions, i.e. it is called
by the transition() function and never gets an argument.

Of course it is possible to write an additional function
run_script(char *script) which contains runcom's current
code, and make the runcom() function a wrapper that just
calls run_script(_PATH_RUNCOM).  This isn't a perfectly
clean solution either, but maybe it's at least a little bit
better.

e.g. basically:

    state_func_t
    runcom (void)
    {
            return run_script(_PATH_RUNCOM);
    }

    state_func_t
    run_script (char *script)
    {
            /* all the code formerly in runcom() */
    }

Then the init_script code would call run_script(kenv_value)
instead of runcom(), of course.

Would that be acceptable?  Or do you have an even better
solution in mind?

Best regards
   Oliver

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"If Java had true garbage collection, most programs
would delete themselves upon execution."
        -- Robert Sewell


More information about the freebsd-hackers mailing list