From 9f6915631b918a56e0e6be958fb14d274cbab322 Mon Sep 17 00:00:00 2001 From: Mike Chan Date: Tue, 2 Mar 2010 10:55:58 -0800 Subject: [PATCH] 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 --- libc/Android.mk | 4 ++ libc/SYSCALLS.TXT | 6 +- libc/arch-arm/syscalls.mk | 6 +- .../syscalls/{setresuid.S => __setresuid.S} | 6 +- .../syscalls/{setreuid.S => __setreuid.S} | 6 +- .../syscalls/{setuid.S => __setuid.S} | 6 +- libc/arch-sh/syscalls.mk | 6 +- .../syscalls/{setresuid.S => __setresuid.S} | 6 +- .../syscalls/{setreuid.S => __setreuid.S} | 6 +- .../arch-sh/syscalls/{setuid.S => __setuid.S} | 6 +- libc/arch-x86/syscalls.mk | 6 +- .../syscalls/{setresuid.S => __setresuid.S} | 6 +- .../syscalls/{setreuid.S => __setreuid.S} | 6 +- .../syscalls/{setuid.S => __setuid.S} | 6 +- libc/bionic/cpuacct.c | 60 +++++++++++++++++++ libc/bionic/fork.c | 8 +++ libc/include/sys/linux-unistd.h | 6 +- libc/unistd/seteuid.c | 3 +- libc/unistd/setresuid.c | 35 +++++++++++ libc/unistd/setreuid.c | 34 +++++++++++ libc/unistd/setuid.c | 34 +++++++++++ 21 files changed, 219 insertions(+), 43 deletions(-) rename libc/arch-arm/syscalls/{setresuid.S => __setresuid.S} (81%) rename libc/arch-arm/syscalls/{setreuid.S => __setreuid.S} (82%) rename libc/arch-arm/syscalls/{setuid.S => __setuid.S} (83%) rename libc/arch-sh/syscalls/{setresuid.S => __setresuid.S} (87%) rename libc/arch-sh/syscalls/{setreuid.S => __setreuid.S} (88%) rename libc/arch-sh/syscalls/{setuid.S => __setuid.S} (89%) rename libc/arch-x86/syscalls/{setresuid.S => __setresuid.S} (87%) rename libc/arch-x86/syscalls/{setreuid.S => __setreuid.S} (86%) rename libc/arch-x86/syscalls/{setuid.S => __setuid.S} (85%) create mode 100644 libc/bionic/cpuacct.c create mode 100644 libc/unistd/setresuid.c create mode 100644 libc/unistd/setreuid.c create mode 100644 libc/unistd/setuid.c diff --git a/libc/Android.mk b/libc/Android.mk index e820b60fa..97f401198 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -47,7 +47,10 @@ libc_common_src_files := \ 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 @@ libc_common_src_files := \ 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 ca48cfbed..8c664d759 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -42,7 +42,7 @@ pid_t __sys_clone:clone (int, void*, int*, void*, int*) 120 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 getppid() 64 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 30209304c..4a8caaca2 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -6,7 +6,7 @@ syscall_src += arch-arm/syscalls/__fork.S 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/getpgid.S 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 266c1a151..771077243 100644 --- a/libc/arch-arm/syscalls/setresuid.S +++ b/libc/arch-arm/syscalls/__setresuid.S @@ -2,12 +2,12 @@ #include .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 0f94b47de..0c68866a7 100644 --- a/libc/arch-arm/syscalls/setreuid.S +++ b/libc/arch-arm/syscalls/__setreuid.S @@ -2,12 +2,12 @@ #include .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 31cf44690..efc6e56bf 100644 --- a/libc/arch-arm/syscalls/setuid.S +++ b/libc/arch-arm/syscalls/__setuid.S @@ -2,12 +2,12 @@ #include .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 c8489545a..ab2f3d1b2 100644 --- a/libc/arch-sh/syscalls.mk +++ b/libc/arch-sh/syscalls.mk @@ -7,7 +7,7 @@ syscall_src += arch-sh/syscalls/_waitpid.S 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/getpgid.S 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 41fe34920..424100e51 100644 --- a/libc/arch-sh/syscalls/setresuid.S +++ b/libc/arch-sh/syscalls/__setresuid.S @@ -2,11 +2,11 @@ #include .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 025df277e..69907482d 100644 --- a/libc/arch-sh/syscalls/setreuid.S +++ b/libc/arch-sh/syscalls/__setreuid.S @@ -2,11 +2,11 @@ #include .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 1fb3148d1..f563de75d 100644 --- a/libc/arch-sh/syscalls/setuid.S +++ b/libc/arch-sh/syscalls/__setuid.S @@ -2,11 +2,11 @@ #include .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 6a528e3b8..ab026fe5f 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -7,7 +7,7 @@ syscall_src += arch-x86/syscalls/_waitpid.S 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/getpgid.S 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 f81cb39f9..c492dfb5d 100644 --- a/libc/arch-x86/syscalls/setresuid.S +++ b/libc/arch-x86/syscalls/__setresuid.S @@ -2,11 +2,11 @@ #include .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 99e5d5b91..111e999af 100644 --- a/libc/arch-x86/syscalls/setreuid.S +++ b/libc/arch-x86/syscalls/__setreuid.S @@ -2,11 +2,11 @@ #include .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 de334c0d3..1e5f28572 100644 --- a/libc/arch-x86/syscalls/setuid.S +++ b/libc/arch-x86/syscalls/__setuid.S @@ -2,11 +2,11 @@ #include .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 000000000..abdbc5134 --- /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 +#include +#include +#include +//#include + +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 1c6a4ba05..e20f548d0 100644 --- a/libc/bionic/fork.c +++ b/libc/bionic/fork.c @@ -43,6 +43,14 @@ int fork(void) 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 d6f706b16..116d0476a 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -12,7 +12,7 @@ pid_t _waitpid (pid_t, int*, int, struct rusage*); 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 getppid (void); 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 42ee7806b..dd9493278 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 000000000..196488101 --- /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 + +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 000000000..04c28264f --- /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 + +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 000000000..8ab637dd6 --- /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 + +int setuid(uid_t uid) +{ + cpuacct_add(uid); + return __setuid(uid); +}