]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/kern_acct.c
xnu-2050.22.13.tar.gz
[apple/xnu.git] / bsd / kern / kern_acct.c
index 1e378b1dbb09f6b2efea0b4374300bc72a1b46e8..516de08dc0bc46896d9bd160375325c2654722e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * The former's operation is described in Leffler, et al., and the latter
  * was provided by UCB with the 4.4BSD-Lite release
  */
-comp_t encode_comp_t(u_long, u_long);
+comp_t encode_comp_t(uint32_t, uint32_t);
 void   acctwatch(void *);
 void   acctwatch_funnel(void *);
 
@@ -161,7 +161,7 @@ acct(proc_t p, struct acct_args *uap, __unused int *retval)
         * writing and make sure it's a 'normal'.
         */
        if (uap->path != USER_ADDR_NULL) {
-               NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, ctx);
+               NDINIT(&nd, LOOKUP, OP_OPEN, NOFOLLOW, UIO_USERSPACE, uap->path, ctx);
                if ((error = vn_open(&nd, FWRITE, 0)))
                        return (error);
 #if CONFIG_MACF
@@ -227,7 +227,7 @@ acct_process(proc_t p)
        struct vnode *vp;
        kauth_cred_t safecred;
        struct session * sessp;
-       boolean_t fstate;
+       struct  tty *tp;
 
        /* If accounting isn't enabled, don't bother */
        vp = acctp;
@@ -271,16 +271,16 @@ acct_process(proc_t p)
        /* (6) The UID and GID of the process */
        safecred = kauth_cred_proc_ref(p);
 
-       an_acct.ac_uid = safecred->cr_ruid;
-       an_acct.ac_gid = safecred->cr_rgid;
+       an_acct.ac_uid = kauth_cred_getruid(safecred);
+       an_acct.ac_gid = kauth_cred_getrgid(safecred);
 
        /* (7) The terminal from which the process was started */
        
        sessp = proc_session(p);
-       if ((p->p_flag & P_CONTROLT) && (sessp != SESSION_NULL) && (sessp->s_ttyp != TTY_NULL)) {
-               fstate = thread_funnel_set(kernel_flock, TRUE);
-               an_acct.ac_tty = sessp->s_ttyp->t_dev;
-               (void) thread_funnel_set(kernel_flock, fstate);
+       if ((p->p_flag & P_CONTROLT) && (sessp != SESSION_NULL) && ((tp = SESSION_TP(sessp)) != TTY_NULL)) {
+               tty_lock(tp);
+               an_acct.ac_tty = tp->t_dev;
+               tty_unlock(tp);
         }else
                an_acct.ac_tty = NODEV;
 
@@ -295,7 +295,7 @@ acct_process(proc_t p)
         */
        if ((error = vnode_getwithref(vp)) == 0) {
                error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&an_acct, sizeof (an_acct),
-                               (off_t)0, UIO_SYSSPACE32, IO_APPEND|IO_UNIT, safecred,
+                               (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, safecred,
                                (int *)0, p);
                vnode_put(vp);
        }
@@ -315,7 +315,7 @@ acct_process(proc_t p)
 #define        MAXFRACT        ((1 << MANTSIZE) - 1)   /* Maximum fractional value. */
 
 comp_t
-encode_comp_t(u_long s, u_long us)
+encode_comp_t(uint32_t s, uint32_t us)
 {
        int exp, rnd;
 
@@ -342,6 +342,7 @@ encode_comp_t(u_long s, u_long us)
        return (exp);
 }
 
+/* XXX The acctwatch() thread need to be protected by a mutex instead. */
 void
 acctwatch_funnel(void *a)
 {