summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorRabin Vincent <rabin.vincent@stericsson.com>2011-12-06 16:04:56 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-12-06 16:04:56 -0800
commit6e9d51701eabe26d2132a214e07b10384ea60a8c (patch)
treebc353c391d47c583d3b395683a0f069a72ce6112 /libc
parentc5819d427de4186780391d7e067850a9e4a09ec7 (diff)
parenta73de44b7c0a50908ea8afe16134316cfc6cfbbe (diff)
downloadbionic-6e9d51701eabe26d2132a214e07b10384ea60a8c.zip
bionic-6e9d51701eabe26d2132a214e07b10384ea60a8c.tar.gz
bionic-6e9d51701eabe26d2132a214e07b10384ea60a8c.tar.bz2
am a73de44b: am 177ba8cb: Prevent deadlock when using fork
* commit 'a73de44b7c0a50908ea8afe16134316cfc6cfbbe': Prevent deadlock when using fork
Diffstat (limited to 'libc')
-rw-r--r--libc/bionic/cpuacct.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c
index 7317073..1321d0e 100644
--- a/libc/bionic/cpuacct.c
+++ b/libc/bionic/cpuacct.c
@@ -30,16 +30,19 @@
#include <errno.h>
#include <sys/stat.h>
#include "cpuacct.h"
+#include <fcntl.h>
int cpuacct_add(uid_t uid)
{
int count;
- FILE *fp;
+ int fd;
char buf[80];
+ ssize_t n;
+ int ret = 0;
count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid);
- fp = fopen(buf, "w+");
- if (!fp) {
+ 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)
@@ -47,14 +50,19 @@ int cpuacct_add(uid_t uid)
/* Note: sizeof("tasks") returns 6, which includes the NULL char */
buf[count - sizeof("tasks")] = '/';
- fp = fopen(buf, "w+");
+ fd = open(buf, O_RDWR | O_CREAT, 0666);
}
- if (!fp)
+ if (fd == -1)
return -errno;
- fprintf(fp, "0");
- if (fclose(fp))
+ 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 0;
+ return ret;
}