bonic: libc: cpuacct support for setuid functions

Any of the setuid functions now updates /acct/uid/ with its own tid
before changing users. This is so we can properly account for cpu time
per uid.

Change-Id: I34186cf4d5228cac8439e582a9e26c01ef3011e4
Signed-off-by: Mike Chan <mike@android.com>
diff --git a/libc/Android.mk b/libc/Android.mk
index e820b60..97f4011 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -47,7 +47,10 @@
 	unistd/sbrk.c \
 	unistd/send.c \
 	unistd/setegid.c \
+	unistd/setuid.c \
 	unistd/seteuid.c \
+	unistd/setreuid.c \
+	unistd/setresuid.c \
 	unistd/setpgrp.c \
 	unistd/sigblock.c \
 	unistd/siginterrupt.c \
@@ -219,6 +222,7 @@
 	bionic/__errno.c \
 	bionic/__set_errno.c \
 	bionic/_rand48.c \
+	bionic/cpuacct.c \
 	bionic/arc4random.c \
 	bionic/basename.c \
 	bionic/basename_r.c \
diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT
index ca48cfb..8c664d7 100644
--- a/libc/SYSCALLS.TXT
+++ b/libc/SYSCALLS.TXT
@@ -42,7 +42,7 @@
 
 int     execve (const char*, char* const*, char* const*)  11
 
-int     setuid:setuid32 (uid_t)    213
+int     __setuid:setuid32 (uid_t)    213
 uid_t   getuid:getuid32 ()         199
 gid_t   getgid:getgid32 ()         200
 uid_t   geteuid:geteuid32 ()       201
@@ -56,8 +56,8 @@
 pid_t   setsid()                   66
 int     setgid:setgid32(gid_t)     214
 int     seteuid:seteuid32(uid_t)   stub
-int     setreuid:setreuid32(uid_t, uid_t)   203
-int     setresuid:setresuid32(uid_t, uid_t, uid_t)   208
+int     __setreuid:setreuid32(uid_t, uid_t)   203
+int     __setresuid:setresuid32(uid_t, uid_t, uid_t)   208
 int     setresgid:setresgid32(gid_t, gid_t, gid_t)   210
 void*   __brk:brk(void*)           45
 # see comments in arch-arm/bionic/kill.S to understand why we don't generate an ARM stub for kill/tkill
diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk
index 3020930..4a8caac 100644
--- a/libc/arch-arm/syscalls.mk
+++ b/libc/arch-arm/syscalls.mk
@@ -6,7 +6,7 @@
 syscall_src += arch-arm/syscalls/waitid.S
 syscall_src += arch-arm/syscalls/__sys_clone.S
 syscall_src += arch-arm/syscalls/execve.S
-syscall_src += arch-arm/syscalls/setuid.S
+syscall_src += arch-arm/syscalls/__setuid.S
 syscall_src += arch-arm/syscalls/getuid.S
 syscall_src += arch-arm/syscalls/getgid.S
 syscall_src += arch-arm/syscalls/geteuid.S
@@ -19,8 +19,8 @@
 syscall_src += arch-arm/syscalls/getppid.S
 syscall_src += arch-arm/syscalls/setsid.S
 syscall_src += arch-arm/syscalls/setgid.S
-syscall_src += arch-arm/syscalls/setreuid.S
-syscall_src += arch-arm/syscalls/setresuid.S
+syscall_src += arch-arm/syscalls/__setreuid.S
+syscall_src += arch-arm/syscalls/__setresuid.S
 syscall_src += arch-arm/syscalls/setresgid.S
 syscall_src += arch-arm/syscalls/__brk.S
 syscall_src += arch-arm/syscalls/__ptrace.S
diff --git a/libc/arch-arm/syscalls/setresuid.S b/libc/arch-arm/syscalls/__setresuid.S
similarity index 81%
rename from libc/arch-arm/syscalls/setresuid.S
rename to libc/arch-arm/syscalls/__setresuid.S
index 266c1a1..7710772 100644
--- a/libc/arch-arm/syscalls/setresuid.S
+++ b/libc/arch-arm/syscalls/__setresuid.S
@@ -2,12 +2,12 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setresuid, #function
-    .globl setresuid
+    .type __setresuid, #function
+    .globl __setresuid
     .align 4
     .fnstart
 
-setresuid:
+__setresuid:
     .save   {r4, r7}
     stmfd   sp!, {r4, r7}
     ldr     r7, =__NR_setresuid32
diff --git a/libc/arch-arm/syscalls/setreuid.S b/libc/arch-arm/syscalls/__setreuid.S
similarity index 82%
rename from libc/arch-arm/syscalls/setreuid.S
rename to libc/arch-arm/syscalls/__setreuid.S
index 0f94b47..0c68866 100644
--- a/libc/arch-arm/syscalls/setreuid.S
+++ b/libc/arch-arm/syscalls/__setreuid.S
@@ -2,12 +2,12 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setreuid, #function
-    .globl setreuid
+    .type __setreuid, #function
+    .globl __setreuid
     .align 4
     .fnstart
 
-setreuid:
+__setreuid:
     .save   {r4, r7}
     stmfd   sp!, {r4, r7}
     ldr     r7, =__NR_setreuid32
diff --git a/libc/arch-arm/syscalls/setuid.S b/libc/arch-arm/syscalls/__setuid.S
similarity index 83%
rename from libc/arch-arm/syscalls/setuid.S
rename to libc/arch-arm/syscalls/__setuid.S
index 31cf446..efc6e56 100644
--- a/libc/arch-arm/syscalls/setuid.S
+++ b/libc/arch-arm/syscalls/__setuid.S
@@ -2,12 +2,12 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setuid, #function
-    .globl setuid
+    .type __setuid, #function
+    .globl __setuid
     .align 4
     .fnstart
 
-setuid:
+__setuid:
     .save   {r4, r7}
     stmfd   sp!, {r4, r7}
     ldr     r7, =__NR_setuid32
diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk
index c848954..ab2f3d1 100644
--- a/libc/arch-sh/syscalls.mk
+++ b/libc/arch-sh/syscalls.mk
@@ -7,7 +7,7 @@
 syscall_src += arch-sh/syscalls/waitid.S
 syscall_src += arch-sh/syscalls/__sys_clone.S
 syscall_src += arch-sh/syscalls/execve.S
-syscall_src += arch-sh/syscalls/setuid.S
+syscall_src += arch-sh/syscalls/__setuid.S
 syscall_src += arch-sh/syscalls/getuid.S
 syscall_src += arch-sh/syscalls/getgid.S
 syscall_src += arch-sh/syscalls/geteuid.S
@@ -20,8 +20,8 @@
 syscall_src += arch-sh/syscalls/getppid.S
 syscall_src += arch-sh/syscalls/setsid.S
 syscall_src += arch-sh/syscalls/setgid.S
-syscall_src += arch-sh/syscalls/setreuid.S
-syscall_src += arch-sh/syscalls/setresuid.S
+syscall_src += arch-sh/syscalls/__setreuid.S
+syscall_src += arch-sh/syscalls/__setresuid.S
 syscall_src += arch-sh/syscalls/setresgid.S
 syscall_src += arch-sh/syscalls/__brk.S
 syscall_src += arch-sh/syscalls/kill.S
diff --git a/libc/arch-sh/syscalls/setresuid.S b/libc/arch-sh/syscalls/__setresuid.S
similarity index 87%
rename from libc/arch-sh/syscalls/setresuid.S
rename to libc/arch-sh/syscalls/__setresuid.S
index 41fe349..424100e 100644
--- a/libc/arch-sh/syscalls/setresuid.S
+++ b/libc/arch-sh/syscalls/__setresuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setresuid, @function
-    .globl setresuid
+    .type __setresuid, @function
+    .globl __setresuid
     .align 4
 
-setresuid:
+__setresuid:
 
     /* invoke trap */
     mov.l   0f, r3  /* trap num */
diff --git a/libc/arch-sh/syscalls/setreuid.S b/libc/arch-sh/syscalls/__setreuid.S
similarity index 88%
rename from libc/arch-sh/syscalls/setreuid.S
rename to libc/arch-sh/syscalls/__setreuid.S
index 025df27..6990748 100644
--- a/libc/arch-sh/syscalls/setreuid.S
+++ b/libc/arch-sh/syscalls/__setreuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setreuid, @function
-    .globl setreuid
+    .type __setreuid, @function
+    .globl __setreuid
     .align 4
 
-setreuid:
+__setreuid:
 
     /* invoke trap */
     mov.l   0f, r3  /* trap num */
diff --git a/libc/arch-sh/syscalls/setuid.S b/libc/arch-sh/syscalls/__setuid.S
similarity index 89%
rename from libc/arch-sh/syscalls/setuid.S
rename to libc/arch-sh/syscalls/__setuid.S
index 1fb3148..f563de7 100644
--- a/libc/arch-sh/syscalls/setuid.S
+++ b/libc/arch-sh/syscalls/__setuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setuid, @function
-    .globl setuid
+    .type __setuid, @function
+    .globl __setuid
     .align 4
 
-setuid:
+__setuid:
 
     /* invoke trap */
     mov.l   0f, r3  /* trap num */
diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk
index 6a528e3..ab026fe 100644
--- a/libc/arch-x86/syscalls.mk
+++ b/libc/arch-x86/syscalls.mk
@@ -7,7 +7,7 @@
 syscall_src += arch-x86/syscalls/waitid.S
 syscall_src += arch-x86/syscalls/__sys_clone.S
 syscall_src += arch-x86/syscalls/execve.S
-syscall_src += arch-x86/syscalls/setuid.S
+syscall_src += arch-x86/syscalls/__setuid.S
 syscall_src += arch-x86/syscalls/getuid.S
 syscall_src += arch-x86/syscalls/getgid.S
 syscall_src += arch-x86/syscalls/geteuid.S
@@ -20,8 +20,8 @@
 syscall_src += arch-x86/syscalls/getppid.S
 syscall_src += arch-x86/syscalls/setsid.S
 syscall_src += arch-x86/syscalls/setgid.S
-syscall_src += arch-x86/syscalls/setreuid.S
-syscall_src += arch-x86/syscalls/setresuid.S
+syscall_src += arch-x86/syscalls/__setreuid.S
+syscall_src += arch-x86/syscalls/__setresuid.S
 syscall_src += arch-x86/syscalls/setresgid.S
 syscall_src += arch-x86/syscalls/__brk.S
 syscall_src += arch-x86/syscalls/kill.S
diff --git a/libc/arch-x86/syscalls/setresuid.S b/libc/arch-x86/syscalls/__setresuid.S
similarity index 87%
rename from libc/arch-x86/syscalls/setresuid.S
rename to libc/arch-x86/syscalls/__setresuid.S
index f81cb39..c492dfb 100644
--- a/libc/arch-x86/syscalls/setresuid.S
+++ b/libc/arch-x86/syscalls/__setresuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setresuid, @function
-    .globl setresuid
+    .type __setresuid, @function
+    .globl __setresuid
     .align 4
 
-setresuid:
+__setresuid:
     pushl   %ebx
     pushl   %ecx
     pushl   %edx
diff --git a/libc/arch-x86/syscalls/setreuid.S b/libc/arch-x86/syscalls/__setreuid.S
similarity index 86%
rename from libc/arch-x86/syscalls/setreuid.S
rename to libc/arch-x86/syscalls/__setreuid.S
index 99e5d5b..111e999 100644
--- a/libc/arch-x86/syscalls/setreuid.S
+++ b/libc/arch-x86/syscalls/__setreuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setreuid, @function
-    .globl setreuid
+    .type __setreuid, @function
+    .globl __setreuid
     .align 4
 
-setreuid:
+__setreuid:
     pushl   %ebx
     pushl   %ecx
     mov     12(%esp), %ebx
diff --git a/libc/arch-x86/syscalls/setuid.S b/libc/arch-x86/syscalls/__setuid.S
similarity index 85%
rename from libc/arch-x86/syscalls/setuid.S
rename to libc/arch-x86/syscalls/__setuid.S
index de334c0..1e5f285 100644
--- a/libc/arch-x86/syscalls/setuid.S
+++ b/libc/arch-x86/syscalls/__setuid.S
@@ -2,11 +2,11 @@
 #include <sys/linux-syscalls.h>
 
     .text
-    .type setuid, @function
-    .globl setuid
+    .type __setuid, @function
+    .globl __setuid
     .align 4
 
-setuid:
+__setuid:
     pushl   %ebx
     mov     8(%esp), %ebx
     movl    $__NR_setuid32, %eax
diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c
new file mode 100644
index 0000000..abdbc51
--- /dev/null
+++ b/libc/bionic/cpuacct.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/stat.h>
+//#include <sys/types.h>
+
+int cpuacct_add(uid_t uid)
+{
+    int count;
+    FILE *fp;
+    char buf[80];
+
+    count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid);
+    fp = fopen(buf, "w+");
+    if (!fp) {
+        /* Note: sizeof("tasks") returns 6, which includes the NULL char */
+        buf[count - sizeof("tasks")] = 0;
+        if (mkdir(buf, 0775) < 0)
+            return -errno;
+
+        /* Note: sizeof("tasks") returns 6, which includes the NULL char */
+        buf[count - sizeof("tasks")] = '/';
+        fp = fopen(buf, "w+");
+    }
+    if (!fp)
+        return -errno;
+
+    fprintf(fp, "0");
+    if (fclose(fp))
+        return -errno;
+
+    return 0;
+}
diff --git a/libc/bionic/fork.c b/libc/bionic/fork.c
index 1c6a4ba..e20f548 100644
--- a/libc/bionic/fork.c
+++ b/libc/bionic/fork.c
@@ -43,6 +43,14 @@
     ret = __fork();
     if (ret != 0) {  /* not a child process */
         __timer_table_start_stop(0);
+    } else {
+        /*
+         * Newly created process must update cpu accounting.
+         * Call cpuacct_add passing in our uid, which will take
+         * the current task id and add it to the uid group passed
+         * as a parameter.
+         */
+        cpuacct_add(getuid());
     }
     return ret;
 }
diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h
index d6f706b..116d047 100644
--- a/libc/include/sys/linux-unistd.h
+++ b/libc/include/sys/linux-unistd.h
@@ -12,7 +12,7 @@
 int              waitid (int, pid_t, struct siginfo_t*, int,void*);
 pid_t            __sys_clone (int, void*, int*, void*, int*);
 int              execve (const char*, char* const*, char* const*);
-int              setuid (uid_t);
+int              __setuid (uid_t);
 uid_t            getuid (void);
 gid_t            getgid (void);
 uid_t            geteuid (void);
@@ -26,8 +26,8 @@
 pid_t            setsid (void);
 int              setgid (gid_t);
 int              seteuid (uid_t);
-int              setreuid (uid_t, uid_t);
-int              setresuid (uid_t, uid_t, uid_t);
+int              __setreuid (uid_t, uid_t);
+int              __setresuid (uid_t, uid_t, uid_t);
 int              setresgid (gid_t, gid_t, gid_t);
 void*            __brk (void*);
 int              kill (pid_t, int);
diff --git a/libc/unistd/seteuid.c b/libc/unistd/seteuid.c
index 42ee780..dd94932 100644
--- a/libc/unistd/seteuid.c
+++ b/libc/unistd/seteuid.c
@@ -29,5 +29,6 @@
 
 int seteuid(uid_t euid)
 {
-    return setresuid(-1, euid,-1);
+    cpuacct_add(euid);
+    return __setresuid(-1, euid,-1);
 }
diff --git a/libc/unistd/setresuid.c b/libc/unistd/setresuid.c
new file mode 100644
index 0000000..1964881
--- /dev/null
+++ b/libc/unistd/setresuid.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setresuid(uid_t ruid, uid_t euid, uid_t suid)
+{
+    cpuacct_add(euid);
+    return __setresuid(ruid, euid, suid);
+
+}
diff --git a/libc/unistd/setreuid.c b/libc/unistd/setreuid.c
new file mode 100644
index 0000000..04c2826
--- /dev/null
+++ b/libc/unistd/setreuid.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setreuid(uid_t ruid, uid_t euid)
+{
+    cpuacct_add(euid);
+    return __setreuid(ruid, euid);
+}
diff --git a/libc/unistd/setuid.c b/libc/unistd/setuid.c
new file mode 100644
index 0000000..8ab637d
--- /dev/null
+++ b/libc/unistd/setuid.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setuid(uid_t uid)
+{
+    cpuacct_add(uid);
+    return __setuid(uid);
+}