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

doing kvm_open() without /bsd



/* for misc readers */
The saga continues with programs (ntpd) wanting to do kvm_open() from a
floppy boot environment (no /bsd file exists). The "solution" is apparently
to generate the name list database via kvm_mkdb when building the floppy
image since at boot time the /bsd file isn't around to read.

/* for tech readers */

In the course of my digging I ran across this:
/usr/src/lib/libkvm/kvm.c in method _kvm_open(kd, uf, mf, sf, flag, errout)
>        ufgiven = (uf != NULL);
>        if (!ufgiven)
>                uf = _PATH_UNIX; 

Which amounts to, "if uf = NULL, then set uf = /bsd".

if (ufgiven == FALSE)
  uf = _PATH_UNIX;

is easier to read and understand what's going on. It's a stylistic issue I
guess, and I favor writing code that is as straightforward as possible. The
usefulness of ufgiven is suspect. Unless I don't understand what 

>                if ((ufgiven || kvm_dbopen(kd) < 0) &&
>                    (kd->nlfd = open(uf, O_RDONLY, 0)) < 0) {
>                        _kvm_syserr(kd, kd->program, "%s", uf);
>                        goto failed;
>                }

is supposed to accomplish. At this stage in the code uf = /bsd or the user
specified value.

I believe the logic should be thus:
                if ((kvm_dbopen(kd) < 0) &&
                    (kd->nlfd = open(uf, O_RDONLY, 0)) < 0) {
                        _kvm_syserr(kd, kd->program, "%s", uf);
                        goto failed;
                }
which in English says, if both kvm_dbopen() and open() failed then handle
the error. And now we can dispense with ufgiven since it is never really
useful.


Something else I noticed.
>        if (mf == 0)
>                mf = _PATH_MEM;
>        if (sf == 0)
>                sf = _PATH_DRUM;

I realize it means the same thing, but shouldn't the 0's be NULL's?
uf/mf/sf are char*'s and the "= 0" makes it seem like the latter could be
integers from casual reading. I think they should be fixed. And purusing
other files shows that there is a lot of code written this way.

=====
 Matthew Patton, 1LT USAF	Webmaster, Resource Analysis
 PGP Fingerprint: 17D4 98B1 51F1 BCD9 D815  5F3D 3B1C 5C26 762C C9C9
          Key ID: 0x762CC9C9    Expires: 7/31/99


Visit your host, monkey.org