Loading libcutils/ashmem-host.c +63 −61 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <errno.h> #include <fcntl.h> #include <limits.h> #include <pthread.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> Loading @@ -36,6 +38,11 @@ #define __unused __attribute__((__unused__)) #endif static pthread_once_t seed_initialized = PTHREAD_ONCE_INIT; static void initialize_random() { srand(time(NULL) + getpid()); } int ashmem_create_region(const char *ignored __unused, size_t size) { static const char txt[] = "abcdefghijklmnopqrstuvwxyz" Loading @@ -44,10 +51,10 @@ int ashmem_create_region(const char *ignored __unused, size_t size) unsigned int retries = 0; pid_t pid = getpid(); int fd; srand(time(NULL) + pid); retry: if (pthread_once(&seed_initialized, &initialize_random) != 0) { return -1; } do { /* not beautiful, its just wolf-like loop unrolling */ snprintf(name, sizeof(name), "/tmp/android-ashmem-%d-%c%c%c%c%c%c%c%c", pid, Loading @@ -64,20 +71,15 @@ retry: fd = open(name, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd == -1) { /* unlikely, but if we failed because `name' exists, retry */ if (errno == EEXIST && ++retries < 6) goto retry; if (errno != EEXIST || ++retries >= 6) { return -1; } } } while (fd == -1); /* truncate the file to `len' bytes */ if (ftruncate(fd, size) == -1) goto error; if (unlink(name) == -1) goto error; if (ftruncate(fd, size) != -1 && unlink(name) != -1) { return fd; error: } close(fd); return -1; } Loading Loading
libcutils/ashmem-host.c +63 −61 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ #include <errno.h> #include <fcntl.h> #include <limits.h> #include <pthread.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> Loading @@ -36,6 +38,11 @@ #define __unused __attribute__((__unused__)) #endif static pthread_once_t seed_initialized = PTHREAD_ONCE_INIT; static void initialize_random() { srand(time(NULL) + getpid()); } int ashmem_create_region(const char *ignored __unused, size_t size) { static const char txt[] = "abcdefghijklmnopqrstuvwxyz" Loading @@ -44,10 +51,10 @@ int ashmem_create_region(const char *ignored __unused, size_t size) unsigned int retries = 0; pid_t pid = getpid(); int fd; srand(time(NULL) + pid); retry: if (pthread_once(&seed_initialized, &initialize_random) != 0) { return -1; } do { /* not beautiful, its just wolf-like loop unrolling */ snprintf(name, sizeof(name), "/tmp/android-ashmem-%d-%c%c%c%c%c%c%c%c", pid, Loading @@ -64,20 +71,15 @@ retry: fd = open(name, O_RDWR | O_CREAT | O_EXCL, 0600); if (fd == -1) { /* unlikely, but if we failed because `name' exists, retry */ if (errno == EEXIST && ++retries < 6) goto retry; if (errno != EEXIST || ++retries >= 6) { return -1; } } } while (fd == -1); /* truncate the file to `len' bytes */ if (ftruncate(fd, size) == -1) goto error; if (unlink(name) == -1) goto error; if (ftruncate(fd, size) != -1 && unlink(name) != -1) { return fd; error: } close(fd); return -1; } Loading