changes for 4.4BSD-Lite requested by USL
[unix-history] / usr / src / sys / kern / kern_acct.c
index 49d78df..fec730c 100644 (file)
@@ -1,33 +1,33 @@
 /*-
 /*-
- * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.proprietary.c%
  *
  *
  * %sccs.include.proprietary.c%
  *
- *     @(#)kern_acct.c 7.23 (Berkeley) %G%
+ *     @(#)kern_acct.c 8.2 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "namei.h"
-#include "resourcevar.h"
-#include "proc.h"
-#include "ioctl.h"
-#include "termios.h"
-#include "tty.h"
-#include "vnode.h"
-#include "mount.h"
-#include "kernel.h"
-#include "file.h"
-#include "acct.h"
-#include "syslog.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/namei.h>
+#include <sys/resourcevar.h>
+#include <sys/proc.h>
+#include <sys/ioctl.h>
+#include <sys/termios.h>
+#include <sys/tty.h>
+#include <sys/vnode.h>
+#include <sys/mount.h>
+#include <sys/kernel.h>
+#include <sys/file.h>
+#include <sys/acct.h>
+#include <sys/syslog.h>
 
 /*
  * Values associated with enabling and disabling accounting
  */
 int    acctsuspend = 2;        /* stop accounting when < 2% free space left */
 int    acctresume = 4;         /* resume when free space risen to > 4% */
 
 /*
  * Values associated with enabling and disabling accounting
  */
 int    acctsuspend = 2;        /* stop accounting when < 2% free space left */
 int    acctresume = 4;         /* resume when free space risen to > 4% */
-struct timeval chk = { 15, 0 };/* frequency to check space for accounting */
+int    acctchkfreq = 15;       /* frequency (in seconds) to check space */
 
 /*
  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
 
 /*
  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
@@ -46,16 +46,16 @@ struct      vnode *savacctp;
  * accounting has been suspended, and freespace rises above acctresume,
  * accounting is resumed.
  */
  * accounting has been suspended, and freespace rises above acctresume,
  * accounting is resumed.
  */
-/* ARGSUSED */
-sysacct(p, uap, retval)
+struct acct_args {
+       char    *fname;
+};
+acct(p, uap, retval)
        struct proc *p;
        struct proc *p;
-       struct args {
-               char    *fname;
-       } *uap;
+       struct acct_args *uap;
        int *retval;
 {
        register struct vnode *vp;
        int *retval;
 {
        register struct vnode *vp;
-       extern int acctwatch();
+       extern void acctwatch __P((void *));
        struct vnode *oacctp;
        int error;
        struct nameidata nd;
        struct vnode *oacctp;
        int error;
        struct nameidata nd;
@@ -70,7 +70,7 @@ sysacct(p, uap, retval)
                if (vp = acctp) {
                        acctp = NULL;
                        error = vn_close(vp, FWRITE, p->p_ucred, p);
                if (vp = acctp) {
                        acctp = NULL;
                        error = vn_close(vp, FWRITE, p->p_ucred, p);
-                       untimeout(acctwatch, (caddr_t)&chk);
+                       untimeout(acctwatch, NULL);
                }
                return (error);
        }
                }
                return (error);
        }
@@ -87,7 +87,7 @@ sysacct(p, uap, retval)
        acctp = vp;
        if (oacctp)
                error = vn_close(oacctp, FWRITE, p->p_ucred, p);
        acctp = vp;
        if (oacctp)
                error = vn_close(oacctp, FWRITE, p->p_ucred, p);
-       acctwatch(&chk);
+       acctwatch(NULL);
        return (error);
 }
 
        return (error);
 }
 
@@ -95,8 +95,10 @@ sysacct(p, uap, retval)
  * Periodically check the file system to see if accounting
  * should be turned on or off.
  */
  * Periodically check the file system to see if accounting
  * should be turned on or off.
  */
-acctwatch(resettime)
-       struct timeval *resettime;
+/* ARGSUSED */
+void
+acctwatch(a)
+       void *a;
 {
        struct statfs sb;
 
 {
        struct statfs sb;
 
@@ -106,25 +108,25 @@ acctwatch(resettime)
                        acctp = savacctp;
                        savacctp = NULL;
                        log(LOG_NOTICE, "Accounting resumed\n");
                        acctp = savacctp;
                        savacctp = NULL;
                        log(LOG_NOTICE, "Accounting resumed\n");
+               }
+       } else {
+               if (acctp == NULL)
                        return;
                        return;
+               (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
+               if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
+                       savacctp = acctp;
+                       acctp = NULL;
+                       log(LOG_NOTICE, "Accounting suspended\n");
                }
        }
                }
        }
-       if (acctp == NULL)
-               return;
-       (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
-       if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
-               savacctp = acctp;
-               acctp = NULL;
-               log(LOG_NOTICE, "Accounting suspended\n");
-       }
-       timeout(acctwatch, (caddr_t)resettime, hzto(resettime));
+       timeout(acctwatch, NULL, acctchkfreq * hz);
 }
 
 /*
  * This routine calculates an accounting record for a process and,
  * if accounting is enabled, writes it to 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)
+acct_process(p)
        register struct proc *p;
 {
        register struct rusage *ru;
        register struct proc *p;
 {
        register struct rusage *ru;
@@ -138,9 +140,8 @@ acct(p)
                return (0);
        bcopy(p->p_comm, ap->ac_comm, sizeof(ap->ac_comm));
        ru = &p->p_stats->p_ru;
                return (0);
        bcopy(p->p_comm, ap->ac_comm, sizeof(ap->ac_comm));
        ru = &p->p_stats->p_ru;
+       calcru(p, &ut, &st, NULL);
        s = splclock();
        s = splclock();
-       ut = p->p_utime;
-       st = p->p_stime;
        t = time;
        splx(s);
        ap->ac_utime = compress(ut.tv_sec, ut.tv_usec);
        t = time;
        splx(s);
        ap->ac_utime = compress(ut.tv_sec, ut.tv_usec);
@@ -157,11 +158,12 @@ acct(p)
        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);
-       if (p->p_flag&SCTTY && p->p_session->s_ttyp)
+       if (p->p_flag & P_CONTROLT && p->p_session->s_ttyp)
                ap->ac_tty = p->p_session->s_ttyp->t_dev;
        else
                ap->ac_tty = NODEV;
        ap->ac_flag = p->p_acflag;
                ap->ac_tty = p->p_session->s_ttyp->t_dev;
        else
                ap->ac_tty = NODEV;
        ap->ac_flag = p->p_acflag;
+       LEASE_CHECK(vp, p, p->p_ucred, LEASE_WRITE);
        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));
        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));