summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEunji, Lee <eunjieji.lee@samsung.com>2016-05-10 20:14:03 +0900
committerEunji, Lee <eunjieji.lee@samsung.com>2016-05-10 20:14:03 +0900
commit80c3e381d0426061593066be200a3c0d747c1065 (patch)
tree758a9812a784f6a3e7361c2a3b13b44c2b21f6e4
parentb15cfa35bad1efbaeb7d86477304ac2b5225e3f5 (diff)
parente66c90a06cc1820b8562a0f531fa31ad6e64a830 (diff)
downloadttrace-80c3e381d0426061593066be200a3c0d747c1065.tar.gz
ttrace-80c3e381d0426061593066be200a3c0d747c1065.tar.bz2
ttrace-80c3e381d0426061593066be200a3c0d747c1065.zip
-rwxr-xr-xsrc/atrace/atrace.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/atrace/atrace.cpp b/src/atrace/atrace.cpp
index 12f005f..fb2ec1f 100755
--- a/src/atrace/atrace.cpp
+++ b/src/atrace/atrace.cpp
@@ -43,6 +43,7 @@
#define BACKUP_TRACE "/tmp/trace.backup"
#define BOOTUP_TRACE "/etc/ttrace.conf"
+#define DEF_GR_SIZE 1024
#else
#include <binder/IBinder.h>
#include <binder/IServiceManager.h>
@@ -507,11 +508,40 @@ static bool setTagsProperty(uint64_t tags)
//atrace "--init_exec" mode
if(g_init_exec) {
- char buf[256]; //insufficient buffer size can cause "ERANGE" as a result of getgrnam_r
- if(0 != getgrnam_r(TTRACE_GROUP_NAME, &group_dev, buf, sizeof(buf), &group_ptr))
+ size_t bufSize = DEF_GR_SIZE;
+ char buf[DEF_GR_SIZE];
+ int ret = 0;
+ ret = getgrnam_r(TTRACE_GROUP_NAME, &group_dev, buf, bufSize, &group_ptr);
+
+ if (ret != 0 && ret != ERANGE)
+ {
+ fprintf(stderr, "Fail to group[%s] info: %s(%d)\n", TTRACE_GROUP_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
+ return false;
+ }
+
+ bool isInvalid = false;
+ while(ret == ERANGE)
{
- fprintf(stderr, "Fail to group[%s] info: %s(%d)\n", TTRACE_GROUP_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
- return false;
+ long int tmpSize = -1;
+
+ if(!isInvalid)
+ tmpSize = sysconf(_SC_GETGR_R_SIZE_MAX);
+
+ if (tmpSize == -1)
+ {
+ bufSize *= 2;
+ }
+ else bufSize = (size_t) tmpSize;
+
+ char *dynbuf = (char *) malloc(bufSize);
+ if(dynbuf == NULL)
+ {
+ fprintf(stderr, "Fail to allocate buffer for group[%s]: %s(%d)\n", TTRACE_GROUP_NAME, strerror_r(errno, str_error, sizeof(str_error)), errno);
+ return false;
+ }
+ ret = getgrnam_r(TTRACE_GROUP_NAME, &group_dev, dynbuf, bufSize, &group_ptr);
+ if(ret == ERANGE) isInvalid = true;
+ free(dynbuf);
}
fd = open("/tmp/tmp_tag", O_CREAT | O_RDWR | O_CLOEXEC, 0666);