diff options
author | Elliott Hughes <enh@google.com> | 2013-10-09 17:35:36 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-10-09 17:35:36 -0700 |
commit | 232163cf70712fe00436b70dd495f4cf405e9eab (patch) | |
tree | 53a65d0054d5828646703e80216eb2987b8dfe27 /libc/bionic | |
parent | 92f3cc50c8d884d1eb3496ebfba7d3916fc711e8 (diff) | |
download | bionic-232163cf70712fe00436b70dd495f4cf405e9eab.zip bionic-232163cf70712fe00436b70dd495f4cf405e9eab.tar.gz bionic-232163cf70712fe00436b70dd495f4cf405e9eab.tar.bz2 |
Clean up the cpuacct cruft.
Change-Id: I6ed63af8dfc2368e211420389fa8af4d5dc0908f
Diffstat (limited to 'libc/bionic')
-rw-r--r-- | libc/bionic/cpuacct.c | 68 | ||||
-rw-r--r-- | libc/bionic/cpuacct.h | 41 | ||||
-rw-r--r-- | libc/bionic/fork.c | 66 | ||||
-rw-r--r-- | libc/bionic/fork.cpp (renamed from libc/bionic/setresuid.c) | 30 | ||||
-rw-r--r-- | libc/bionic/setegid.cpp (renamed from libc/bionic/setegid.c) | 6 | ||||
-rw-r--r-- | libc/bionic/seteuid.cpp (renamed from libc/bionic/seteuid.c) | 10 | ||||
-rw-r--r-- | libc/bionic/setreuid.c | 37 | ||||
-rw-r--r-- | libc/bionic/setuid.c | 37 |
8 files changed, 29 insertions, 266 deletions
diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c deleted file mode 100644 index 1321d0e..0000000 --- a/libc/bionic/cpuacct.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 "cpuacct.h" -#include <fcntl.h> - -int cpuacct_add(uid_t uid) -{ - int count; - int fd; - char buf[80]; - ssize_t n; - int ret = 0; - - count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid); - fd = open(buf, O_RDWR | O_CREAT, 0666); - if (fd == -1) { - /* 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")] = '/'; - fd = open(buf, O_RDWR | O_CREAT, 0666); - } - if (fd == -1) - return -errno; - - n = TEMP_FAILURE_RETRY(write(fd, "0", 1)); - if (n < 0) - ret = -errno; - else if (n == 0) - ret = -EIO; - - if (TEMP_FAILURE_RETRY(close(fd)) == -1) - return -errno; - - return ret; -} diff --git a/libc/bionic/cpuacct.h b/libc/bionic/cpuacct.h deleted file mode 100644 index 8e24c8c..0000000 --- a/libc/bionic/cpuacct.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -#ifndef _BIONIC_CPUACCT_H -#define _BIONIC_CPUACCT_H - -#include <sys/cdefs.h> -#include <sys/types.h> - -__BEGIN_DECLS - -extern int cpuacct_add(uid_t uid); - -__END_DECLS - -#endif /* _BIONIC_CPUACCT_H */ diff --git a/libc/bionic/fork.c b/libc/bionic/fork.c deleted file mode 100644 index d30b41b..0000000 --- a/libc/bionic/fork.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008 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 "pthread_internal.h" -#include "cpuacct.h" - -#include "private/bionic_pthread.h" - -extern int __fork(void); - -int fork(void) -{ - int ret; - - /* Posix mandates that the timers of a fork child process be - * disarmed, but not destroyed. To avoid a race condition, we're - * going to stop all timers now, and only re-start them in case - * of error, or in the parent process - */ - __timer_table_start_stop(1); - __bionic_atfork_run_prepare(); - - ret = __fork(); - if (ret != 0) { /* not a child process */ - __timer_table_start_stop(0); - __bionic_atfork_run_parent(); - } else { - // Fix the tid in the pthread_internal_t struct after a fork. - __pthread_settid(pthread_self(), gettid()); - - /* - * 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()); - __bionic_atfork_run_child(); - } - return ret; -} diff --git a/libc/bionic/setresuid.c b/libc/bionic/fork.cpp index e62b3e9..a3bea20 100644 --- a/libc/bionic/setresuid.c +++ b/libc/bionic/fork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Android Open Source Project + * Copyright (C) 2008 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,14 +25,30 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #include <unistd.h> -#include "cpuacct.h" +#include "pthread_internal.h" + +#include "private/bionic_pthread.h" -extern int __setresuid(uid_t ruid, uid_t euid, uid_t suid); +extern "C" int __fork(); -int setresuid(uid_t ruid, uid_t euid, uid_t suid) -{ - cpuacct_add(euid); - return __setresuid(ruid, euid, suid); +int fork() { + // POSIX mandates that the timers of a fork child process be + // disarmed, but not destroyed. To avoid a race condition, we're + // going to stop all timers now, and only re-start them in case + // of error, or in the parent process + __timer_table_start_stop(1); + __bionic_atfork_run_prepare(); + int result = __fork(); + if (result != 0) { // Not a child process. + __timer_table_start_stop(0); + __bionic_atfork_run_parent(); + } else { + // Fix the tid in the pthread_internal_t struct after a fork. + __pthread_settid(pthread_self(), gettid()); + __bionic_atfork_run_child(); + } + return result; } diff --git a/libc/bionic/setegid.c b/libc/bionic/setegid.cpp index 9bd697b..2030ee7 100644 --- a/libc/bionic/setegid.c +++ b/libc/bionic/setegid.cpp @@ -25,9 +25,9 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + #include <unistd.h> -int setegid(gid_t egid) -{ - return setresgid(-1, egid, -1); +int setegid(gid_t egid) { + return setresgid(-1, egid, -1); } diff --git a/libc/bionic/seteuid.c b/libc/bionic/seteuid.cpp index b3ea372..6d2c89c 100644 --- a/libc/bionic/seteuid.c +++ b/libc/bionic/seteuid.cpp @@ -25,13 +25,9 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include <unistd.h> -#include "cpuacct.h" -extern int __setresuid(uid_t, uid_t, uid_t); +#include <unistd.h> -int seteuid(uid_t euid) -{ - cpuacct_add(euid); - return __setresuid(-1, euid,-1); +int seteuid(uid_t euid) { + return setresuid(-1, euid,-1); } diff --git a/libc/bionic/setreuid.c b/libc/bionic/setreuid.c deleted file mode 100644 index 32e70c8..0000000 --- a/libc/bionic/setreuid.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 "cpuacct.h" - -extern int __setreuid(uid_t ruid, uid_t euid); - -int setreuid(uid_t ruid, uid_t euid) -{ - cpuacct_add(euid); - return __setreuid(ruid, euid); -} diff --git a/libc/bionic/setuid.c b/libc/bionic/setuid.c deleted file mode 100644 index 30785d6..0000000 --- a/libc/bionic/setuid.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 "cpuacct.h" - -extern int __setuid(uid_t); - -int setuid(uid_t uid) -{ - cpuacct_add(uid); - return __setuid(uid); -} |