From d96ad66076c70cd472bd36fc128031750751c09b Mon Sep 17 00:00:00 2001
From: Shashank Mittal <mittals@codeaurora.org>
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.

CRs-Fixed: 272695

Change-Id: Ia91b789effca2dafa12ee388211f7e54001fb8cb
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
---
 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 <stdio.h>
 #include <errno.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #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