aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitriy Filchenko <dmitriyf@google.com>2016-08-16 09:56:25 -0700
committerDmitriy Filchenko <dmitriyf@google.com>2016-08-16 14:36:17 -0700
commit1123bf3646276221086f1da6877bba2bfa4d78e8 (patch)
treed68faeebc6c45cd819bec528b310681759706e2e /tests
parentb97c6bded4880f489e7a300dae83e113449f880e (diff)
downloadgoldfish-opengl-1123bf3646276221086f1da6877bba2bfa4d78e8.tar.gz
Update the get_process_name call.
BUG:29824203 Change-Id: I47efa5872619dcfe36579a33162214545daa9907
Diffstat (limited to 'tests')
-rw-r--r--tests/gles_android_wrapper/egl.cpp47
1 files changed, 6 insertions, 41 deletions
diff --git a/tests/gles_android_wrapper/egl.cpp b/tests/gles_android_wrapper/egl.cpp
index c7ba1254..34223681 100644
--- a/tests/gles_android_wrapper/egl.cpp
+++ b/tests/gles_android_wrapper/egl.cpp
@@ -102,51 +102,16 @@ static gl2_wrapper_context_t *getGL2Context()
const char *getProcName()
{
- static const char *procname = NULL;
+ static constexpr size_t kMaxProcessNameLength = 100;
+ static const char procname[kMaxProcessNameLength]{0};
- if (procname == NULL) {
- const char *str = get_process_name();
- if (strcmp(str, "unknown") != 0) {
- procname = str;
- } else {
- // we need to obtain our process name from the command line;
- FILE *fp = fopen("/proc/self/cmdline", "rt");
- if (fp == NULL) {
- ALOGE("couldn't open /proc/self/cmdline\n");
- return NULL;
- }
+ int rc = pthread_getname_np(pthread_self(), procname, kMaxProcessNameLength);
- char line[1000];
- if (fgets(line, sizeof(line), fp) == NULL) {
- ALOGE("couldn't read the self cmdline from \n");
- fclose(fp);
- return NULL;
- }
- fclose(fp);
-
- if (line[0] == '\0') {
- ALOGE("cmdline is empty\n");
- return NULL;
- }
-
- //obtain the basename;
- line[sizeof(line) - 1] = '\0';
- char *p = line;
- while (*p != '\0' &&
- *p != '\t' &&
- *p != ' ' &&
- *p != '\n') {
- p++;
- }
-
- *p = '\0'; p--;
- while (p > line && *p != '/') p--;
- if (*p == '/') p++;
- procname = strdup(p);
- }
+ if (rc == 0) {
+ return procname;
}
- return procname;
+ return nullptr;
}