Revert "More pthreads cleanup."

This reverts commit 2a1bb4e646

Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
This commit is contained in:
Elliott Hughes
2013-02-12 06:06:22 +00:00
committed by Gerrit Code Review
parent 2a1bb4e646
commit 6f94de3ca4
17 changed files with 291 additions and 362 deletions

View File

@@ -31,17 +31,15 @@
#include <grp.h>
#include <mntent.h>
#include <netdb.h>
#include <private/android_filesystem_config.h>
#include <private/debug_format.h>
#include <private/logd.h>
#include <pthread.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "private/android_filesystem_config.h"
#include "private/debug_format.h"
#include "private/ErrnoRestorer.h"
#include "private/logd.h"
// Thread-specific state for the non-reentrant functions.
static pthread_once_t stubs_once = PTHREAD_ONCE_INIT;
static pthread_key_t stubs_key;
@@ -60,7 +58,7 @@ static int do_getpw_r(int by_name, const char* name, uid_t uid,
passwd** result) {
// getpwnam_r and getpwuid_r don't modify errno, but library calls we
// make might.
ErrnoRestorer errno_restorer;
int old_errno = errno;
*result = NULL;
// Our implementation of getpwnam(3) and getpwuid(3) use thread-local
@@ -71,7 +69,9 @@ static int do_getpw_r(int by_name, const char* name, uid_t uid,
// POSIX allows failure to find a match to be considered a non-error.
// Reporting success (0) but with *result NULL is glibc's behavior.
if (src == NULL) {
return (errno == ENOENT) ? 0 : errno;
int rc = (errno == ENOENT) ? 0 : errno;
errno = old_errno;
return rc;
}
// Work out where our strings will go in 'buf', and whether we've got
@@ -84,11 +84,13 @@ static int do_getpw_r(int by_name, const char* name, uid_t uid,
dst->pw_shell = buf + required_byte_count;
required_byte_count += strlen(src->pw_shell) + 1;
if (byte_count < required_byte_count) {
errno = old_errno;
return ERANGE;
}
// Copy the strings.
snprintf(buf, byte_count, "%s%c%s%c%s", src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
snprintf(buf, byte_count, "%s%c%s%c%s",
src->pw_name, 0, src->pw_dir, 0, src->pw_shell);
// pw_passwd is non-POSIX and unused (always NULL) in bionic.
// pw_gecos is non-POSIX and missing in bionic.
@@ -99,6 +101,7 @@ static int do_getpw_r(int by_name, const char* name, uid_t uid,
dst->pw_uid = src->pw_uid;
*result = dst;
errno = old_errno;
return 0;
}