sleep doesn't need spl0 (idle does it)
[unix-history] / usr / src / sys / kern / kern_acct.c
index ebe0305..962f41f 100644 (file)
@@ -1,24 +1,25 @@
-/*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
  *
  *
- *     @(#)kern_acct.c 7.13 (Berkeley) %G%
+ *     @(#)kern_acct.c 7.20 (Berkeley) %G%
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "time.h"
+#include "namei.h"
+#include "resourcevar.h"
 #include "proc.h"
 #include "ioctl.h"
 #include "termios.h"
 #include "tty.h"
 #include "proc.h"
 #include "ioctl.h"
 #include "termios.h"
 #include "tty.h"
-#include "user.h"
 #include "vnode.h"
 #include "mount.h"
 #include "kernel.h"
 #include "vnode.h"
 #include "mount.h"
 #include "kernel.h"
+#include "file.h"
 #include "acct.h"
 #include "acct.h"
-#include "uio.h"
 #include "syslog.h"
 
 /*
 #include "syslog.h"
 
 /*
@@ -35,7 +36,15 @@ struct       vnode *acctp;
 struct vnode *savacctp;
 
 /*
 struct vnode *savacctp;
 
 /*
- * Perform process accounting functions.
+ * Enable or disable process accounting.
+ *
+ * If a non-null filename is given, that file is used to store accounting
+ * records on process exit. If a null filename is given process accounting
+ * is suspended. If accounting is enabled, the system checks the amount
+ * of freespace on the filesystem at timeval intervals. If the amount of
+ * freespace is below acctsuspend percent, accounting is suspended. If
+ * accounting has been suspended, and freespace rises above acctresume,
+ * accounting is resumed.
  */
 /* ARGSUSED */
 sysacct(p, uap, retval)
  */
 /* ARGSUSED */
 sysacct(p, uap, retval)
@@ -46,45 +55,41 @@ sysacct(p, uap, retval)
        int *retval;
 {
        register struct vnode *vp;
        int *retval;
 {
        register struct vnode *vp;
-       register struct nameidata *ndp = &u.u_nd;
        extern int acctwatch();
        struct vnode *oacctp;
        int error;
        extern int acctwatch();
        struct vnode *oacctp;
        int error;
+       struct nameidata nd;
 
 
-       if (error = suser(u.u_cred, &u.u_acflag))
+       if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
        if (savacctp) {
                acctp = savacctp;
                savacctp = NULL;
        }
                return (error);
        if (savacctp) {
                acctp = savacctp;
                savacctp = NULL;
        }
-       if (uap->fname==NULL) {
+       if (uap->fname == NULL) {
                if (vp = acctp) {
                        acctp = NULL;
                if (vp = acctp) {
                        acctp = NULL;
-                       vrele(vp);
+                       error = vn_close(vp, FWRITE, p->p_ucred, p);
                        untimeout(acctwatch, (caddr_t)&chk);
                }
                        untimeout(acctwatch, (caddr_t)&chk);
                }
-               return (0);
+               return (error);
        }
        }
-       ndp->ni_nameiop = LOOKUP | FOLLOW;
-       ndp->ni_segflg = UIO_USERSPACE;
-       ndp->ni_dirp = uap->fname;
-       if (error = namei(ndp))
+       nd.ni_segflg = UIO_USERSPACE;
+       nd.ni_dirp = uap->fname;
+       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) {
        if (vp->v_type != VREG) {
-               vrele(vp);
+               (void) vn_close(vp, FWRITE, p->p_ucred, p);
                return (EACCES);
        }
                return (EACCES);
        }
-       if (vp->v_mount->mnt_flag & MNT_RDONLY) {
-               vrele(vp);
-               return (EROFS);
-       }
        oacctp = acctp;
        acctp = vp;
        if (oacctp)
        oacctp = acctp;
        acctp = vp;
        if (oacctp)
-               vrele(oacctp);
+               error = vn_close(oacctp, FWRITE, p->p_ucred, p);
        acctwatch(&chk);
        acctwatch(&chk);
-       return (0);
+       return (error);
 }
 
 /*
 }
 
 /*
@@ -97,7 +102,7 @@ acctwatch(resettime)
        struct statfs sb;
 
        if (savacctp) {
        struct statfs sb;
 
        if (savacctp) {
-               (void)VFS_STATFS(savacctp->v_mount, &sb);
+               (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
                if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
                        acctp = savacctp;
                        savacctp = NULL;
                if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
                        acctp = savacctp;
                        savacctp = NULL;
@@ -107,7 +112,7 @@ acctwatch(resettime)
        }
        if (acctp == NULL)
                return;
        }
        if (acctp == NULL)
                return;
-       (void)VFS_STATFS(acctp->v_mount, &sb);
+       (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
        if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
                savacctp = acctp;
                acctp = NULL;
        if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
                savacctp = acctp;
                acctp = NULL;
@@ -117,7 +122,8 @@ acctwatch(resettime)
 }
 
 /*
 }
 
 /*
- * On exit, write a record on the accounting file.
+ * This routine calculates an accounting record for a process and,
+ * if accounting is enabled, writes it to the accounting file.
  */
 acct(p)
        register struct proc *p;
  */
 acct(p)
        register struct proc *p;
@@ -132,7 +138,7 @@ acct(p)
        if ((vp = acctp) == NULL)
                return (0);
        bcopy(p->p_comm, ap->ac_comm, sizeof(ap->ac_comm));
        if ((vp = acctp) == NULL)
                return (0);
        bcopy(p->p_comm, ap->ac_comm, sizeof(ap->ac_comm));
-       ru = &u.u_ru;
+       ru = &p->p_stats->p_ru;
        s = splclock();
        ut = p->p_utime;
        st = p->p_stime;
        s = splclock();
        ut = p->p_utime;
        st = p->p_stime;
@@ -140,15 +146,15 @@ acct(p)
        splx(s);
        ap->ac_utime = compress(ut.tv_sec, ut.tv_usec);
        ap->ac_stime = compress(st.tv_sec, st.tv_usec);
        splx(s);
        ap->ac_utime = compress(ut.tv_sec, ut.tv_usec);
        ap->ac_stime = compress(st.tv_sec, st.tv_usec);
-       timevalsub(&t, &u.u_start);
+       timevalsub(&t, &p->p_stats->p_start);
        ap->ac_etime = compress(t.tv_sec, t.tv_usec);
        ap->ac_etime = compress(t.tv_sec, t.tv_usec);
-       ap->ac_btime = u.u_start.tv_sec;
-       ap->ac_uid = p->p_ruid;
-       ap->ac_gid = p->p_rgid;
+       ap->ac_btime = p->p_stats->p_start.tv_sec;
+       ap->ac_uid = p->p_cred->p_ruid;
+       ap->ac_gid = p->p_cred->p_rgid;
        t = st;
        timevaladd(&t, &ut);
        if (i = t.tv_sec * hz + t.tv_usec / tick)
        t = st;
        timevaladd(&t, &ut);
        if (i = t.tv_sec * hz + t.tv_usec / tick)
-               ap->ac_mem = (ru->ru_ixrss+ru->ru_idrss+ru->ru_isrss) / i;
+               ap->ac_mem = (ru->ru_ixrss + ru->ru_idrss + ru->ru_isrss) / i;
        else
                ap->ac_mem = 0;
        ap->ac_io = compress(ru->ru_inblock + ru->ru_oublock, (long)0);
        else
                ap->ac_mem = 0;
        ap->ac_io = compress(ru->ru_inblock + ru->ru_oublock, (long)0);
@@ -156,9 +162,10 @@ acct(p)
                ap->ac_tty = p->p_session->s_ttyp->t_dev;
        else
                ap->ac_tty = NODEV;
                ap->ac_tty = p->p_session->s_ttyp->t_dev;
        else
                ap->ac_tty = NODEV;
-       ap->ac_flag = u.u_acflag;
-       return (vn_rdwr(UIO_WRITE, vp, (caddr_t)ap, sizeof (acctbuf),
-               (off_t)0, UIO_SYSSPACE, IO_UNIT|IO_APPEND, u.u_cred, (int *)0));
+       ap->ac_flag = p->p_acflag;
+       return (vn_rdwr(UIO_WRITE, vp, (caddr_t)ap, sizeof (acctbuf), (off_t)0,
+               UIO_SYSSPACE, IO_UNIT|IO_APPEND, p->p_ucred, (int *)0,
+               (struct proc *)0));
 }
 
 /*
 }
 
 /*