summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShashank Mittal <mittals@codeaurora.org>2011-02-07 20:53:56 -0800
committerJessica Gonzalez <jgaona@codeaurora.org>2011-02-08 12:39:11 -0800
commit2af5b7c89c39cab16666d3aaf1b31d8b2b8fc7bf (patch)
tree64de9e5beb0cfc2f55d45f301a34807f7f543dc0
parent80f4dde02580e827cc80becb99d6c9f99a8a2288 (diff)
downloadbionic-M7630AABBQMLZA4030.zip
bionic-M7630AABBQMLZA4030.tar.gz
bionic-M7630AABBQMLZA4030.tar.bz2
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 <mittals@codeaurora.org>
-rwxr-xr-x[-rw-r--r--]libc/bionic/cpuacct.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c
index 7317073..1d12308 100644..100755
--- 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;