factoring out "at" syscalls common code in nlookup

Nicolas Thery nthery at gmail.com
Sun Jul 26 18:44:41 PDT 2009


2009/7/26 Matthew Dillon <dillon at apollo.backplane.com>:
>    Looks pretty good but what is nl_atfp used for?  The fp has to be
>    held anyway, I know, but I think I'd rather it be done explicitly
>    in the system calls like it is already.

Well, I did it that way to simplify the callers (no need to keep track
of fp).  Also I thought that, as nl_nch depends on fp being ref'ed for
correctness, it is more maintainable to store the ref in the same
structure as nl_nch.  This avoids lifetime issues (bogus caller
dropping the ref early) and leaks (ref never dropped).

Would you be happier with the following?

struct file *fp = NULL;
. ..
error =  nlookup_init_at(&nd, &fp, uap->fd, uap->path, UIO_USERSPACE, 0);
if (error == 0) {
        error = kern_open(...);
}
nlookup_done_at(&nd, fp);

That keeps the callers simple and makes the ref to fp somewhat explicit.





More information about the Kernel mailing list