BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / netccitt / pk_acct.c
index e759ac3..a66906c 100644 (file)
@@ -7,21 +7,44 @@
  * the Laboratory for Computation Vision and the Computer Science Department
  * of the University of British Columbia.
  *
  * the Laboratory for Computation Vision and the Computer Science Department
  * of the University of British Columbia.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)pk_acct.c   7.5 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)pk_acct.c   7.6 (Berkeley) 6/26/91
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "time.h"
+#include "namei.h"
 #include "proc.h"
 #include "proc.h"
-#include "user.h"
 #include "vnode.h"
 #include "kernel.h"
 #include "file.h"
 #include "vnode.h"
 #include "kernel.h"
 #include "file.h"
-#include "acct.h"
-#include "uio.h"
 #include "socket.h"
 #include "socketvar.h"
 
 #include "socket.h"
 #include "socketvar.h"
 
@@ -42,35 +65,29 @@ pk_accton (path)
        char *path;
 {
        register struct vnode *vp = NULL;
        char *path;
 {
        register struct vnode *vp = NULL;
-       register struct nameidata *ndp = &u.u_nd;
+       struct nameidata nd;
        struct vnode *oacctp = pkacctp;
        struct vnode *oacctp = pkacctp;
+       struct proc *p = curproc;
        int error;
 
        int error;
 
-       ndp -> ni_segflg = UIO_USERSPACE;
-       ndp -> ni_dirp = path;
-       if (error = vn_open (ndp, FREAD|FWRITE, 0))
+       if (path == 0)
+               goto close;
+       nd.ni_segflg = UIO_USERSPACE;
+       nd.ni_dirp = path;
+       if (error = vn_open (&nd, p, FWRITE, 0644))
                return (error);
                return (error);
-       vp = ndp -> ni_vp;
+       vp = nd.ni_vp;
+       VOP_UNLOCK(vp);
        if (vp -> v_type != VREG) {
                vrele (vp);
                return (EACCES);
        }
        pkacctp = vp;
        if (vp -> v_type != VREG) {
                vrele (vp);
                return (EACCES);
        }
        pkacctp = vp;
-       if (oacctp)
-               vrele (oacctp);
-       return (0);
-}
-
-/* 
- *  Turn off packet accounting
- */
-
-pk_acctoff ()
-{
-       if (pkacctp) {
-               vrele (pkacctp);
-               pkacctp = 0;
+       if (oacctp) {
+       close:
+               error = vn_close (oacctp, FWRITE, p -> p_ucred, p);
        }
        }
+       return (error);
 }
 
 /* 
 }
 
 /* 
@@ -102,7 +119,7 @@ register struct pklcd *lcp;
                acbuf.x25acct_revcharge = 1;
        acbuf.x25acct_stime = lcp -> lcd_stime;
        acbuf.x25acct_etime = time.tv_sec - acbuf.x25acct_stime;
                acbuf.x25acct_revcharge = 1;
        acbuf.x25acct_stime = lcp -> lcd_stime;
        acbuf.x25acct_etime = time.tv_sec - acbuf.x25acct_stime;
-       acbuf.x25acct_uid = u.u_uid;
+       acbuf.x25acct_uid = curproc -> p_cred -> p_ruid;
        acbuf.x25acct_psize = sa -> x25_opts.op_psize;
        acbuf.x25acct_net = sa -> x25_net;
        /*
        acbuf.x25acct_psize = sa -> x25_opts.op_psize;
        acbuf.x25acct_net = sa -> x25_net;
        /*
@@ -123,6 +140,7 @@ register struct pklcd *lcp;
        acbuf.x25acct_rxcnt = lcp -> lcd_rxcnt;
 
        (void) vn_rdwr(UIO_WRITE, vp, (caddr_t)&acbuf, sizeof (acbuf),
        acbuf.x25acct_rxcnt = lcp -> lcd_rxcnt;
 
        (void) vn_rdwr(UIO_WRITE, vp, (caddr_t)&acbuf, sizeof (acbuf),
-               (off_t)0, UIO_SYSSPACE, IO_UNIT|IO_APPEND, u.u_cred, (int *)0,
+               (off_t)0, UIO_SYSSPACE, IO_UNIT|IO_APPEND,
+               curproc -> p_ucred, (int *)0,
                (struct proc *)0);
 }
                (struct proc *)0);
 }