Taylor R Campbell <campbell+netbsd-tech-k...@mumble.net> wrote: > I don't think namei.h / vfs_lookup.c is the right place to be handling > file descriptors. Can you make these take vnodes, rather than file > descriptors, or move them into vfs_syscalls.c?
I made the change, but it makes nameiat_simple_user() usage more complicated, with code duplicated on each call (see example at the end) > I think you'll leak pb here in the error branch above. I haven't gone > through the other error branches in the patch, but the proliferation > of new resource acquisitions requiring clean-up makes me nervous. The problem is that we need to hold a reference on the vnode we use in NDAT(). +static int +do_sys_chmodat(struct lwp *l, int fdat, const char *path, int mode, int flags) +{ int error; struct vnode *vp; + namei_simple_flags_t nsflag; + file_t *dfp = NULL; + struct vnode *dvp = NULL; - error = namei_simple_user(SCARG(uap, path), - NSM_FOLLOW_TRYEMULROOT, &vp); + if (flags & AT_SYMLINK_NOFOLLOW) + nsflag = NSM_NOFOLLOW_TRYEMULROOT; + else + nsflag = NSM_FOLLOW_TRYEMULROOT; + + /* fd_getvnode() will use the descriptor for us */ + if (fdat != AT_FDCWD) { + if ((error = fd_getvnode(fdat, &dfp)) != 0) + return (error); + dvp = dfp->f_data; + } + + error = nameiat_simple_user(dvp, path, nsflag, &vp); if (error != 0) - return (error); + goto out; - error = change_mode(vp, SCARG(uap, mode), l); + error = change_mode(vp, mode, l); vrele(vp); +out: + if (dfp != NULL) + fd_putfile(fdat); + return (error); } -- Emmanuel Dreyfus http://hcpnet.free.fr/pubz m...@netbsd.org