From 2af5b7c89c39cab16666d3aaf1b31d8b2b8fc7bf Mon Sep 17 00:00:00 2001 From: Shashank Mittal Date: Mon, 7 Feb 2011 20:53:56 -0800 Subject: [bionic]: Fixing futex problem in cpuacct update. With fprintf, sometimes after fork child process gets stuck in fuxtex waiting queue. To fix this problem this change opens the file in SYNC mode using open command and writes to the file using write command. (cherry picked from commit d96ad66076c70cd472bd36fc128031750751c09b) Change-Id: I7b0a386b1a86f2db3a1829f3d2210911febb2fbc CRs-Fixed: 272695 Signed-off-by: Shashank Mittal --- libc/bionic/cpuacct.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) mode change 100644 => 100755 libc/bionic/cpuacct.c diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c old mode 100644 new mode 100755 index 7317073..1d12308 --- a/libc/bionic/cpuacct.c +++ b/libc/bionic/cpuacct.c @@ -29,17 +29,18 @@ #include #include #include +#include #include "cpuacct.h" int cpuacct_add(uid_t uid) { int count; - FILE *fp; + int fd; char buf[80]; count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid); - fp = fopen(buf, "w+"); - if (!fp) { + fd = open(buf, O_RDWR| O_SYNC); + if (fd < 0) { /* Note: sizeof("tasks") returns 6, which includes the NULL char */ buf[count - sizeof("tasks")] = 0; if (mkdir(buf, 0775) < 0) @@ -47,13 +48,13 @@ 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_SYNC); } - if (!fp) + if (fd < 0) return -errno; - fprintf(fp, "0"); - if (fclose(fp)) + write(fd, "0", 2); + if (close(fd)) return -errno; return 0; -- cgit v1.1