+ return (error);
+ }
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->fname, p);
+ if (error = vn_open(&nd, FWRITE, 0644))
+ return (error);
+ vp = nd.ni_vp;
+ VOP_UNLOCK(vp);
+ if (vp->v_type != VREG) {
+ (void) vn_close(vp, FWRITE, p->p_ucred, p);
+ return (EACCES);
+ }
+ oacctp = acctp;
+ acctp = vp;
+ if (oacctp)
+ error = vn_close(oacctp, FWRITE, p->p_ucred, p);
+ acctwatch(NULL);
+ return (error);
+}
+
+/*
+ * Periodically check the file system to see if accounting
+ * should be turned on or off. Beware the case where the vnode
+ * has been vgone()'d out from underneath us, e.g. when the file
+ * system containing the accounting file has been forcibly unmounted.
+ */
+/* ARGSUSED */
+void
+acctwatch(a)
+ void *a;
+{
+ struct statfs sb;
+
+ if (savacctp) {
+ if (savacctp->v_type == VBAD) {
+ (void) vn_close(savacctp, FWRITE, NOCRED, NULL);
+ savacctp = NULL;